Introduce LRM markers when needed in the address part of the subject lines.
[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      (gnus-string-mark-left-to-right
3713       (inline
3714        (gnus-summary-extract-address-component gnus-tmp-from))))))
3715
3716 (defun gnus-summary-insert-line (gnus-tmp-header
3717                                  gnus-tmp-level gnus-tmp-current
3718                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3719                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3720                                  &optional gnus-tmp-dummy gnus-tmp-score
3721                                  gnus-tmp-process)
3722   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3723       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3724                                           gnus-tmp-level)))
3725   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3726          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3727          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3728          (gnus-tmp-score-char
3729           (if (or (null gnus-summary-default-score)
3730                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3731                       gnus-summary-zcore-fuzz))
3732               ?                         ;Whitespace
3733             (if (< gnus-tmp-score gnus-summary-default-score)
3734                 gnus-score-below-mark gnus-score-over-mark)))
3735          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3736          (gnus-tmp-replied
3737           (cond (gnus-tmp-process gnus-process-mark)
3738                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3739                  gnus-cached-mark)
3740                 (gnus-tmp-replied gnus-replied-mark)
3741                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3742                  gnus-forwarded-mark)
3743                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3744                  gnus-saved-mark)
3745                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3746                  gnus-recent-mark)
3747                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3748                  gnus-unseen-mark)
3749                 (t gnus-no-mark)))
3750          (gnus-tmp-downloaded
3751           (cond (undownloaded
3752                  gnus-undownloaded-mark)
3753                 (gnus-newsgroup-agentized
3754                  gnus-downloaded-mark)
3755                 (t
3756                  gnus-no-mark)))
3757          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3758          (gnus-tmp-name
3759           (cond
3760            ((string-match "<[^>]+> *$" gnus-tmp-from)
3761             (let ((beg (match-beginning 0)))
3762               (or (and (string-match "^\".+\"" gnus-tmp-from)
3763                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3764                   (substring gnus-tmp-from 0 beg))))
3765            ((string-match "(.+)" gnus-tmp-from)
3766             (substring gnus-tmp-from
3767                        (1+ (match-beginning 0)) (1- (match-end 0))))
3768            (t gnus-tmp-from)))
3769          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3770          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3771          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3772          (inhibit-read-only t))
3773     (when (string= gnus-tmp-name "")
3774       (setq gnus-tmp-name gnus-tmp-from))
3775     (unless (numberp gnus-tmp-lines)
3776       (setq gnus-tmp-lines -1))
3777     (if (= gnus-tmp-lines -1)
3778         (setq gnus-tmp-lines "?")
3779       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3780     (condition-case ()
3781         (gnus-put-text-property
3782          (point)
3783          (progn (eval gnus-summary-line-format-spec) (point))
3784          'gnus-number gnus-tmp-number)
3785       (error (gnus-message 5 "Error updating the summary line")))
3786     (when (gnus-visual-p 'summary-highlight 'highlight)
3787       (forward-line -1)
3788       (gnus-summary-highlight-line)
3789       (gnus-run-hooks 'gnus-summary-update-hook)
3790       (forward-line 1))))
3791
3792 (defun gnus-summary-update-line (&optional dont-update)
3793   "Update summary line after change."
3794   (when (and gnus-summary-default-score
3795              (not gnus-summary-inhibit-highlight))
3796     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3797            (article (gnus-summary-article-number))
3798            (score (gnus-summary-article-score article)))
3799       (unless dont-update
3800         (if (and gnus-summary-mark-below
3801                  (< (gnus-summary-article-score)
3802                     gnus-summary-mark-below))
3803             ;; This article has a low score, so we mark it as read.
3804             (when (memq article gnus-newsgroup-unreads)
3805               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3806           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3807             ;; This article was previously marked as read on account
3808             ;; of a low score, but now it has risen, so we mark it as
3809             ;; unread.
3810             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3811         (gnus-summary-update-mark
3812          (if (or (null gnus-summary-default-score)
3813                  (<= (abs (- score gnus-summary-default-score))
3814                      gnus-summary-zcore-fuzz))
3815              ?                          ;Whitespace
3816            (if (< score gnus-summary-default-score)
3817                gnus-score-below-mark gnus-score-over-mark))
3818          'score))
3819       ;; Do visual highlighting.
3820       (when (gnus-visual-p 'summary-highlight 'highlight)
3821         (gnus-summary-highlight-line)
3822         (gnus-run-hooks 'gnus-summary-update-hook)))))
3823
3824 (defvar gnus-tmp-new-adopts nil)
3825
3826 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3827   "Return the number of articles in THREAD.
3828 This may be 0 in some cases -- if none of the articles in
3829 the thread are to be displayed."
3830   (let* ((number
3831          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3832           (cond
3833            ((not (listp thread))
3834             1)
3835            ((and (consp thread) (cdr thread))
3836             (apply
3837              '+ 1 (mapcar
3838                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3839            ((null thread)
3840             1)
3841            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3842             1)
3843            (t 0))))
3844     (when (and level (zerop level) gnus-tmp-new-adopts)
3845       (incf number
3846             (apply '+ (mapcar
3847                        'gnus-summary-number-of-articles-in-thread
3848                        gnus-tmp-new-adopts))))
3849     (if char
3850         (if (> number 1) gnus-not-empty-thread-mark
3851           gnus-empty-thread-mark)
3852       number)))
3853
3854 (defsubst gnus-summary-line-message-size (head)
3855   "Return pretty-printed version of message size.
3856 This function is intended to be used in
3857 `gnus-summary-line-format-alist'."
3858   (let ((c (or (mail-header-chars head) -1)))
3859     (cond ((< c 0) "n/a")               ; chars not available
3860           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3861           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3862           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3863           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3864
3865 (defcustom gnus-user-date-format-alist
3866   '(((gnus-seconds-today) . "Today, %H:%M")
3867     ((+ 86400 (gnus-seconds-today)) . "Yesterday, %H:%M")
3868     (604800 . "%A %H:%M")               ; That's one week
3869     ((gnus-seconds-month) . "%A %d")
3870     ((gnus-seconds-year) . "%B %d")
3871     (t . "%b %d %Y"))                   ; This one is used when no other
3872                                         ; does match
3873   "Specifies date format depending on age of article.
3874 This is an alist of items (AGE . FORMAT).  AGE can be a number (of
3875 seconds) or a Lisp expression evaluating to a number.  When the age of
3876 the article is less than this number, then use `format-time-string'
3877 with the corresponding FORMAT for displaying the date of the article.
3878 If AGE is not a number or a Lisp expression evaluating to a
3879 non-number, then the corresponding FORMAT is used as a default value.
3880
3881 Note that the list is processed from the beginning, so it should be
3882 sorted by ascending AGE.  Also note that items following the first
3883 non-number AGE will be ignored.
3884
3885 You can use the functions `gnus-seconds-today', `gnus-seconds-month'
3886 and `gnus-seconds-year' in the AGE spec.  They return the number of
3887 seconds passed since the start of today, of this month, of this year,
3888 respectively."
3889   :version "24.1"
3890   :group 'gnus-summary-format
3891   :type '(alist :key-type sexp :value-type string))
3892
3893 (defun gnus-user-date (messy-date)
3894   "Format the messy-date according to `gnus-user-date-format-alist'.
3895 Returns \"  ?  \" if there's bad input or if another error occurs.
3896 Input should look like this: \"Sun, 14 Oct 2001 13:34:39 +0200\"."
3897   (condition-case ()
3898       (let* ((messy-date (gnus-float-time (gnus-date-get-time messy-date)))
3899              (now (gnus-float-time))
3900              ;;If we don't find something suitable we'll use this one
3901              (my-format "%b %d '%y"))
3902         (let* ((difference (- now messy-date))
3903                (templist gnus-user-date-format-alist)
3904                (top (eval (caar templist))))
3905           (while (if (numberp top) (< top difference) (not top))
3906             (progn
3907               (setq templist (cdr templist))
3908               (setq top (eval (caar templist)))))
3909           (if (stringp (cdr (car templist)))
3910               (setq my-format (cdr (car templist)))))
3911         (format-time-string (eval my-format) (seconds-to-time messy-date)))
3912     (error "  ?   ")))
3913
3914 (defun gnus-summary-set-local-parameters (group)
3915   "Go through the local params of GROUP and set all variable specs in that list."
3916   (let ((vars '(quit-config active)))   ; Ignore things that aren't
3917                                         ; really variables.
3918     (dolist (elem (gnus-group-find-parameter group))
3919       (and (consp elem)                 ; Has to be a cons.
3920            (consp (cdr elem))           ; The cdr has to be a list.
3921            (symbolp (car elem))         ; Has to be a symbol in there.
3922            (not (memq (car elem) vars))
3923            (ignore-errors
3924              (push (car elem) vars)
3925              ;; Variables like `gnus-show-threads' that are globally
3926              ;; bound, if used as group parameters, need to get to be
3927              ;; buffer-local, whereas just parameters like `gcc-self',
3928              ;; `timestamp', etc. should not be bound as variables.
3929              (if (boundp (car elem))
3930                  (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3931                (eval (nth 1 elem))))))))
3932
3933 (defun gnus-summary-read-group (group &optional show-all no-article
3934                                       kill-buffer no-display backward
3935                                       select-articles)
3936   "Start reading news in newsgroup GROUP.
3937 If SHOW-ALL is non-nil, already read articles are also listed.
3938 If NO-ARTICLE is non-nil, no article is selected initially.
3939 If NO-DISPLAY, don't generate a summary buffer."
3940   (let (result)
3941     (while (and group
3942                 (null (setq result
3943                             (let ((gnus-auto-select-next nil))
3944                               (or (gnus-summary-read-group-1
3945                                    group show-all no-article
3946                                    kill-buffer no-display
3947                                    select-articles)
3948                                   (setq show-all nil
3949                                         select-articles nil)))))
3950                 (eq gnus-auto-select-next 'quietly))
3951       (set-buffer gnus-group-buffer)
3952       ;; The entry function called above goes to the next
3953       ;; group automatically, so we go two groups back
3954       ;; if we are searching for the previous group.
3955       (when backward
3956         (gnus-group-prev-unread-group 2))
3957       (if (not (equal group (gnus-group-group-name)))
3958           (setq group (gnus-group-group-name))
3959         (setq group nil)))
3960     result))
3961
3962 (defun gnus-summary-read-group-1 (group show-all no-article
3963                                         kill-buffer no-display
3964                                         &optional select-articles)
3965   ;; Killed foreign groups can't be entered.
3966   ;;  (when (and (not (gnus-group-native-p group))
3967   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3968   ;;    (error "Dead non-native groups can't be entered"))
3969   (gnus-message 5 "Retrieving newsgroup: %s..."
3970                 (gnus-group-decoded-name group))
3971   (let* ((new-group (gnus-summary-setup-buffer group))
3972          (quit-config (gnus-group-quit-config group))
3973          (did-select (and new-group (gnus-select-newsgroup
3974                                      group show-all select-articles))))
3975     (cond
3976      ;; This summary buffer exists already, so we just select it.
3977      ((not new-group)
3978       (gnus-set-global-variables)
3979       (when kill-buffer
3980         (gnus-kill-or-deaden-summary kill-buffer))
3981       (gnus-configure-windows 'summary 'force)
3982       (gnus-set-mode-line 'summary)
3983       (gnus-summary-position-point)
3984       (message "")
3985       t)
3986      ;; We couldn't select this group.
3987      ((null did-select)
3988       (when (and (eq major-mode 'gnus-summary-mode)
3989                  (not (equal (current-buffer) kill-buffer)))
3990         (kill-buffer (current-buffer))
3991         (if (not quit-config)
3992             (progn
3993               ;; Update the info -- marks might need to be removed,
3994               ;; for instance.
3995               (gnus-summary-update-info)
3996               (set-buffer gnus-group-buffer)
3997               (gnus-group-jump-to-group group)
3998               (gnus-group-next-unread-group 1))
3999           (gnus-handle-ephemeral-exit quit-config)))
4000       (if (null (gnus-list-of-unread-articles group))
4001           (gnus-message 3 "Group %s contains no messages" group)
4002         (gnus-message 3 "Can't select group"))
4003       nil)
4004      ;; The user did a `C-g' while prompting for number of articles,
4005      ;; so we exit this group.
4006      ((eq did-select 'quit)
4007       (and (eq major-mode 'gnus-summary-mode)
4008            (not (equal (current-buffer) kill-buffer))
4009            (kill-buffer (current-buffer)))
4010       (when kill-buffer
4011         (gnus-kill-or-deaden-summary kill-buffer))
4012       (if (not quit-config)
4013           (progn
4014             (set-buffer gnus-group-buffer)
4015             (gnus-group-jump-to-group group)
4016             (gnus-configure-windows 'group 'force))
4017         (gnus-handle-ephemeral-exit quit-config))
4018       ;; Finally signal the quit.
4019       (signal 'quit nil))
4020      ;; The group was successfully selected.
4021      (t
4022       (gnus-set-global-variables)
4023       ;; Save the active value in effect when the group was entered.
4024       (setq gnus-newsgroup-active
4025             (gnus-copy-sequence
4026              (gnus-active gnus-newsgroup-name)))
4027       (setq gnus-newsgroup-highest (cdr gnus-newsgroup-active))
4028       ;; You can change the summary buffer in some way with this hook.
4029       (gnus-run-hooks 'gnus-select-group-hook)
4030       (when (memq 'summary (gnus-update-format-specifications
4031                             nil 'summary 'summary-mode 'summary-dummy))
4032         ;; The format specification for the summary line was updated,
4033         ;; so we need to update the mark positions as well.
4034         (gnus-update-summary-mark-positions))
4035       ;; Do score processing.
4036       (when gnus-use-scoring
4037         (gnus-possibly-score-headers))
4038       ;; Check whether to fill in the gaps in the threads.
4039       (when gnus-build-sparse-threads
4040         (gnus-build-sparse-threads))
4041       ;; Find the initial limit.
4042       (if show-all
4043           (let ((gnus-newsgroup-dormant nil))
4044             (gnus-summary-initial-limit show-all))
4045         (gnus-summary-initial-limit show-all))
4046       ;; Generate the summary buffer.
4047       (unless no-display
4048         (gnus-summary-prepare))
4049       (when gnus-use-trees
4050         (gnus-tree-open group)
4051         (setq gnus-summary-highlight-line-function
4052               'gnus-tree-highlight-article))
4053       ;; If the summary buffer is empty, but there are some low-scored
4054       ;; articles or some excluded dormants, we include these in the
4055       ;; buffer.
4056       (when (and (zerop (buffer-size))
4057                  (not no-display))
4058         (cond (gnus-newsgroup-dormant
4059                (gnus-summary-limit-include-dormant))
4060               ((and gnus-newsgroup-scored show-all)
4061                (gnus-summary-limit-include-expunged t))))
4062       ;; Function `gnus-apply-kill-file' must be called in this hook.
4063       (gnus-run-hooks 'gnus-apply-kill-hook)
4064       (if (and (zerop (buffer-size))
4065                (not no-display))
4066           (progn
4067             ;; This newsgroup is empty.
4068             (gnus-summary-catchup-and-exit nil t)
4069             (gnus-message 6 "No unread news")
4070             (when kill-buffer
4071               (gnus-kill-or-deaden-summary kill-buffer))
4072             ;; Return nil from this function.
4073             nil)
4074         ;; Hide conversation thread subtrees.  We cannot do this in
4075         ;; gnus-summary-prepare-hook since kill processing may not
4076         ;; work with hidden articles.
4077         (gnus-summary-maybe-hide-threads)
4078         (gnus-configure-windows 'summary)
4079         (when kill-buffer
4080           (gnus-kill-or-deaden-summary kill-buffer))
4081         (gnus-summary-auto-select-subject)
4082         ;; Show first unread article if requested.
4083         (if (and (not no-article)
4084                  (not no-display)
4085                  gnus-newsgroup-unreads
4086                  gnus-auto-select-first)
4087             (progn
4088               (let ((art (gnus-summary-article-number)))
4089                 (unless (and (not gnus-plugged)
4090                              (or (memq art gnus-newsgroup-undownloaded)
4091                                  (memq art gnus-newsgroup-downloadable)))
4092                   (gnus-summary-goto-article art))))
4093           ;; Don't select any articles.
4094           (gnus-summary-position-point)
4095           (gnus-configure-windows 'summary 'force)
4096           (gnus-set-mode-line 'summary))
4097         (when (and gnus-auto-center-group
4098                    (get-buffer-window gnus-group-buffer t))
4099           ;; Gotta use windows, because recenter does weird stuff if
4100           ;; the current buffer ain't the displayed window.
4101           (let ((owin (selected-window)))
4102             (select-window (get-buffer-window gnus-group-buffer t))
4103             (when (gnus-group-goto-group group)
4104               (recenter))
4105             (select-window owin)))
4106         ;; Mark this buffer as "prepared".
4107         (setq gnus-newsgroup-prepared t)
4108         (gnus-run-hooks 'gnus-summary-prepared-hook)
4109         (unless (gnus-ephemeral-group-p group)
4110           (gnus-group-update-group group nil t))
4111         t)))))
4112
4113 (defun gnus-summary-auto-select-subject ()
4114   "Select the subject line on initial group entry."
4115   (goto-char (point-min))
4116   (cond
4117    ((eq gnus-auto-select-subject 'best)
4118     (gnus-summary-best-unread-subject))
4119    ((eq gnus-auto-select-subject 'unread)
4120     (gnus-summary-first-unread-subject))
4121    ((eq gnus-auto-select-subject 'unseen)
4122     (gnus-summary-first-unseen-subject))
4123    ((eq gnus-auto-select-subject 'unseen-or-unread)
4124     (gnus-summary-first-unseen-or-unread-subject))
4125    ((eq gnus-auto-select-subject 'first)
4126     ;; Do nothing.
4127     )
4128    ((functionp gnus-auto-select-subject)
4129     (funcall gnus-auto-select-subject))))
4130
4131 (defun gnus-summary-prepare ()
4132   "Generate the summary buffer."
4133   (interactive)
4134   (let ((inhibit-read-only t))
4135     (erase-buffer)
4136     (setq gnus-newsgroup-data nil
4137           gnus-newsgroup-data-reverse nil)
4138     (gnus-run-hooks 'gnus-summary-generate-hook)
4139     ;; Generate the buffer, either with threads or without.
4140     (when gnus-newsgroup-headers
4141       (gnus-summary-prepare-threads
4142        (if gnus-show-threads
4143            (gnus-sort-gathered-threads
4144             (funcall gnus-summary-thread-gathering-function
4145                      (gnus-sort-threads
4146                       (gnus-cut-threads (gnus-make-threads)))))
4147          ;; Unthreaded display.
4148          (gnus-sort-articles gnus-newsgroup-headers))))
4149     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4150     ;; Call hooks for modifying summary buffer.
4151     (goto-char (point-min))
4152     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4153
4154 (defsubst gnus-general-simplify-subject (subject)
4155   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4156   (setq subject
4157         (cond
4158          ;; Truncate the subject.
4159          (gnus-simplify-subject-functions
4160           (gnus-map-function gnus-simplify-subject-functions subject))
4161          ((numberp gnus-summary-gather-subject-limit)
4162           (setq subject (gnus-simplify-subject-re subject))
4163           (if (> (length subject) gnus-summary-gather-subject-limit)
4164               (substring subject 0 gnus-summary-gather-subject-limit)
4165             subject))
4166          ;; Fuzzily simplify it.
4167          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4168           (gnus-simplify-subject-fuzzy subject))
4169          ;; Just remove the leading "Re:".
4170          (t
4171           (gnus-simplify-subject-re subject))))
4172
4173   (if (and gnus-summary-gather-exclude-subject
4174            (string-match gnus-summary-gather-exclude-subject subject))
4175       nil                         ; This article shouldn't be gathered
4176     subject))
4177
4178 (defun gnus-summary-simplify-subject-query ()
4179   "Query where the respool algorithm would put this article."
4180   (interactive)
4181   (gnus-summary-select-article)
4182   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4183
4184 (defun gnus-gather-threads-by-subject (threads)
4185   "Gather threads by looking at Subject headers."
4186   (if (not gnus-summary-make-false-root)
4187       threads
4188     (let ((hashtb (gnus-make-hashtable 1024))
4189           (prev threads)
4190           (result threads)
4191           subject hthread whole-subject)
4192       (while threads
4193         (setq subject (gnus-general-simplify-subject
4194                        (setq whole-subject (mail-header-subject
4195                                             (caar threads)))))
4196         (when subject
4197           (if (setq hthread (gnus-gethash subject hashtb))
4198               (progn
4199                 ;; We enter a dummy root into the thread, if we
4200                 ;; haven't done that already.
4201                 (unless (stringp (caar hthread))
4202                   (setcar hthread (list whole-subject (car hthread))))
4203                 ;; We add this new gathered thread to this gathered
4204                 ;; thread.
4205                 (setcdr (car hthread)
4206                         (nconc (cdar hthread) (list (car threads))))
4207                 ;; Remove it from the list of threads.
4208                 (setcdr prev (cdr threads))
4209                 (setq threads prev))
4210             ;; Enter this thread into the hash table.
4211             (gnus-sethash subject
4212                           (if gnus-summary-make-false-root-always
4213                               (progn
4214                                 ;; If you want a dummy root above all
4215                                 ;; threads...
4216                                 (setcar threads (list whole-subject
4217                                                       (car threads)))
4218                                 threads)
4219                             threads)
4220                           hashtb)))
4221         (setq prev threads)
4222         (setq threads (cdr threads)))
4223       result)))
4224
4225 (defun gnus-gather-threads-by-references (threads)
4226   "Gather threads by looking at References headers."
4227   (let ((idhashtb (gnus-make-hashtable 1024))
4228         (thhashtb (gnus-make-hashtable 1024))
4229         (prev threads)
4230         (result threads)
4231         ids references id gthread gid entered ref)
4232     (while threads
4233       (when (setq references (mail-header-references (caar threads)))
4234         (setq id (mail-header-id (caar threads))
4235               ids (inline (gnus-split-references references))
4236               entered nil)
4237         (while (setq ref (pop ids))
4238           (setq ids (delete ref ids))
4239           (if (not (setq gid (gnus-gethash ref idhashtb)))
4240               (progn
4241                 (gnus-sethash ref id idhashtb)
4242                 (gnus-sethash id threads thhashtb))
4243             (setq gthread (gnus-gethash gid thhashtb))
4244             (unless entered
4245               ;; We enter a dummy root into the thread, if we
4246               ;; haven't done that already.
4247               (unless (stringp (caar gthread))
4248                 (setcar gthread (list (mail-header-subject (caar gthread))
4249                                       (car gthread))))
4250               ;; We add this new gathered thread to this gathered
4251               ;; thread.
4252               (setcdr (car gthread)
4253                       (nconc (cdar gthread) (list (car threads)))))
4254             ;; Add it into the thread hash table.
4255             (gnus-sethash id gthread thhashtb)
4256             (setq entered t)
4257             ;; Remove it from the list of threads.
4258             (setcdr prev (cdr threads))
4259             (setq threads prev))))
4260       (setq prev threads)
4261       (setq threads (cdr threads)))
4262     result))
4263
4264 (defun gnus-sort-gathered-threads (threads)
4265   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4266   (let ((result threads))
4267     (while threads
4268       (when (stringp (caar threads))
4269         (setcdr (car threads)
4270                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4271       (setq threads (cdr threads)))
4272     result))
4273
4274 (defun gnus-thread-loop-p (root thread)
4275   "Say whether ROOT is in THREAD."
4276   (let ((stack (list thread))
4277         (infloop 0)
4278         th)
4279     (while (setq thread (pop stack))
4280       (setq th (cdr thread))
4281       (while (and th
4282                   (not (eq (caar th) root)))
4283         (pop th))
4284       (if th
4285           ;; We have found a loop.
4286           (let (ref-dep)
4287             (setcdr thread (delq (car th) (cdr thread)))
4288             (if (boundp (setq ref-dep (intern "none"
4289                                               gnus-newsgroup-dependencies)))
4290                 (setcdr (symbol-value ref-dep)
4291                         (nconc (cdr (symbol-value ref-dep))
4292                                (list (car th))))
4293               (set ref-dep (list nil (car th))))
4294             (setq infloop 1
4295                   stack nil))
4296         ;; Push all the subthreads onto the stack.
4297         (push (cdr thread) stack)))
4298     infloop))
4299
4300 (defun gnus-make-threads ()
4301   "Go through the dependency hashtb and find the roots.  Return all threads."
4302   (let (threads)
4303     (while (catch 'infloop
4304              (mapatoms
4305               (lambda (refs)
4306                 ;; Deal with self-referencing References loops.
4307                 (when (and (car (symbol-value refs))
4308                            (not (zerop
4309                                  (apply
4310                                   '+
4311                                   (mapcar
4312                                    (lambda (thread)
4313                                      (gnus-thread-loop-p
4314                                       (car (symbol-value refs)) thread))
4315                                    (cdr (symbol-value refs)))))))
4316                   (setq threads nil)
4317                   (throw 'infloop t))
4318                 (unless (car (symbol-value refs))
4319                   ;; These threads do not refer back to any other
4320                   ;; articles, so they're roots.
4321                   (setq threads (append (cdr (symbol-value refs)) threads))))
4322               gnus-newsgroup-dependencies)))
4323     threads))
4324
4325 ;; Build the thread tree.
4326 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4327   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4328
4329 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4330 if it was already present.
4331
4332 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4333 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4334 Message-IDs will be renamed to a unique Message-ID before being
4335 entered.
4336
4337 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4338   (let* ((id (mail-header-id header))
4339          (id-dep (and id (intern id dependencies)))
4340          parent-id ref ref-dep ref-header replaced)
4341     ;; Enter this `header' in the `dependencies' table.
4342     (cond
4343      ((not id-dep)
4344       (setq header nil))
4345      ;; The first two cases do the normal part: enter a new `header'
4346      ;; in the `dependencies' table.
4347      ((not (boundp id-dep))
4348       (set id-dep (list header)))
4349      ((null (car (symbol-value id-dep)))
4350       (setcar (symbol-value id-dep) header))
4351
4352      ;; From here the `header' was already present in the
4353      ;; `dependencies' table.
4354      (force-new
4355       ;; Overrides an existing entry;
4356       ;; just set the header part of the entry.
4357       (setcar (symbol-value id-dep) header)
4358       (setq replaced t))
4359
4360      ;; Renames the existing `header' to a unique Message-ID.
4361      ((not gnus-summary-ignore-duplicates)
4362       ;; An article with this Message-ID has already been seen.
4363       ;; We rename the Message-ID.
4364       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4365            (list header))
4366       (mail-header-set-id header id))
4367
4368      ;; The last case ignores an existing entry, except it adds any
4369      ;; additional Xrefs (in case the two articles came from different
4370      ;; servers.
4371      ;; Also sets `header' to `nil' meaning that the `dependencies'
4372      ;; table was *not* modified.
4373      (t
4374       (mail-header-set-xref
4375        (car (symbol-value id-dep))
4376        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4377                    "")
4378                (or (mail-header-xref header) "")))
4379       (setq header nil)))
4380
4381     (when (and header (not replaced))
4382       ;; First check that we are not creating a References loop.
4383       (setq parent-id (gnus-parent-id (mail-header-references header)))
4384       (setq ref parent-id)
4385       (while (and ref
4386                   (setq ref-dep (intern-soft ref dependencies))
4387                   (boundp ref-dep)
4388                   (setq ref-header (car (symbol-value ref-dep))))
4389         (if (string= id ref)
4390             ;; Yuk!  This is a reference loop.  Make the article be a
4391             ;; root article.
4392             (progn
4393               (mail-header-set-references (car (symbol-value id-dep)) "none")
4394               (setq ref nil)
4395               (setq parent-id nil))
4396           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4397       (setq ref-dep (intern (or parent-id "none") dependencies))
4398       (if (boundp ref-dep)
4399           (setcdr (symbol-value ref-dep)
4400                   (nconc (cdr (symbol-value ref-dep))
4401                          (list (symbol-value id-dep))))
4402         (set ref-dep (list nil (symbol-value id-dep)))))
4403     header))
4404
4405 (defun gnus-extract-message-id-from-in-reply-to (string)
4406   (if (string-match "<[^>]+>" string)
4407       (substring string (match-beginning 0) (match-end 0))
4408     nil))
4409
4410 (defun gnus-build-sparse-threads ()
4411   (let ((headers gnus-newsgroup-headers)
4412         (mail-parse-charset gnus-newsgroup-charset)
4413         (gnus-summary-ignore-duplicates t)
4414         header references generation relations
4415         subject child end new-child date)
4416     ;; First we create an alist of generations/relations, where
4417     ;; generations is how much we trust the relation, and the relation
4418     ;; is parent/child.
4419     (gnus-message 7 "Making sparse threads...")
4420     (save-excursion
4421       (nnheader-set-temp-buffer " *gnus sparse threads*")
4422       (while (setq header (pop headers))
4423         (when (and (setq references (mail-header-references header))
4424                    (not (string= references "")))
4425           (insert references)
4426           (setq child (mail-header-id header)
4427                 subject (mail-header-subject header)
4428                 date (mail-header-date header)
4429                 generation 0)
4430           (while (search-backward ">" nil t)
4431             (setq end (1+ (point)))
4432             (when (search-backward "<" nil t)
4433               (setq new-child (buffer-substring (point) end))
4434               (push (list (incf generation)
4435                           child (setq child new-child)
4436                           subject date)
4437                     relations)))
4438           (when child
4439             (push (list (1+ generation) child nil subject) relations))
4440           (erase-buffer)))
4441       (kill-buffer (current-buffer)))
4442     ;; Sort over trustworthiness.
4443     (dolist (relation (sort relations 'car-less-than-car))
4444       (when (gnus-dependencies-add-header
4445              (make-full-mail-header
4446               gnus-reffed-article-number
4447               (nth 3 relation) "" (or (nth 4 relation) "")
4448               (nth 1 relation)
4449               (or (nth 2 relation) "") 0 0 "")
4450              gnus-newsgroup-dependencies nil)
4451         (push gnus-reffed-article-number gnus-newsgroup-limit)
4452         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4453         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4454               gnus-newsgroup-reads)
4455         (decf gnus-reffed-article-number)))
4456     (gnus-message 7 "Making sparse threads...done")))
4457
4458 (defun gnus-build-old-threads ()
4459   ;; Look at all the articles that refer back to old articles, and
4460   ;; fetch the headers for the articles that aren't there.  This will
4461   ;; build complete threads - if the roots haven't been expired by the
4462   ;; server, that is.
4463   (let ((mail-parse-charset gnus-newsgroup-charset)
4464         id heads)
4465     (mapatoms
4466      (lambda (refs)
4467        (when (not (car (symbol-value refs)))
4468          (setq heads (cdr (symbol-value refs)))
4469          (while heads
4470            (if (memq (mail-header-number (caar heads))
4471                      gnus-newsgroup-dormant)
4472                (setq heads (cdr heads))
4473              (setq id (symbol-name refs))
4474              (while (and (setq id (gnus-build-get-header id))
4475                          (not (car (gnus-id-to-thread id)))))
4476              (setq heads nil)))))
4477      gnus-newsgroup-dependencies)))
4478
4479 (defsubst gnus-remove-odd-characters (string)
4480   "Translate STRING into something that doesn't contain weird characters."
4481   (mm-subst-char-in-string
4482    ?\r ?\-
4483    (mm-subst-char-in-string ?\n ?\- string t) t))
4484
4485 ;; This function has to be called with point after the article number
4486 ;; on the beginning of the line.
4487 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4488   (let ((eol (point-at-eol))
4489         (buffer (current-buffer))
4490         header references in-reply-to)
4491
4492     ;; overview: [num subject from date id refs chars lines misc]
4493     (unwind-protect
4494         (let (x)
4495           (narrow-to-region (point) eol)
4496           (unless (eobp)
4497             (forward-char))
4498
4499           (setq header
4500                 (make-full-mail-header
4501                  number                 ; number
4502                  (condition-case ()     ; subject
4503                      (gnus-remove-odd-characters
4504                       (funcall gnus-decode-encoded-word-function
4505                                (setq x (nnheader-nov-field))))
4506                    (error x))
4507                  (condition-case ()     ; from
4508                      (gnus-remove-odd-characters
4509                       (funcall gnus-decode-encoded-address-function
4510                                (setq x (nnheader-nov-field))))
4511                    (error x))
4512                  (nnheader-nov-field)   ; date
4513                  (nnheader-nov-read-message-id number)  ; id
4514                  (setq references (nnheader-nov-field)) ; refs
4515                  (nnheader-nov-read-integer) ; chars
4516                  (nnheader-nov-read-integer) ; lines
4517                  (unless (eobp)
4518                    (if (looking-at "Xref: ")
4519                        (goto-char (match-end 0)))
4520                    (nnheader-nov-field)) ; Xref
4521                  (nnheader-nov-parse-extra)))) ; extra
4522
4523       (widen))
4524
4525     (when (and (string= references "")
4526                (setq in-reply-to (mail-header-extra header))
4527                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4528       (mail-header-set-references
4529        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4530
4531     (when gnus-alter-header-function
4532       (funcall gnus-alter-header-function header))
4533     (gnus-dependencies-add-header header dependencies force-new)))
4534
4535 (defun gnus-build-get-header (id)
4536   "Look through the buffer of NOV lines and find the header to ID.
4537 Enter this line into the dependencies hash table, and return
4538 the id of the parent article (if any)."
4539   (let ((deps gnus-newsgroup-dependencies)
4540         found header)
4541     (prog1
4542         (with-current-buffer nntp-server-buffer
4543           (let ((case-fold-search nil))
4544             (goto-char (point-min))
4545             (while (and (not found)
4546                         (search-forward id nil t))
4547               (beginning-of-line)
4548               (setq found (looking-at
4549                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4550                                    (regexp-quote id))))
4551               (or found (beginning-of-line 2)))
4552             (when found
4553               (beginning-of-line)
4554               (and
4555                (setq header (gnus-nov-parse-line
4556                              (read (current-buffer)) deps))
4557                (gnus-parent-id (mail-header-references header))))))
4558       (when header
4559         (let ((number (mail-header-number header)))
4560           (push number gnus-newsgroup-limit)
4561           (push header gnus-newsgroup-headers)
4562           (if (memq number gnus-newsgroup-unselected)
4563               (progn
4564                 (setq gnus-newsgroup-unreads
4565                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4566                                                number))
4567                 (setq gnus-newsgroup-unselected
4568                       (delq number gnus-newsgroup-unselected)))
4569             (push number gnus-newsgroup-ancient)))))))
4570
4571 (defun gnus-build-all-threads ()
4572   "Read all the headers."
4573   (let ((gnus-summary-ignore-duplicates t)
4574         (mail-parse-charset gnus-newsgroup-charset)
4575         (dependencies gnus-newsgroup-dependencies)
4576         header article)
4577     (with-current-buffer nntp-server-buffer
4578       (let ((case-fold-search nil))
4579         (goto-char (point-min))
4580         (while (not (eobp))
4581           (ignore-errors
4582             (setq article (read (current-buffer))
4583                   header (gnus-nov-parse-line article dependencies t)))
4584           (when header
4585             (with-current-buffer gnus-summary-buffer
4586               (push header gnus-newsgroup-headers)
4587               (if (memq (setq article (mail-header-number header))
4588                         gnus-newsgroup-unselected)
4589                   (progn
4590                     (setq gnus-newsgroup-unreads
4591                           (gnus-add-to-sorted-list
4592                            gnus-newsgroup-unreads article))
4593                     (setq gnus-newsgroup-unselected
4594                           (delq article gnus-newsgroup-unselected)))
4595                 (push article gnus-newsgroup-ancient)))
4596             (forward-line 1)))))))
4597
4598 (defun gnus-summary-update-article-line (article header)
4599   "Update the line for ARTICLE using HEADER."
4600   (let* ((id (mail-header-id header))
4601          (thread (gnus-id-to-thread id)))
4602     (unless thread
4603       (error "Article in no thread"))
4604     ;; Update the thread.
4605     (setcar thread header)
4606     (gnus-summary-goto-subject article)
4607     (let* ((datal (gnus-data-find-list article))
4608            (data (car datal))
4609            (inhibit-read-only t)
4610            (level (gnus-summary-thread-level)))
4611       (gnus-delete-line)
4612       (let ((inserted (- (point)
4613                          (progn
4614                            (gnus-summary-insert-line
4615                             header level nil
4616                             (memq article gnus-newsgroup-undownloaded)
4617                             (gnus-article-mark article)
4618                             (memq article gnus-newsgroup-replied)
4619                             (memq article gnus-newsgroup-expirable)
4620                             ;; Only insert the Subject string when it's different
4621                             ;; from the previous Subject string.
4622                             (if (and
4623                                  gnus-show-threads
4624                                  (gnus-subject-equal
4625                                   (condition-case ()
4626                                       (mail-header-subject
4627                                        (gnus-data-header
4628                                         (cadr
4629                                          (gnus-data-find-list
4630                                           article
4631                                           (gnus-data-list t)))))
4632                                     ;; Error on the side of excessive subjects.
4633                                     (error ""))
4634                                   (mail-header-subject header)))
4635                                 ""
4636                               (mail-header-subject header))
4637                             nil (cdr (assq article gnus-newsgroup-scored))
4638                             (memq article gnus-newsgroup-processable))
4639                            (point)))))
4640         (when (cdr datal)
4641           (gnus-data-update-list
4642            (cdr datal)
4643            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4644
4645 (defun gnus-summary-update-article (article &optional iheader)
4646   "Update ARTICLE in the summary buffer."
4647   (set-buffer gnus-summary-buffer)
4648   (let* ((header (gnus-summary-article-header article))
4649          (id (mail-header-id header))
4650          (data (gnus-data-find article))
4651          (thread (gnus-id-to-thread id))
4652          (references (mail-header-references header))
4653          (parent
4654           (gnus-id-to-thread
4655            (or (gnus-parent-id
4656                 (when (and references
4657                            (not (equal "" references)))
4658                   references))
4659                "none")))
4660          (inhibit-read-only t)
4661          (old (car thread)))
4662     (when thread
4663       (unless iheader
4664         (setcar thread nil)
4665         (when parent
4666           (delq thread parent)))
4667       (if (gnus-summary-insert-subject id header)
4668           ;; Set the (possibly) new article number in the data structure.
4669           (gnus-data-set-number data (gnus-id-to-article id))
4670         (setcar thread old)
4671         nil))))
4672
4673 (defun gnus-rebuild-thread (id &optional line)
4674   "Rebuild the thread containing ID.
4675 If LINE, insert the rebuilt thread starting on line LINE."
4676   (let ((inhibit-read-only t)
4677         old-pos current thread data)
4678     (if (not gnus-show-threads)
4679         (setq thread (list (car (gnus-id-to-thread id))))
4680       ;; Get the thread this article is part of.
4681       (setq thread (gnus-remove-thread id)))
4682     (setq old-pos (point-at-bol))
4683     (setq current (save-excursion
4684                     (and (re-search-backward "[\r\n]" nil t)
4685                          (gnus-summary-article-number))))
4686     ;; If this is a gathered thread, we have to go some re-gathering.
4687     (when (stringp (car thread))
4688       (let ((subject (car thread))
4689             roots thr)
4690         (setq thread (cdr thread))
4691         (while thread
4692           (unless (memq (setq thr (gnus-id-to-thread
4693                                    (gnus-root-id
4694                                     (mail-header-id (caar thread)))))
4695                         roots)
4696             (push thr roots))
4697           (setq thread (cdr thread)))
4698         ;; We now have all (unique) roots.
4699         (if (= (length roots) 1)
4700             ;; All the loose roots are now one solid root.
4701             (setq thread (car roots))
4702           (setq thread (cons subject (gnus-sort-threads roots))))))
4703     (let (threads)
4704       ;; We then insert this thread into the summary buffer.
4705       (when line
4706         (goto-char (point-min))
4707         (forward-line (1- line)))
4708       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4709         (if gnus-show-threads
4710             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4711           (gnus-summary-prepare-unthreaded thread))
4712         (setq data (nreverse gnus-newsgroup-data))
4713         (setq threads gnus-newsgroup-threads))
4714       ;; We splice the new data into the data structure.
4715       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4716       ;;!!! then we want to insert at the beginning of the buffer.
4717       ;;!!! That happens to be true with Gnus now, but that may
4718       ;;!!! change in the future.  Perhaps.
4719       (gnus-data-enter-list
4720        (if line nil current) data (- (point) old-pos))
4721       (setq gnus-newsgroup-threads
4722             (nconc threads gnus-newsgroup-threads))
4723       (gnus-data-compute-positions))))
4724
4725 (defun gnus-number-to-header (number)
4726   "Return the header for article NUMBER."
4727   (let ((headers gnus-newsgroup-headers))
4728     (while (and headers
4729                 (not (= number (mail-header-number (car headers)))))
4730       (pop headers))
4731     (when headers
4732       (car headers))))
4733
4734 (defun gnus-parent-headers (in-headers &optional generation)
4735   "Return the headers of the GENERATIONeth parent of HEADERS."
4736   (unless generation
4737     (setq generation 1))
4738   (let ((parent t)
4739         (headers in-headers)
4740         references)
4741     (while (and parent
4742                 (not (zerop generation))
4743                 (setq references (mail-header-references headers)))
4744       (setq headers (if (and references
4745                              (setq parent (gnus-parent-id references)))
4746                         (car (gnus-id-to-thread parent))
4747                       nil))
4748       (decf generation))
4749     (and (not (eq headers in-headers))
4750          headers)))
4751
4752 (defun gnus-id-to-thread (id)
4753   "Return the (sub-)thread where ID appears."
4754   (gnus-gethash id gnus-newsgroup-dependencies))
4755
4756 (defun gnus-id-to-article (id)
4757   "Return the article number of ID."
4758   (let ((thread (gnus-id-to-thread id)))
4759     (when (and thread
4760                (car thread))
4761       (mail-header-number (car thread)))))
4762
4763 (defun gnus-id-to-header (id)
4764   "Return the article headers of ID."
4765   (car (gnus-id-to-thread id)))
4766
4767 (defun gnus-article-displayed-root-p (article)
4768   "Say whether ARTICLE is a root(ish) article."
4769   (let ((level (gnus-summary-thread-level article))
4770         (refs (mail-header-references  (gnus-summary-article-header article)))
4771         particle)
4772     (cond
4773      ((null level) nil)
4774      ((zerop level) t)
4775      ((null refs) t)
4776      ((null (gnus-parent-id refs)) t)
4777      ((and (= 1 level)
4778            (null (setq particle (gnus-id-to-article
4779                                  (gnus-parent-id refs))))
4780            (null (gnus-summary-thread-level particle)))))))
4781
4782 (defun gnus-root-id (id)
4783   "Return the id of the root of the thread where ID appears."
4784   (let (last-id prev)
4785     (while (and id (setq prev (car (gnus-id-to-thread id))))
4786       (setq last-id id
4787             id (gnus-parent-id (mail-header-references prev))))
4788     last-id))
4789
4790 (defun gnus-articles-in-thread (thread)
4791   "Return the list of articles in THREAD."
4792   (cons (mail-header-number (car thread))
4793         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4794
4795 (defun gnus-remove-thread (id &optional dont-remove)
4796   "Remove the thread that has ID in it."
4797   (let (headers thread last-id)
4798     ;; First go up in this thread until we find the root.
4799     (setq last-id (gnus-root-id id)
4800           headers (message-flatten-list (gnus-id-to-thread last-id)))
4801     ;; We have now found the real root of this thread.  It might have
4802     ;; been gathered into some loose thread, so we have to search
4803     ;; through the threads to find the thread we wanted.
4804     (let ((threads gnus-newsgroup-threads)
4805           sub)
4806       (while threads
4807         (setq sub (car threads))
4808         (if (stringp (car sub))
4809             ;; This is a gathered thread, so we look at the roots
4810             ;; below it to find whether this article is in this
4811             ;; gathered root.
4812             (progn
4813               (setq sub (cdr sub))
4814               (while sub
4815                 (when (member (caar sub) headers)
4816                   (setq thread (car threads)
4817                         threads nil
4818                         sub nil))
4819                 (setq sub (cdr sub))))
4820           ;; It's an ordinary thread, so we check it.
4821           (when (eq (car sub) (car headers))
4822             (setq thread sub
4823                   threads nil)))
4824         (setq threads (cdr threads)))
4825       ;; If this article is in no thread, then it's a root.
4826       (if thread
4827           (unless dont-remove
4828             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4829         (setq thread (gnus-id-to-thread last-id)))
4830       (when thread
4831         (prog1
4832             thread                      ; We return this thread.
4833           (unless dont-remove
4834             (if (stringp (car thread))
4835                 (progn
4836                   ;; If we use dummy roots, then we have to remove the
4837                   ;; dummy root as well.
4838                   (when (eq gnus-summary-make-false-root 'dummy)
4839                     ;; We go to the dummy root by going to
4840                     ;; the first sub-"thread", and then one line up.
4841                     (gnus-summary-goto-article
4842                      (mail-header-number (caadr thread)))
4843                     (forward-line -1)
4844                     (gnus-delete-line)
4845                     (gnus-data-compute-positions))
4846                   (setq thread (cdr thread))
4847                   (while thread
4848                     (gnus-remove-thread-1 (car thread))
4849                     (setq thread (cdr thread))))
4850               (gnus-remove-thread-1 thread))))))))
4851
4852 (defun gnus-remove-thread-1 (thread)
4853   "Remove the thread THREAD recursively."
4854   (let ((number (mail-header-number (pop thread)))
4855         d)
4856     (setq thread (reverse thread))
4857     (while thread
4858       (gnus-remove-thread-1 (pop thread)))
4859     (when (setq d (gnus-data-find number))
4860       (goto-char (gnus-data-pos d))
4861       (gnus-summary-show-thread)
4862       (gnus-data-remove
4863        number
4864        (- (point-at-bol)
4865           (prog1
4866               (1+ (point-at-eol))
4867             (gnus-delete-line)))))))
4868
4869 (defun gnus-sort-threads-recursive (threads func)
4870   (sort (mapcar (lambda (thread)
4871                   (cons (car thread)
4872                         (and (cdr thread)
4873                              (gnus-sort-threads-recursive (cdr thread) func))))
4874                 threads) func))
4875
4876 (defun gnus-sort-threads-loop (threads func)
4877   (let* ((superthread (cons nil threads))
4878          (stack (list (cons superthread threads)))
4879          remaining-threads thread)
4880     (while stack
4881       (setq remaining-threads (cdr (car stack)))
4882       (if remaining-threads
4883           (progn (setq thread (car remaining-threads))
4884                  (setcdr (car stack) (cdr remaining-threads))
4885                  (if (cdr thread)
4886                      (push (cons thread (cdr thread)) stack)))
4887         (setq thread (caar stack))
4888         (setcdr thread (sort (cdr thread) func))
4889         (pop stack)))
4890     (cdr superthread)))
4891
4892 (defun gnus-sort-threads (threads)
4893   "Sort THREADS."
4894   (if (not gnus-thread-sort-functions)
4895       threads
4896     (gnus-message 8 "Sorting threads...")
4897     (prog1
4898         (condition-case nil
4899             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4900               (gnus-sort-threads-recursive
4901                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4902           ;; Even after binding max-lisp-eval-depth, the recursive
4903           ;; sorter might fail for very long threads.  In that case,
4904           ;; try using a (less well-tested) non-recursive sorter.
4905           (error (gnus-message 9 "Sorting threads with loop...")
4906                  (gnus-sort-threads-loop
4907                   threads (gnus-make-sort-function
4908                            gnus-thread-sort-functions))))
4909       (gnus-message 8 "Sorting threads...done"))))
4910
4911 (defun gnus-sort-articles (articles)
4912   "Sort ARTICLES."
4913   (when gnus-article-sort-functions
4914     (gnus-message 7 "Sorting articles...")
4915     (prog1
4916         (setq gnus-newsgroup-headers
4917               (sort articles (gnus-make-sort-function
4918                               gnus-article-sort-functions)))
4919       (gnus-message 7 "Sorting articles...done"))))
4920
4921 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4922 (defmacro gnus-thread-header (thread)
4923   "Return header of first article in THREAD.
4924 Note that THREAD must never, ever be anything else than a variable -
4925 using some other form will lead to serious barfage."
4926   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4927   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4928   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4929         (vector thread) 2))
4930
4931 (defsubst gnus-article-sort-by-number (h1 h2)
4932   "Sort articles by article number."
4933   (< (mail-header-number h1)
4934      (mail-header-number h2)))
4935
4936 (defun gnus-thread-sort-by-number (h1 h2)
4937   "Sort threads by root article number."
4938   (gnus-article-sort-by-number
4939    (gnus-thread-header h1) (gnus-thread-header h2)))
4940
4941 (defsubst gnus-article-sort-by-random (h1 h2)
4942   "Sort articles randomly."
4943   (zerop (random 2)))
4944
4945 (defun gnus-thread-sort-by-random (h1 h2)
4946   "Sort threads randomly."
4947   (gnus-article-sort-by-random
4948    (gnus-thread-header h1) (gnus-thread-header h2)))
4949
4950 (defsubst gnus-article-sort-by-lines (h1 h2)
4951   "Sort articles by article Lines header."
4952   (< (mail-header-lines h1)
4953      (mail-header-lines h2)))
4954
4955 (defun gnus-thread-sort-by-lines (h1 h2)
4956   "Sort threads by root article Lines header."
4957   (gnus-article-sort-by-lines
4958    (gnus-thread-header h1) (gnus-thread-header h2)))
4959
4960 (defsubst gnus-article-sort-by-chars (h1 h2)
4961   "Sort articles by octet length."
4962   (< (mail-header-chars h1)
4963      (mail-header-chars h2)))
4964
4965 (defun gnus-thread-sort-by-chars (h1 h2)
4966   "Sort threads by root article octet length."
4967   (gnus-article-sort-by-chars
4968    (gnus-thread-header h1) (gnus-thread-header h2)))
4969
4970 (defsubst gnus-article-sort-by-author (h1 h2)
4971   "Sort articles by root author."
4972   (gnus-string<
4973    (let ((extract (funcall
4974                    gnus-extract-address-components
4975                    (mail-header-from h1))))
4976      (or (car extract) (cadr extract) ""))
4977    (let ((extract (funcall
4978                    gnus-extract-address-components
4979                    (mail-header-from h2))))
4980      (or (car extract) (cadr extract) ""))))
4981
4982 (defun gnus-thread-sort-by-author (h1 h2)
4983   "Sort threads by root author."
4984   (gnus-article-sort-by-author
4985    (gnus-thread-header h1)  (gnus-thread-header h2)))
4986
4987 (defsubst gnus-article-sort-by-recipient (h1 h2)
4988   "Sort articles by recipient."
4989   (gnus-string<
4990    (let ((extract (funcall
4991                    gnus-extract-address-components
4992                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4993      (or (car extract) (cadr extract)))
4994    (let ((extract (funcall
4995                    gnus-extract-address-components
4996                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4997      (or (car extract) (cadr extract)))))
4998
4999 (defun gnus-thread-sort-by-recipient (h1 h2)
5000   "Sort threads by root recipient."
5001   (gnus-article-sort-by-recipient
5002    (gnus-thread-header h1) (gnus-thread-header h2)))
5003
5004 (defsubst gnus-article-sort-by-subject (h1 h2)
5005   "Sort articles by root subject."
5006   (gnus-string<
5007    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
5008    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
5009
5010 (defun gnus-thread-sort-by-subject (h1 h2)
5011   "Sort threads by root subject."
5012   (gnus-article-sort-by-subject
5013    (gnus-thread-header h1) (gnus-thread-header h2)))
5014
5015 (defsubst gnus-article-sort-by-date (h1 h2)
5016   "Sort articles by root article date."
5017   (time-less-p
5018    (gnus-date-get-time (mail-header-date h1))
5019    (gnus-date-get-time (mail-header-date h2))))
5020
5021 (defun gnus-thread-sort-by-date (h1 h2)
5022   "Sort threads by root article date."
5023   (gnus-article-sort-by-date
5024    (gnus-thread-header h1) (gnus-thread-header h2)))
5025
5026 (defsubst gnus-article-sort-by-score (h1 h2)
5027   "Sort articles by root article score.
5028 Unscored articles will be counted as having a score of zero."
5029   (> (or (cdr (assq (mail-header-number h1)
5030                     gnus-newsgroup-scored))
5031          gnus-summary-default-score 0)
5032      (or (cdr (assq (mail-header-number h2)
5033                     gnus-newsgroup-scored))
5034          gnus-summary-default-score 0)))
5035
5036 (defun gnus-thread-sort-by-score (h1 h2)
5037   "Sort threads by root article score."
5038   (gnus-article-sort-by-score
5039    (gnus-thread-header h1) (gnus-thread-header h2)))
5040
5041 (defun gnus-thread-sort-by-total-score (h1 h2)
5042   "Sort threads by the sum of all scores in the thread.
5043 Unscored articles will be counted as having a score of zero."
5044   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
5045
5046 (defun gnus-thread-total-score (thread)
5047   ;; This function find the total score of THREAD.
5048   (cond
5049    ((null thread)
5050     0)
5051    ((consp thread)
5052     (if (stringp (car thread))
5053         (apply gnus-thread-score-function 0
5054                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
5055       (gnus-thread-total-score-1 thread)))
5056    (t
5057     (gnus-thread-total-score-1 (list thread)))))
5058
5059 (defun gnus-article-sort-by-most-recent-number (h1 h2)
5060   "Sort articles by number."
5061   (gnus-article-sort-by-number h1 h2))
5062
5063 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
5064   "Sort threads such that the thread with the most recently arrived article comes first."
5065   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
5066
5067 (defun gnus-thread-highest-number (thread)
5068   "Return the highest article number in THREAD."
5069   (apply 'max (mapcar (lambda (header)
5070                         (mail-header-number header))
5071                       (message-flatten-list thread))))
5072
5073 (defun gnus-article-sort-by-most-recent-date (h1 h2)
5074   "Sort articles by number."
5075   (gnus-article-sort-by-date h1 h2))
5076
5077 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
5078   "Sort threads such that the thread with the most recently dated article comes first."
5079   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
5080
5081 ; Since this is called not only to sort the top-level threads, but
5082 ; also in recursive sorts to order the articles within a thread, each
5083 ; article will be processed many times.  Thus it speeds things up
5084 ; quite a bit to use gnus-date-get-time, which caches the time value.
5085 (defun gnus-thread-latest-date (thread)
5086   "Return the highest article date in THREAD."
5087   (apply 'max
5088          (mapcar (lambda (header) (gnus-float-time
5089                                    (gnus-date-get-time
5090                                     (mail-header-date header))))
5091                  (message-flatten-list thread))))
5092
5093 (defun gnus-thread-total-score-1 (root)
5094   ;; This function find the total score of the thread below ROOT.
5095   (setq root (car root))
5096   (apply gnus-thread-score-function
5097          (or (append
5098               (mapcar 'gnus-thread-total-score
5099                       (cdr (gnus-id-to-thread (mail-header-id root))))
5100               (when (> (mail-header-number root) 0)
5101                 (list (or (cdr (assq (mail-header-number root)
5102                                      gnus-newsgroup-scored))
5103                           gnus-summary-default-score 0))))
5104              (list gnus-summary-default-score)
5105              '(0))))
5106
5107 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5108 (defvar gnus-tmp-prev-subject nil)
5109 (defvar gnus-tmp-false-parent nil)
5110 (defvar gnus-tmp-root-expunged nil)
5111 (defvar gnus-tmp-dummy-line nil)
5112
5113 (defun gnus-extra-header (type &optional header)
5114   "Return the extra header of TYPE."
5115   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5116       ""))
5117
5118 (defvar gnus-tmp-thread-tree-header-string "")
5119
5120 (defcustom gnus-sum-thread-tree-root "> "
5121   "With %B spec, used for the root of a thread.
5122 If nil, use subject instead."
5123   :version "22.1"
5124   :type '(radio (const :format "%v  " nil) string)
5125   :group 'gnus-thread)
5126
5127 (defcustom gnus-sum-thread-tree-false-root "> "
5128   "With %B spec, used for a false root of a thread.
5129 If nil, use subject instead."
5130   :version "22.1"
5131   :type '(radio (const :format "%v  " nil) string)
5132   :group 'gnus-thread)
5133
5134 (defcustom gnus-sum-thread-tree-single-indent ""
5135   "With %B spec, used for a thread with just one message.
5136 If nil, use subject instead."
5137   :version "22.1"
5138   :type '(radio (const :format "%v  " nil) string)
5139   :group 'gnus-thread)
5140
5141 (defcustom gnus-sum-thread-tree-vertical "| "
5142   "With %B spec, used for drawing a vertical line."
5143   :version "22.1"
5144   :type 'string
5145   :group 'gnus-thread)
5146
5147 (defcustom gnus-sum-thread-tree-indent "  "
5148   "With %B spec, used for indenting."
5149   :version "22.1"
5150   :type 'string
5151   :group 'gnus-thread)
5152
5153 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5154   "With %B spec, used for a leaf with brothers."
5155   :version "22.1"
5156   :type 'string
5157   :group 'gnus-thread)
5158
5159 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5160   "With %B spec, used for a leaf without brothers."
5161   :version "22.1"
5162   :type 'string
5163   :group 'gnus-thread)
5164
5165 (defcustom gnus-summary-display-while-building nil
5166   "If non-nil, show and update the summary buffer as it's being built.
5167 If the value is t, update the buffer after every line is inserted.  If
5168 the value is an integer (N), update the display every N lines."
5169   :version "22.1"
5170   :group 'gnus-thread
5171   :type '(choice (const :tag "off" nil)
5172                  number
5173                  (const :tag "frequently" t)))
5174
5175 (defun gnus-summary-prepare-threads (threads)
5176   "Prepare summary buffer from THREADS and indentation LEVEL.
5177 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5178 or a straight list of headers."
5179   (gnus-message 7 "Generating summary...")
5180
5181   (setq gnus-newsgroup-threads threads)
5182   (beginning-of-line)
5183
5184   (let ((gnus-tmp-level 0)
5185         (default-score (or gnus-summary-default-score 0))
5186         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5187         (building-line-count gnus-summary-display-while-building)
5188         (building-count (integerp gnus-summary-display-while-building))
5189         thread number subject stack state gnus-tmp-gathered beg-match
5190         new-roots gnus-tmp-new-adopts thread-end simp-subject
5191         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5192         gnus-tmp-replied gnus-tmp-subject-or-nil
5193         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5194         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5195         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5196         tree-stack)
5197
5198     (setq gnus-tmp-prev-subject nil
5199           gnus-tmp-thread-tree-header-string "")
5200
5201     (if (vectorp (car threads))
5202         ;; If this is a straight (sic) list of headers, then a
5203         ;; threaded summary display isn't required, so we just create
5204         ;; an unthreaded one.
5205         (gnus-summary-prepare-unthreaded threads)
5206
5207       ;; Do the threaded display.
5208
5209       (if gnus-summary-display-while-building
5210           (switch-to-buffer (buffer-name)))
5211       (while (or threads stack gnus-tmp-new-adopts new-roots)
5212
5213         (if (and (= gnus-tmp-level 0)
5214                  (or (not stack)
5215                      (= (caar stack) 0))
5216                  (not gnus-tmp-false-parent)
5217                  (or gnus-tmp-new-adopts new-roots))
5218             (if gnus-tmp-new-adopts
5219                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5220                       thread (list (car gnus-tmp-new-adopts))
5221                       gnus-tmp-header (caar thread)
5222                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5223               (when new-roots
5224                 (setq thread (list (car new-roots))
5225                       gnus-tmp-header (caar thread)
5226                       new-roots (cdr new-roots))))
5227
5228           (if threads
5229               ;; If there are some threads, we do them before the
5230               ;; threads on the stack.
5231               (setq thread threads
5232                     gnus-tmp-header (caar thread))
5233             ;; There were no current threads, so we pop something off
5234             ;; the stack.
5235             (setq state (car stack)
5236                   gnus-tmp-level (car state)
5237                   tree-stack (cadr state)
5238                   thread (caddr state)
5239                   stack (cdr stack)
5240                   gnus-tmp-header (caar thread))))
5241
5242         (setq gnus-tmp-false-parent nil)
5243         (setq gnus-tmp-root-expunged nil)
5244         (setq thread-end nil)
5245
5246         (if (stringp gnus-tmp-header)
5247             ;; The header is a dummy root.
5248             (cond
5249              ((eq gnus-summary-make-false-root 'adopt)
5250               ;; We let the first article adopt the rest.
5251               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5252                                                (cddar thread)))
5253               (setq gnus-tmp-gathered
5254                     (nconc (mapcar
5255                             (lambda (h) (mail-header-number (car h)))
5256                             (cddar thread))
5257                            gnus-tmp-gathered))
5258               (setq thread (cons (list (caar thread)
5259                                        (cadar thread))
5260                                  (cdr thread)))
5261               (setq gnus-tmp-level -1
5262                     gnus-tmp-false-parent t))
5263              ((eq gnus-summary-make-false-root 'empty)
5264               ;; We print adopted articles with empty subject fields.
5265               (setq gnus-tmp-gathered
5266                     (nconc (mapcar
5267                             (lambda (h) (mail-header-number (car h)))
5268                             (cddar thread))
5269                            gnus-tmp-gathered))
5270               (setq gnus-tmp-level -1))
5271              ((eq gnus-summary-make-false-root 'dummy)
5272               ;; We remember that we probably want to output a dummy
5273               ;; root.
5274               (setq gnus-tmp-dummy-line gnus-tmp-header)
5275               (setq gnus-tmp-prev-subject gnus-tmp-header))
5276              (t
5277               ;; We do not make a root for the gathered
5278               ;; sub-threads at all.
5279               (setq gnus-tmp-level -1)))
5280
5281           (setq number (mail-header-number gnus-tmp-header)
5282                 subject (mail-header-subject gnus-tmp-header)
5283                 simp-subject (gnus-simplify-subject-fully subject))
5284
5285           (cond
5286            ;; If the thread has changed subject, we might want to make
5287            ;; this subthread into a root.
5288            ((and (null gnus-thread-ignore-subject)
5289                  (not (zerop gnus-tmp-level))
5290                  gnus-tmp-prev-subject
5291                  (not (string= gnus-tmp-prev-subject simp-subject)))
5292             (setq new-roots (nconc new-roots (list (car thread)))
5293                   thread-end t
5294                   gnus-tmp-header nil))
5295            ;; If the article lies outside the current limit,
5296            ;; then we do not display it.
5297            ((not (memq number gnus-newsgroup-limit))
5298             (setq gnus-tmp-gathered
5299                   (nconc (mapcar
5300                           (lambda (h) (mail-header-number (car h)))
5301                           (cdar thread))
5302                          gnus-tmp-gathered))
5303             (setq gnus-tmp-new-adopts (if (cdar thread)
5304                                           (append gnus-tmp-new-adopts
5305                                                   (cdar thread))
5306                                         gnus-tmp-new-adopts)
5307                   thread-end t
5308                   gnus-tmp-header nil)
5309             (when (zerop gnus-tmp-level)
5310               (setq gnus-tmp-root-expunged t)))
5311            ;; Perhaps this article is to be marked as read?
5312            ((and gnus-summary-mark-below
5313                  (< (or (cdr (assq number gnus-newsgroup-scored))
5314                         default-score)
5315                     gnus-summary-mark-below)
5316                  ;; Don't touch sparse articles.
5317                  (not (gnus-summary-article-sparse-p number))
5318                  (not (gnus-summary-article-ancient-p number)))
5319             (setq gnus-newsgroup-unreads
5320                   (delq number gnus-newsgroup-unreads))
5321             (if gnus-newsgroup-auto-expire
5322                 (setq gnus-newsgroup-expirable
5323                       (gnus-add-to-sorted-list
5324                        gnus-newsgroup-expirable number))
5325               (push (cons number gnus-low-score-mark)
5326                     gnus-newsgroup-reads))))
5327
5328           (when gnus-tmp-header
5329             ;; We may have an old dummy line to output before this
5330             ;; article.
5331             (when (and gnus-tmp-dummy-line
5332                        (gnus-subject-equal
5333                         gnus-tmp-dummy-line
5334                         (mail-header-subject gnus-tmp-header)))
5335               (gnus-summary-insert-dummy-line
5336                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5337               (setq gnus-tmp-dummy-line nil))
5338
5339             ;; Compute the mark.
5340             (setq gnus-tmp-unread (gnus-article-mark number))
5341
5342             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5343                                   gnus-tmp-header gnus-tmp-level)
5344                   gnus-newsgroup-data)
5345
5346             ;; Actually insert the line.
5347             (setq
5348              gnus-tmp-subject-or-nil
5349              (cond
5350               ((and gnus-thread-ignore-subject
5351                     gnus-tmp-prev-subject
5352                     (not (string= gnus-tmp-prev-subject simp-subject)))
5353                subject)
5354               ((zerop gnus-tmp-level)
5355                (if (and (eq gnus-summary-make-false-root 'empty)
5356                         (memq number gnus-tmp-gathered)
5357                         gnus-tmp-prev-subject
5358                         (string= gnus-tmp-prev-subject simp-subject))
5359                    gnus-summary-same-subject
5360                  subject))
5361               (t gnus-summary-same-subject)))
5362             (if (and (eq gnus-summary-make-false-root 'adopt)
5363                      (= gnus-tmp-level 1)
5364                      (memq number gnus-tmp-gathered))
5365                 (setq gnus-tmp-opening-bracket ?\<
5366                       gnus-tmp-closing-bracket ?\>)
5367               (setq gnus-tmp-opening-bracket ?\[
5368                     gnus-tmp-closing-bracket ?\]))
5369             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5370                 (gnus-make-thread-indent-array
5371                  (max (* 2 (length gnus-thread-indent-array))
5372                       gnus-tmp-level)))
5373             (setq
5374              gnus-tmp-indentation
5375              (aref gnus-thread-indent-array gnus-tmp-level)
5376              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5377              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5378                                 gnus-summary-default-score 0)
5379              gnus-tmp-score-char
5380              (if (or (null gnus-summary-default-score)
5381                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5382                          gnus-summary-zcore-fuzz))
5383                  ?                      ;Whitespace
5384                (if (< gnus-tmp-score gnus-summary-default-score)
5385                    gnus-score-below-mark gnus-score-over-mark))
5386              gnus-tmp-replied
5387              (cond ((memq number gnus-newsgroup-processable)
5388                     gnus-process-mark)
5389                    ((memq number gnus-newsgroup-cached)
5390                     gnus-cached-mark)
5391                    ((memq number gnus-newsgroup-replied)
5392                     gnus-replied-mark)
5393                    ((memq number gnus-newsgroup-forwarded)
5394                     gnus-forwarded-mark)
5395                    ((memq number gnus-newsgroup-saved)
5396                     gnus-saved-mark)
5397                    ((memq number gnus-newsgroup-recent)
5398                     gnus-recent-mark)
5399                    ((memq number gnus-newsgroup-unseen)
5400                     gnus-unseen-mark)
5401                    (t gnus-no-mark))
5402              gnus-tmp-downloaded
5403              (cond ((memq number gnus-newsgroup-undownloaded)
5404                     gnus-undownloaded-mark)
5405                    (gnus-newsgroup-agentized
5406                     gnus-downloaded-mark)
5407                    (t
5408                     gnus-no-mark))
5409              gnus-tmp-from (mail-header-from gnus-tmp-header)
5410              gnus-tmp-name
5411              (cond
5412               ((string-match "<[^>]+> *$" gnus-tmp-from)
5413                (setq beg-match (match-beginning 0))
5414                (or (and (string-match "^\".+\"" gnus-tmp-from)
5415                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5416                    (substring gnus-tmp-from 0 beg-match)))
5417               ((string-match "(.+)" gnus-tmp-from)
5418                (substring gnus-tmp-from
5419                           (1+ (match-beginning 0)) (1- (match-end 0))))
5420               (t gnus-tmp-from))
5421
5422              ;; Do the %B string
5423              gnus-tmp-thread-tree-header-string
5424              (cond
5425               ((not gnus-show-threads) "")
5426               ((zerop gnus-tmp-level)
5427                (cond ((cdar thread)
5428                       (or gnus-sum-thread-tree-root subject))
5429                      (gnus-tmp-new-adopts
5430                       (or gnus-sum-thread-tree-false-root subject))
5431                      (t
5432                       (or gnus-sum-thread-tree-single-indent subject))))
5433               (t
5434                (concat (apply 'concat
5435                               (mapcar (lambda (item)
5436                                         (if (= item 1)
5437                                             gnus-sum-thread-tree-vertical
5438                                           gnus-sum-thread-tree-indent))
5439                                       (cdr (reverse tree-stack))))
5440                        (if (nth 1 thread)
5441                            gnus-sum-thread-tree-leaf-with-other
5442                          gnus-sum-thread-tree-single-leaf)))))
5443             (when (string= gnus-tmp-name "")
5444               (setq gnus-tmp-name gnus-tmp-from))
5445             (unless (numberp gnus-tmp-lines)
5446               (setq gnus-tmp-lines -1))
5447             (if (= gnus-tmp-lines -1)
5448                 (setq gnus-tmp-lines "?")
5449               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5450             (gnus-put-text-property
5451              (point)
5452              (progn (eval gnus-summary-line-format-spec) (point))
5453              'gnus-number number)
5454             (when gnus-visual-p
5455               (forward-line -1)
5456               (gnus-summary-highlight-line)
5457               (when gnus-summary-update-hook
5458                 (gnus-run-hooks 'gnus-summary-update-hook))
5459               (forward-line 1))
5460
5461             (setq gnus-tmp-prev-subject simp-subject)))
5462
5463         (when (nth 1 thread)
5464           (push (list (max 0 gnus-tmp-level)
5465                       (copy-sequence tree-stack)
5466                       (nthcdr 1 thread))
5467                 stack))
5468         (push (if (nth 1 thread) 1 0) tree-stack)
5469         (incf gnus-tmp-level)
5470         (setq threads (if thread-end nil (cdar thread)))
5471         (if gnus-summary-display-while-building
5472             (if building-count
5473                 (progn
5474                   ;; use a set frequency
5475                   (setq building-line-count (1- building-line-count))
5476                   (when (= building-line-count 0)
5477                     (sit-for 0)
5478                     (setq building-line-count
5479                           gnus-summary-display-while-building)))
5480               ;; always
5481               (sit-for 0)))
5482         (unless threads
5483           (setq gnus-tmp-level 0)))))
5484   (gnus-message 7 "Generating summary...done"))
5485
5486 (defun gnus-summary-prepare-unthreaded (headers)
5487   "Generate an unthreaded summary buffer based on HEADERS."
5488   (let (header number mark)
5489
5490     (beginning-of-line)
5491
5492     (while headers
5493       ;; We may have to root out some bad articles...
5494       (when (memq (setq number (mail-header-number
5495                                 (setq header (pop headers))))
5496                   gnus-newsgroup-limit)
5497         ;; Mark article as read when it has a low score.
5498         (when (and gnus-summary-mark-below
5499                    (< (or (cdr (assq number gnus-newsgroup-scored))
5500                           gnus-summary-default-score 0)
5501                       gnus-summary-mark-below)
5502                    (not (gnus-summary-article-ancient-p number)))
5503           (setq gnus-newsgroup-unreads
5504                 (delq number gnus-newsgroup-unreads))
5505           (if gnus-newsgroup-auto-expire
5506               (push number gnus-newsgroup-expirable)
5507             (push (cons number gnus-low-score-mark)
5508                   gnus-newsgroup-reads)))
5509
5510         (setq mark (gnus-article-mark number))
5511         (push (gnus-data-make number mark (1+ (point)) header 0)
5512               gnus-newsgroup-data)
5513         (gnus-summary-insert-line
5514          header 0 number
5515          (memq number gnus-newsgroup-undownloaded)
5516          mark (memq number gnus-newsgroup-replied)
5517          (memq number gnus-newsgroup-expirable)
5518          (mail-header-subject header) nil
5519          (cdr (assq number gnus-newsgroup-scored))
5520          (memq number gnus-newsgroup-processable))))))
5521
5522 (defun gnus-group-get-list-identifiers (group)
5523   "Get list identifier regexp for GROUP."
5524   (or (gnus-parameter-list-identifier group)
5525       (if (consp gnus-list-identifiers)
5526           (mapconcat 'identity gnus-list-identifiers " *\\|")
5527         gnus-list-identifiers)))
5528
5529 (defun gnus-summary-remove-list-identifiers ()
5530   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5531   (let ((regexp (gnus-group-get-list-identifiers gnus-newsgroup-name))
5532         changed subject)
5533     (when regexp
5534       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5535       (dolist (header gnus-newsgroup-headers)
5536         (setq subject (mail-header-subject header)
5537               changed nil)
5538         (while (string-match regexp subject)
5539           (setq subject
5540                 (concat (substring subject 0 (match-beginning 1))
5541                         (substring subject (match-end 0)))
5542                 changed t))
5543         (when changed
5544           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5545             (setq subject
5546                   (concat (substring subject 0 (match-beginning 1))
5547                           (substring subject (match-end 1)))))
5548           (mail-header-set-subject header subject))))))
5549
5550 (defun gnus-fetch-headers (articles &optional limit force-new dependencies)
5551   "Fetch headers of ARTICLES."
5552   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5553     (gnus-message 5 "Fetching headers for %s..." name)
5554     (prog1
5555         (if (eq 'nov
5556                 (setq gnus-headers-retrieved-by
5557                       (gnus-retrieve-headers
5558                        articles gnus-newsgroup-name
5559                        (or limit
5560                            ;; We might want to fetch old headers, but
5561                            ;; not if there is only 1 article.
5562                            (and (or (and
5563                                      (not (eq gnus-fetch-old-headers 'some))
5564                                      (not (numberp gnus-fetch-old-headers)))
5565                                     (> (length articles) 1))
5566                                 gnus-fetch-old-headers)))))
5567             (gnus-get-newsgroup-headers-xover
5568              articles force-new dependencies gnus-newsgroup-name t)
5569           (gnus-get-newsgroup-headers dependencies force-new))
5570       (gnus-message 5 "Fetching headers for %s...done" name))))
5571
5572 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5573   "Select newsgroup GROUP.
5574 If READ-ALL is non-nil, all articles in the group are selected.
5575 If SELECT-ARTICLES, only select those articles from GROUP."
5576   (let* ((entry (gnus-group-entry group))
5577          ;;!!! Dirty hack; should be removed.
5578          (gnus-summary-ignore-duplicates
5579           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5580               t
5581             gnus-summary-ignore-duplicates))
5582          (info (nth 2 entry))
5583          charset articles fetched-articles cached)
5584
5585     (unless (gnus-check-server
5586              (set (make-local-variable 'gnus-current-select-method)
5587                   (gnus-find-method-for-group group)))
5588       (error "Couldn't open server"))
5589     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5590
5591     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5592         (gnus-activate-group group)     ; Or we can activate it...
5593         (progn                          ; Or we bug out.
5594           (when (equal major-mode 'gnus-summary-mode)
5595             (gnus-kill-buffer (current-buffer)))
5596           (error
5597            "Couldn't activate group %s: %s"
5598            (mm-decode-coding-string group charset)
5599            (mm-decode-coding-string (gnus-status-message group) charset))))
5600
5601     (unless (gnus-request-group group t)
5602       (when (equal major-mode 'gnus-summary-mode)
5603         (gnus-kill-buffer (current-buffer)))
5604       (error "Couldn't request group %s: %s"
5605              (mm-decode-coding-string group charset)
5606              (mm-decode-coding-string (gnus-status-message group) charset)))
5607
5608     (when (and gnus-agent
5609                (gnus-active group))
5610       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5611
5612       (setq gnus-summary-use-undownloaded-faces
5613             (gnus-agent-find-parameter
5614              group
5615              'agent-enable-undownloaded-faces)))
5616
5617     (setq gnus-newsgroup-name group
5618           gnus-newsgroup-unselected nil
5619           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5620
5621     (let ((display (gnus-group-find-parameter group 'display)))
5622       (setq gnus-newsgroup-display
5623             (cond
5624              ((not (zerop (or (car-safe read-all) 0)))
5625               ;; The user entered the group with C-u SPC/RET, let's show
5626               ;; all articles.
5627               'gnus-not-ignore)
5628              ((eq display 'all)
5629               'gnus-not-ignore)
5630              ((arrayp display)
5631               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5632              ((numberp display)
5633               ;; The following is probably the "correct" solution, but
5634               ;; it makes Gnus fetch all headers and then limit the
5635               ;; articles (which is slow), so instead we hack the
5636               ;; select-articles parameter instead. -- Simon Josefsson
5637               ;; <jas@kth.se>
5638               ;;
5639               ;; (gnus-byte-compile
5640               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5641               ;;                         display)))))
5642               (setq select-articles
5643                     (gnus-uncompress-range
5644                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5645                              (if (> tmp 0)
5646                                  tmp
5647                                1))
5648                            (cdr (gnus-active group)))))
5649               nil)
5650              (t
5651               nil))))
5652
5653     (gnus-summary-setup-default-charset)
5654
5655     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5656     (when (gnus-virtual-group-p group)
5657       (setq cached gnus-newsgroup-cached))
5658
5659     (setq gnus-newsgroup-unreads
5660           (gnus-sorted-ndifference
5661            (gnus-sorted-ndifference gnus-newsgroup-unreads
5662                                     gnus-newsgroup-marked)
5663            gnus-newsgroup-dormant))
5664
5665     (setq gnus-newsgroup-processable nil)
5666
5667     (gnus-update-read-articles group gnus-newsgroup-unreads t)
5668
5669     ;; Adjust and set lists of article marks.
5670     (when info
5671       (gnus-adjust-marked-articles info))
5672     (if (setq articles select-articles)
5673         (setq gnus-newsgroup-unselected
5674               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5675       (setq articles (gnus-articles-to-read group read-all)))
5676
5677     (cond
5678      ((null articles)
5679       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5680       'quit)
5681      ((eq articles 0) nil)
5682      (t
5683       ;; Init the dependencies hash table.
5684       (setq gnus-newsgroup-dependencies
5685             (gnus-make-hashtable (length articles)))
5686       (gnus-set-global-variables)
5687       ;; Retrieve the headers and read them in.
5688
5689       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5690
5691       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5692       (when cached
5693         (setq gnus-newsgroup-cached cached))
5694
5695       ;; Suppress duplicates?
5696       (when gnus-suppress-duplicates
5697         (gnus-dup-suppress-articles))
5698
5699       ;; Set the initial limit.
5700       (setq gnus-newsgroup-limit (copy-sequence articles))
5701       ;; Remove canceled articles from the list of unread articles.
5702       (setq fetched-articles
5703             (mapcar (lambda (headers) (mail-header-number headers))
5704                     gnus-newsgroup-headers))
5705       (setq gnus-newsgroup-articles fetched-articles)
5706       (setq gnus-newsgroup-unreads
5707             (gnus-sorted-nintersection
5708              gnus-newsgroup-unreads fetched-articles))
5709       (gnus-compute-unseen-list)
5710
5711       ;; Removed marked articles that do not exist.
5712       (gnus-update-missing-marks
5713        (gnus-sorted-difference articles fetched-articles))
5714       ;; We might want to build some more threads first.
5715       (when (and gnus-fetch-old-headers
5716                  (eq gnus-headers-retrieved-by 'nov))
5717         (if (eq gnus-fetch-old-headers 'invisible)
5718             (gnus-build-all-threads)
5719           (gnus-build-old-threads)))
5720       ;; Let the Gnus agent mark articles as read.
5721       (when gnus-agent
5722         (gnus-agent-get-undownloaded-list))
5723       ;; Remove list identifiers from subject
5724       (gnus-summary-remove-list-identifiers)
5725       ;; Check whether auto-expire is to be done in this group.
5726       (setq gnus-newsgroup-auto-expire
5727             (and (gnus-group-auto-expirable-p group)
5728                  (not (gnus-group-read-only-p group))))
5729       ;; Set up the article buffer now, if necessary.
5730       (unless (and gnus-single-article-buffer
5731                    (equal gnus-article-buffer "*Article*"))
5732         (gnus-article-setup-buffer))
5733       ;; First and last article in this newsgroup.
5734       (when gnus-newsgroup-headers
5735         (setq gnus-newsgroup-begin
5736               (mail-header-number (car gnus-newsgroup-headers))
5737               gnus-newsgroup-end
5738               (mail-header-number
5739                (gnus-last-element gnus-newsgroup-headers))))
5740       ;; GROUP is successfully selected.
5741       (or gnus-newsgroup-headers t)))))
5742
5743 (defun gnus-compute-unseen-list ()
5744   ;; The `seen' marks are treated specially.
5745   (if (not gnus-newsgroup-seen)
5746       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5747     (setq gnus-newsgroup-unseen
5748           (gnus-inverse-list-range-intersection
5749            gnus-newsgroup-articles gnus-newsgroup-seen))))
5750
5751 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5752
5753 (defun gnus-summary-display-make-predicate (display)
5754   (require 'gnus-agent)
5755   (when (= (length display) 1)
5756     (setq display (car display)))
5757   (unless gnus-summary-display-cache
5758     (dolist (elem (append '((unread . unread)
5759                             (read . read)
5760                             (unseen . unseen))
5761                           gnus-article-mark-lists))
5762       (push (cons (cdr elem)
5763                   (gnus-byte-compile    ;Why bother?
5764                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5765             gnus-summary-display-cache)))
5766   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5767         (gnus-category-predicate-cache gnus-summary-display-cache))
5768     (gnus-get-predicate display)))
5769
5770 ;; Uses the dynamically bound `gnus-number' variable.
5771 (defvar gnus-number)
5772 (defun gnus-article-marked-p (type &optional article)
5773   (let ((article (or article gnus-number)))
5774     (cond
5775      ((eq type 'tick)
5776       (memq article gnus-newsgroup-marked))
5777      ((eq type 'spam)
5778       (memq article gnus-newsgroup-spam-marked))
5779      ((eq type 'unsend)
5780       (memq article gnus-newsgroup-unsendable))
5781      ((eq type 'undownload)
5782       (memq article gnus-newsgroup-undownloaded))
5783      ((eq type 'download)
5784       (memq article gnus-newsgroup-downloadable))
5785      ((eq type 'unread)
5786       (memq article gnus-newsgroup-unreads))
5787      ((eq type 'read)
5788       (memq article gnus-newsgroup-reads))
5789      ((eq type 'dormant)
5790       (memq article gnus-newsgroup-dormant) )
5791      ((eq type 'expire)
5792       (memq article gnus-newsgroup-expirable))
5793      ((eq type 'reply)
5794       (memq article gnus-newsgroup-replied))
5795      ((eq type 'killed)
5796       (memq article gnus-newsgroup-killed))
5797      ((eq type 'bookmark)
5798       (assq article gnus-newsgroup-bookmarks))
5799      ((eq type 'score)
5800       (assq article gnus-newsgroup-scored))
5801      ((eq type 'save)
5802       (memq article gnus-newsgroup-saved))
5803      ((eq type 'cache)
5804       (memq article gnus-newsgroup-cached))
5805      ((eq type 'forward)
5806       (memq article gnus-newsgroup-forwarded))
5807      ((eq type 'seen)
5808       (not (memq article gnus-newsgroup-unseen)))
5809      ((eq type 'recent)
5810       (memq article gnus-newsgroup-recent))
5811      (t t))))
5812
5813 (defun gnus-articles-to-read (group &optional read-all)
5814   "Find out what articles the user wants to read."
5815   (let* ((only-read-p t)
5816          (articles
5817           ;; Select all articles if `read-all' is non-nil, or if there
5818           ;; are no unread articles.
5819           (if (or read-all
5820                   (and (zerop (length gnus-newsgroup-marked))
5821                        (zerop (length gnus-newsgroup-unreads)))
5822                   ;; Fetch all if the predicate is non-nil.
5823                   gnus-newsgroup-display)
5824               ;; We want to select the headers for all the articles in
5825               ;; the group, so we select either all the active
5826               ;; articles in the group, or (if that's nil), the
5827               ;; articles in the cache.
5828               (or
5829                (if gnus-newsgroup-maximum-articles
5830                    (let ((active (gnus-active group)))
5831                      (gnus-uncompress-range
5832                       (cons (max (car active)
5833                                  (- (cdr active)
5834                                     gnus-newsgroup-maximum-articles
5835                                     -1))
5836                             (cdr active))))
5837                  (gnus-uncompress-range (gnus-active group)))
5838                (gnus-cache-articles-in-group group))
5839             ;; Select only the "normal" subset of articles.
5840             (setq only-read-p nil)
5841             (gnus-sorted-nunion
5842              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5843              gnus-newsgroup-unreads)))
5844          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5845          (scored (length scored-list))
5846          (number (length articles))
5847          (marked (+ (length gnus-newsgroup-marked)
5848                     (length gnus-newsgroup-dormant)))
5849          (select
5850           (cond
5851            ((numberp read-all)
5852             read-all)
5853            ((numberp gnus-newsgroup-display)
5854             gnus-newsgroup-display)
5855            (t
5856             (condition-case ()
5857                 (cond
5858                  ((and (or (<= scored marked) (= scored number))
5859                        (numberp gnus-large-newsgroup)
5860                        (> number gnus-large-newsgroup))
5861                   (let* ((cursor-in-echo-area nil)
5862                          (initial (gnus-parameter-large-newsgroup-initial
5863                                    gnus-newsgroup-name))
5864                          (default (if only-read-p
5865                                       (or initial gnus-large-newsgroup)
5866                                     number))
5867                          (input
5868                           (read-string
5869                            (if only-read-p
5870                                (format
5871                               "How many articles from %s (available %d, default %d): "
5872                               (gnus-group-decoded-name
5873                                (gnus-group-real-name gnus-newsgroup-name))
5874                               number default)
5875                              (format
5876                                 "How many articles from %s (%d available): "
5877                                 (gnus-group-decoded-name
5878                                  (gnus-group-real-name gnus-newsgroup-name))
5879                                 default))
5880                            nil
5881                            nil
5882                            (number-to-string default))))
5883                     (if (string-match "^[ \t]*$" input) number input)))
5884                  ((and (> scored marked) (< scored number)
5885                        (> (- scored number) 20))
5886                   (let ((input
5887                          (read-string
5888                           (format "%s %s (%d scored, %d total): "
5889                                   "How many articles from"
5890                                   (gnus-group-decoded-name
5891                                    (gnus-group-real-name gnus-newsgroup-name))
5892                                   scored number))))
5893                     (if (string-match "^[ \t]*$" input)
5894                         number input)))
5895                  (t number))
5896               (quit
5897                (message "Quit getting the articles to read")
5898                nil))))))
5899     (setq select (if (stringp select) (string-to-number select) select))
5900     (if (or (null select) (zerop select))
5901         select
5902       (if (and (not (zerop scored)) (<= (abs select) scored))
5903           (progn
5904             (setq articles (sort scored-list '<))
5905             (setq number (length articles)))
5906         (setq articles (copy-sequence articles)))
5907
5908       (when (< (abs select) number)
5909         (if (< select 0)
5910             ;; Select the N oldest articles.
5911             (setcdr (nthcdr (1- (abs select)) articles) nil)
5912           ;; Select the N most recent articles.
5913           (setq articles (nthcdr (- number select) articles))))
5914       (setq gnus-newsgroup-unselected
5915             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5916       (when gnus-alter-articles-to-read-function
5917         (setq articles
5918               (sort
5919                (funcall gnus-alter-articles-to-read-function
5920                         gnus-newsgroup-name articles)
5921                '<)))
5922       articles)))
5923
5924 (defun gnus-killed-articles (killed articles)
5925   (let (out)
5926     (while articles
5927       (when (inline (gnus-member-of-range (car articles) killed))
5928         (push (car articles) out))
5929       (setq articles (cdr articles)))
5930     out))
5931
5932 (defun gnus-uncompress-marks (marks)
5933   "Uncompress the mark ranges in MARKS."
5934   (let ((uncompressed '(score bookmark))
5935         out)
5936     (while marks
5937       (if (memq (caar marks) uncompressed)
5938           (push (car marks) out)
5939         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5940       (setq marks (cdr marks)))
5941     out))
5942
5943 (defun gnus-article-mark-to-type (mark)
5944   "Return the type of MARK."
5945   (or (cadr (assq mark gnus-article-special-mark-lists))
5946       'list))
5947
5948 (defun gnus-article-unpropagatable-p (mark)
5949   "Return whether MARK should be propagated to back end."
5950   (memq mark gnus-article-unpropagated-mark-lists))
5951
5952 (defun gnus-adjust-marked-articles (info)
5953   "Set all article lists and remove all marks that are no longer valid."
5954   (let* ((marked-lists (gnus-info-marks info))
5955          (active (gnus-active (gnus-info-group info)))
5956          (min (car active))
5957          (max (cdr active))
5958          (types gnus-article-mark-lists)
5959          marks var articles article mark mark-type
5960          bgn end)
5961     ;; Hack to avoid adjusting marks for imap.
5962     (when (eq (car (gnus-find-method-for-group (gnus-info-group info)))
5963               'nnimap)
5964       (setq min 1))
5965
5966     (dolist (marks marked-lists)
5967       (setq mark (car marks)
5968             mark-type (gnus-article-mark-to-type mark)
5969             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5970
5971       ;; We set the variable according to the type of the marks list,
5972       ;; and then adjust the marks to a subset of the active articles.
5973       (cond
5974        ;; Adjust "simple" lists - compressed yet unsorted
5975        ((eq mark-type 'list)
5976         ;; Simultaneously uncompress and clip to active range
5977         ;; See gnus-uncompress-range for a description of possible marks
5978         (let (l lh)
5979           (if (not (cadr marks))
5980               (set var nil)
5981             (setq articles (if (numberp (cddr marks))
5982                                (list (cdr marks))
5983                              (cdr marks))
5984                   lh (cons nil nil)
5985                   l lh)
5986
5987             (while (setq article (pop articles))
5988               (cond ((consp article)
5989                      (setq bgn (max (car article) min)
5990                            end (min (cdr article) max))
5991                      (while (<= bgn end)
5992                        (setq l (setcdr l (cons bgn nil))
5993                              bgn (1+ bgn))))
5994                     ((and (<= min article)
5995                           (>= max article))
5996                      (setq l (setcdr l (cons article nil))))))
5997             (set var (cdr lh)))))
5998        ;; Adjust assocs.
5999        ((eq mark-type 'tuple)
6000         (set var (setq articles (cdr marks)))
6001         (when (not (listp (cdr (symbol-value var))))
6002           (set var (list (symbol-value var))))
6003         (when (not (listp (cdr articles)))
6004           (setq articles (list articles)))
6005         (while articles
6006           (when (or (not (consp (setq article (pop articles))))
6007                     (< (car article) min)
6008                     (> (car article) max))
6009             (set var (delq article (symbol-value var))))))
6010        ;; Adjust ranges (sloppily).
6011        ((eq mark-type 'range)
6012         (cond
6013          ((eq mark 'seen)
6014           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
6015           ;; It should be (seen (NUM1 . NUM2)).
6016           (when (numberp (cddr marks))
6017             (setcdr marks (list (cdr marks))))
6018           (setq articles (cdr marks))
6019           (while (and articles
6020                       (or (and (consp (car articles))
6021                                (> min (cdar articles)))
6022                           (and (numberp (car articles))
6023                                (> min (car articles)))))
6024             (pop articles))
6025           (set var articles))))))))
6026
6027 (defun gnus-update-missing-marks (missing)
6028   "Go through the list of MISSING articles and remove them from the mark lists."
6029   (when missing
6030     (let (var m)
6031       ;; Go through all types.
6032       (dolist (elem gnus-article-mark-lists)
6033         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
6034           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
6035           (when (symbol-value var)
6036             ;; This list has articles.  So we delete all missing
6037             ;; articles from it.
6038             (setq m missing)
6039             (while m
6040               (set var (delq (pop m) (symbol-value var))))))))))
6041
6042 (defun gnus-update-marks ()
6043   "Enter the various lists of marked articles into the newsgroup info list."
6044   (let ((types gnus-article-mark-lists)
6045         (info (gnus-get-info gnus-newsgroup-name))
6046         type list newmarked symbol delta-marks)
6047     (when info
6048       ;; Add all marks lists to the list of marks lists.
6049       (while (setq type (pop types))
6050         (setq list (symbol-value
6051                     (setq symbol
6052                           (intern (format "gnus-newsgroup-%s" (car type))))))
6053
6054         (when list
6055           ;; Get rid of the entries of the articles that have the
6056           ;; default score.
6057           (when (and (eq (cdr type) 'score)
6058                      gnus-save-score
6059                      list)
6060             (let* ((arts list)
6061                    (prev (cons nil list))
6062                    (all prev))
6063               (while arts
6064                 (if (or (not (consp (car arts)))
6065                         (= (cdar arts) gnus-summary-default-score))
6066                     (setcdr prev (cdr arts))
6067                   (setq prev arts))
6068                 (setq arts (cdr arts)))
6069               (setq list (cdr all)))))
6070
6071         (when (eq (cdr type) 'seen)
6072           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
6073
6074         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
6075           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
6076
6077         (when (and (gnus-check-backend-function
6078                     'request-set-mark gnus-newsgroup-name)
6079                    (not (gnus-article-unpropagatable-p (cdr type))))
6080           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
6081                  ;; Don't do anything about marks for articles we
6082                  ;; didn't actually get any headers for.
6083                  (del
6084                   (gnus-list-range-intersection
6085                    gnus-newsgroup-articles
6086                    (gnus-remove-from-range (gnus-copy-sequence old) list)))
6087                  (add
6088                   (gnus-list-range-intersection
6089                    gnus-newsgroup-articles
6090                    (gnus-remove-from-range
6091                     (gnus-copy-sequence list) old))))
6092             (when add
6093               (push (list add 'add (list (cdr type))) delta-marks))
6094             (when del
6095               ;; Don't delete marks from outside the active range.
6096               ;; This shouldn't happen, but is a sanity check.
6097               (setq del (gnus-sorted-range-intersection
6098                          (gnus-active gnus-newsgroup-name) del))
6099               (push (list del 'del (list (cdr type))) delta-marks))))
6100
6101         (when list
6102           (push (cons (cdr type) list) newmarked)))
6103
6104       (when delta-marks
6105         (unless (gnus-check-group gnus-newsgroup-name)
6106           (error "Can't open server for %s" gnus-newsgroup-name))
6107         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
6108
6109       ;; Enter these new marks into the info of the group.
6110       (if (nthcdr 3 info)
6111           (setcar (nthcdr 3 info) newmarked)
6112         ;; Add the marks lists to the end of the info.
6113         (when newmarked
6114           (setcdr (nthcdr 2 info) (list newmarked))))
6115
6116       ;; Cut off the end of the info if there's nothing else there.
6117       (let ((i 5))
6118         (while (and (> i 2)
6119                     (not (nth i info)))
6120           (when (nthcdr (decf i) info)
6121             (setcdr (nthcdr i info) nil)))))))
6122
6123 (defun gnus-set-mode-line (where)
6124   "Set the mode line of the article or summary buffers.
6125 If WHERE is `summary', the summary mode line format will be used."
6126   ;; Is this mode line one we keep updated?
6127   (when (and (memq where gnus-updated-mode-lines)
6128              (symbol-value
6129               (intern (format "gnus-%s-mode-line-format-spec" where))))
6130     (let (mode-string)
6131       ;; We evaluate this in the summary buffer since these
6132       ;; variables are buffer-local to that buffer.
6133       (with-current-buffer gnus-summary-buffer
6134         ;; We bind all these variables that are used in the `eval' form
6135         ;; below.
6136         (let* ((mformat (symbol-value
6137                          (intern
6138                           (format "gnus-%s-mode-line-format-spec" where))))
6139                (gnus-tmp-group-name (gnus-mode-string-quote
6140                                      (gnus-group-decoded-name
6141                                       gnus-newsgroup-name)))
6142                (gnus-tmp-article-number (or gnus-current-article 0))
6143                (gnus-tmp-unread gnus-newsgroup-unreads)
6144                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6145                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6146                (gnus-tmp-unread-and-unselected
6147                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6148                             (zerop gnus-tmp-unselected))
6149                        "")
6150                       ((zerop gnus-tmp-unselected)
6151                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6152                       (t (format "{%d(+%d) more}"
6153                                  gnus-tmp-unread-and-unticked
6154                                  gnus-tmp-unselected))))
6155                (gnus-tmp-subject
6156                 (if (and gnus-current-headers
6157                          (vectorp gnus-current-headers))
6158                     (gnus-mode-string-quote
6159                      (mail-header-subject gnus-current-headers))
6160                   ""))
6161                bufname-length max-len
6162                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6163           (setq mode-string (eval mformat))
6164           (setq bufname-length (if (string-match "%b" mode-string)
6165                                    (- (length
6166                                        (buffer-name
6167                                         (if (eq where 'summary)
6168                                             nil
6169                                           (get-buffer gnus-article-buffer))))
6170                                       2)
6171                                  0))
6172           (setq max-len (max 4 (if gnus-mode-non-string-length
6173                                    (- (window-width)
6174                                       gnus-mode-non-string-length
6175                                       bufname-length)
6176                                  (length mode-string))))
6177           ;; We might have to chop a bit of the string off...
6178           (when (> (length mode-string) max-len)
6179             (setq mode-string
6180                   (concat (truncate-string-to-width mode-string (- max-len 3))
6181                           "...")))))
6182       ;; Update the mode line.
6183       (setq mode-line-buffer-identification
6184             (gnus-mode-line-buffer-identification (list mode-string)))
6185       (set-buffer-modified-p t))))
6186
6187 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6188   "Go through the HEADERS list and add all Xrefs to a hash table.
6189 The resulting hash table is returned, or nil if no Xrefs were found."
6190   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6191          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6192          (xref-hashtb (gnus-make-hashtable))
6193          start group entry number xrefs header)
6194     (while headers
6195       (setq header (pop headers))
6196       (when (and (setq xrefs (mail-header-xref header))
6197                  (not (memq (setq number (mail-header-number header))
6198                             unreads)))
6199         (setq start 0)
6200         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6201           (setq start (match-end 0))
6202           (setq group (if prefix
6203                           (concat prefix (substring xrefs (match-beginning 1)
6204                                                     (match-end 1)))
6205                         (substring xrefs (match-beginning 1) (match-end 1))))
6206           (setq number
6207                 (string-to-number (substring xrefs (match-beginning 2)
6208                                           (match-end 2))))
6209           (if (setq entry (gnus-gethash group xref-hashtb))
6210               (setcdr entry (cons number (cdr entry)))
6211             (gnus-sethash group (cons number nil) xref-hashtb)))))
6212     (and start xref-hashtb)))
6213
6214 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6215   "Look through all the headers and mark the Xrefs as read."
6216   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6217         name info xref-hashtb idlist method nth4)
6218     (with-current-buffer gnus-group-buffer
6219       (when (setq xref-hashtb
6220                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6221         (mapatoms
6222          (lambda (group)
6223            (unless (string= from-newsgroup (setq name (symbol-name group)))
6224              (setq idlist (symbol-value group))
6225              ;; Dead groups are not updated.
6226              (and (prog1
6227                       (setq info (gnus-get-info name))
6228                     (when (stringp (setq nth4 (gnus-info-method info)))
6229                       (setq nth4 (gnus-server-to-method nth4))))
6230                   ;; Only do the xrefs if the group has the same
6231                   ;; select method as the group we have just read.
6232                   (or (gnus-methods-equal-p
6233                        nth4 (gnus-find-method-for-group from-newsgroup))
6234                       virtual
6235                       (equal nth4 (setq method (gnus-find-method-for-group
6236                                                 from-newsgroup)))
6237                       (and (equal (car nth4) (car method))
6238                            (equal (nth 1 nth4) (nth 1 method))))
6239                   gnus-use-cross-reference
6240                   (or (not (eq gnus-use-cross-reference t))
6241                       virtual
6242                       ;; Only do cross-references on subscribed
6243                       ;; groups, if that is what is wanted.
6244                       (<= (gnus-info-level info) gnus-level-subscribed))
6245                   (gnus-group-make-articles-read name idlist))))
6246          xref-hashtb)))))
6247
6248 (defun gnus-compute-read-articles (group articles)
6249   (let* ((entry (gnus-group-entry group))
6250          (info (nth 2 entry))
6251          (active (gnus-active group))
6252          ninfo)
6253     (when entry
6254       ;; First peel off all invalid article numbers.
6255       (when active
6256         (let ((ids articles)
6257               id first)
6258           (while (setq id (pop ids))
6259             (when (and first (> id (cdr active)))
6260               ;; We'll end up in this situation in one particular
6261               ;; obscure situation.  If you re-scan a group and get
6262               ;; a new article that is cross-posted to a different
6263               ;; group that has not been re-scanned, you might get
6264               ;; crossposted article that has a higher number than
6265               ;; Gnus believes possible.  So we re-activate this
6266               ;; group as well.  This might mean doing the
6267               ;; crossposting thingy will *increase* the number
6268               ;; of articles in some groups.  Tsk, tsk.
6269               (setq active (or (gnus-activate-group group) active)))
6270             (when (or (> id (cdr active))
6271                       (< id (car active)))
6272               (setq articles (delq id articles))))))
6273       ;; If the read list is nil, we init it.
6274       (if (and active
6275                (null (gnus-info-read info))
6276                (> (car active) 1))
6277           (setq ninfo (cons 1 (1- (car active))))
6278         (setq ninfo (gnus-info-read info)))
6279       ;; Then we add the read articles to the range.
6280       (gnus-add-to-range
6281        ninfo (setq articles (sort articles '<))))))
6282
6283 (defun gnus-group-make-articles-read (group articles)
6284   "Update the info of GROUP to say that ARTICLES are read."
6285   (let* ((num 0)
6286          (entry (gnus-group-entry group))
6287          (info (nth 2 entry))
6288          (active (gnus-active group))
6289          range)
6290     (if (not entry)
6291         ;; Group that Gnus doesn't know exists, but still allow the
6292         ;; backend to set marks.
6293         (gnus-request-set-mark
6294          group (list (list (gnus-compress-sequence (sort articles #'<))
6295                            'add '(read))))
6296       ;; Normal, subscribed groups.
6297       (setq range (gnus-compute-read-articles group articles))
6298       (with-current-buffer gnus-group-buffer
6299         (gnus-undo-register
6300           `(progn
6301              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6302              (gnus-info-set-read ',info ',(gnus-info-read info))
6303              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6304              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6305              (gnus-group-update-group ,group t))))
6306       ;; Add the read articles to the range.
6307       (gnus-info-set-read info range)
6308       (gnus-request-set-mark group (list (list range 'add '(read))))
6309       ;; Then we have to re-compute how many unread
6310       ;; articles there are in this group.
6311       (when active
6312         (cond
6313          ((not range)
6314           (setq num (- (1+ (cdr active)) (car active))))
6315          ((not (listp (cdr range)))
6316           (setq num (- (cdr active) (- (1+ (cdr range))
6317                                        (car range)))))
6318          (t
6319           (while range
6320             (if (numberp (car range))
6321                 (setq num (1+ num))
6322               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6323             (setq range (cdr range)))
6324           (setq num (- (cdr active) num))))
6325         ;; Update the number of unread articles.
6326         (setcar entry num)
6327         ;; Update the group buffer.
6328         (unless (gnus-ephemeral-group-p group)
6329           (gnus-group-update-group group t))))))
6330
6331 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6332   (let ((cur nntp-server-buffer)
6333         (dependencies
6334          (or dependencies
6335              (with-current-buffer gnus-summary-buffer
6336                gnus-newsgroup-dependencies)))
6337         headers id end ref number
6338         (mail-parse-charset gnus-newsgroup-charset)
6339         (mail-parse-ignored-charsets
6340          (save-current-buffer (condition-case nil
6341                                   (set-buffer gnus-summary-buffer)
6342                                 (error))
6343                               gnus-newsgroup-ignored-charsets)))
6344     (with-current-buffer nntp-server-buffer
6345       ;; Translate all TAB characters into SPACE characters.
6346       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6347       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6348       (ietf-drums-unfold-fws)
6349       (gnus-run-hooks 'gnus-parse-headers-hook)
6350       (let ((case-fold-search t)
6351             in-reply-to header p lines chars)
6352         (goto-char (point-min))
6353         ;; Search to the beginning of the next header.  Error messages
6354         ;; do not begin with 2 or 3.
6355         (while (re-search-forward "^[23][0-9]+ " nil t)
6356           (setq id nil
6357                 ref nil)
6358           ;; This implementation of this function, with nine
6359           ;; search-forwards instead of the one re-search-forward and
6360           ;; a case (which basically was the old function) is actually
6361           ;; about twice as fast, even though it looks messier.  You
6362           ;; can't have everything, I guess.  Speed and elegance
6363           ;; doesn't always go hand in hand.
6364           (setq
6365            header
6366            (vector
6367             ;; Number.
6368             (prog1
6369                 (setq number (read cur))
6370               (end-of-line)
6371               (setq p (point))
6372               (narrow-to-region (point)
6373                                 (or (and (search-forward "\n.\n" nil t)
6374                                          (- (point) 2))
6375                                     (point))))
6376             ;; Subject.
6377             (progn
6378               (goto-char p)
6379               (if (search-forward "\nsubject:" nil t)
6380                   (funcall gnus-decode-encoded-word-function
6381                            (nnheader-header-value))
6382                 "(none)"))
6383             ;; From.
6384             (progn
6385               (goto-char p)
6386               (if (search-forward "\nfrom:" nil t)
6387                   (funcall gnus-decode-encoded-address-function
6388                            (nnheader-header-value))
6389                 "(nobody)"))
6390             ;; Date.
6391             (progn
6392               (goto-char p)
6393               (if (search-forward "\ndate:" nil t)
6394                   (nnheader-header-value) ""))
6395             ;; Message-ID.
6396             (progn
6397               (goto-char p)
6398               (setq id (if (re-search-forward
6399                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6400                            ;; We do it this way to make sure the Message-ID
6401                            ;; is (somewhat) syntactically valid.
6402                            (buffer-substring (match-beginning 1)
6403                                              (match-end 1))
6404                          ;; If there was no message-id, we just fake one
6405                          ;; to make subsequent routines simpler.
6406                          (nnheader-generate-fake-message-id number))))
6407             ;; References.
6408             (progn
6409               (goto-char p)
6410               (if (search-forward "\nreferences:" nil t)
6411                   (progn
6412                     (setq end (point))
6413                     (prog1
6414                         (nnheader-header-value)
6415                       (setq ref
6416                             (buffer-substring
6417                              (progn
6418                                (end-of-line)
6419                                (search-backward ">" end t)
6420                                (1+ (point)))
6421                              (progn
6422                                (search-backward "<" end t)
6423                                (point))))))
6424                 ;; Get the references from the in-reply-to header if there
6425                 ;; were no references and the in-reply-to header looks
6426                 ;; promising.
6427                 (if (and (search-forward "\nin-reply-to:" nil t)
6428                          (setq in-reply-to (nnheader-header-value))
6429                          (string-match "<[^>]+>" in-reply-to))
6430                     (let (ref2)
6431                       (setq ref (substring in-reply-to (match-beginning 0)
6432                                            (match-end 0)))
6433                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6434                         (setq ref2 (substring in-reply-to (match-beginning 0)
6435                                               (match-end 0)))
6436                         (when (> (length ref2) (length ref))
6437                           (setq ref ref2)))
6438                       ref)
6439                   (setq ref nil))))
6440             ;; Chars.
6441             (progn
6442               (goto-char p)
6443               (if (search-forward "\nchars: " nil t)
6444                   (if (numberp (setq chars (ignore-errors (read cur))))
6445                       chars -1)
6446                 -1))
6447             ;; Lines.
6448             (progn
6449               (goto-char p)
6450               (if (search-forward "\nlines: " nil t)
6451                   (if (numberp (setq lines (ignore-errors (read cur))))
6452                       lines -1)
6453                 -1))
6454             ;; Xref.
6455             (progn
6456               (goto-char p)
6457               (and (search-forward "\nxref:" nil t)
6458                    (nnheader-header-value)))
6459             ;; Extra.
6460             (when gnus-extra-headers
6461               (let ((extra gnus-extra-headers)
6462                     out)
6463                 (while extra
6464                   (goto-char p)
6465                   (when (search-forward
6466                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6467                     (push (cons (car extra) (nnheader-header-value))
6468                           out))
6469                   (pop extra))
6470                 out))))
6471           (when (equal id ref)
6472             (setq ref nil))
6473
6474           (when gnus-alter-header-function
6475             (funcall gnus-alter-header-function header)
6476             (setq id (mail-header-id header)
6477                   ref (gnus-parent-id (mail-header-references header))))
6478
6479           (when (setq header
6480                       (gnus-dependencies-add-header
6481                        header dependencies force-new))
6482             (push header headers))
6483           (goto-char (point-max))
6484           (widen))
6485         (nreverse headers)))))
6486
6487 ;; Goes through the xover lines and returns a list of vectors
6488 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6489                                                   force-new dependencies
6490                                                   group also-fetch-heads)
6491   "Parse the news overview data in the server buffer.
6492 Return a list of headers that match SEQUENCE (see
6493 `nntp-retrieve-headers')."
6494   ;; Get the Xref when the users reads the articles since most/some
6495   ;; NNTP servers do not include Xrefs when using XOVER.
6496   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6497   (let ((mail-parse-charset gnus-newsgroup-charset)
6498         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6499         (cur nntp-server-buffer)
6500         (dependencies (or dependencies gnus-newsgroup-dependencies))
6501         (allp (cond
6502                ((eq gnus-read-all-available-headers t)
6503                 t)
6504                ((and (stringp gnus-read-all-available-headers)
6505                      group)
6506                 (string-match gnus-read-all-available-headers group))
6507                (t
6508                 nil)))
6509         number headers header)
6510     (with-current-buffer nntp-server-buffer
6511       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6512       ;; Allow the user to mangle the headers before parsing them.
6513       (gnus-run-hooks 'gnus-parse-headers-hook)
6514       (goto-char (point-min))
6515       (gnus-parse-without-error
6516         (while (and (or sequence allp)
6517                     (not (eobp)))
6518           (setq number (read cur))
6519           (when (not allp)
6520             (while (and sequence
6521                         (< (car sequence) number))
6522               (setq sequence (cdr sequence))))
6523           (when (and (or allp
6524                          (and sequence
6525                               (eq number (car sequence))))
6526                      (progn
6527                        (setq sequence (cdr sequence))
6528                        (setq header (inline
6529                                       (gnus-nov-parse-line
6530                                        number dependencies force-new)))))
6531             (push header headers))
6532           (forward-line 1)))
6533       ;; A common bug in inn is that if you have posted an article and
6534       ;; then retrieves the active file, it will answer correctly --
6535       ;; the new article is included.  However, a NOV entry for the
6536       ;; article may not have been generated yet, so this may fail.
6537       ;; We work around this problem by retrieving the last few
6538       ;; headers using HEAD.
6539       (if (or (not also-fetch-heads)
6540               (not sequence))
6541           ;; We (probably) got all the headers.
6542           (nreverse headers)
6543         (let ((gnus-nov-is-evil t))
6544           (nconc
6545            (nreverse headers)
6546            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6547              (gnus-get-newsgroup-headers))))))))
6548
6549 (defun gnus-article-get-xrefs ()
6550   "Fill in the Xref value in `gnus-current-headers', if necessary.
6551 This is meant to be called in `gnus-article-internal-prepare-hook'."
6552   (let ((headers (with-current-buffer gnus-summary-buffer
6553                    gnus-current-headers)))
6554     (or (not gnus-use-cross-reference)
6555         (not headers)
6556         (and (mail-header-xref headers)
6557              (not (string= (mail-header-xref headers) "")))
6558         (let ((case-fold-search t)
6559               xref)
6560           (save-restriction
6561             (nnheader-narrow-to-headers)
6562             (goto-char (point-min))
6563             (when (or (and (not (eobp))
6564                            (eq (downcase (char-after)) ?x)
6565                            (looking-at "Xref:"))
6566                       (search-forward "\nXref:" nil t))
6567               (goto-char (1+ (match-end 0)))
6568               (setq xref (buffer-substring (point) (point-at-eol)))
6569               (mail-header-set-xref headers xref)))))))
6570
6571 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6572   "Find article ID and insert the summary line for that article.
6573 OLD-HEADER can either be a header or a line number to insert
6574 the subject line on.
6575 If USE-OLD-HEADER is non-nil, then OLD-HEADER should be a header,
6576 and OLD-HEADER will be used when the summary line is inserted,
6577 too, instead of trying to fetch new headers."
6578   (let* ((line (and (numberp old-header) old-header))
6579          (old-header (and (vectorp old-header) old-header))
6580          (header (cond ((and old-header use-old-header)
6581                         old-header)
6582                        ((and (numberp id)
6583                              (gnus-number-to-header id))
6584                         (gnus-number-to-header id))
6585                        (t
6586                         (gnus-read-header id))))
6587          (number (and (numberp id) id))
6588          d)
6589     (when header
6590       ;; Rebuild the thread that this article is part of and go to the
6591       ;; article we have fetched.
6592       (when (and (not gnus-show-threads)
6593                  old-header)
6594         (when (and number
6595                    (setq d (gnus-data-find (mail-header-number old-header))))
6596           (goto-char (gnus-data-pos d))
6597           (gnus-data-remove
6598            number
6599            (- (point-at-bol)
6600               (prog1
6601                   (1+ (point-at-eol))
6602                 (gnus-delete-line))))))
6603       ;; Remove list identifiers from subject.
6604       (let ((gnus-newsgroup-headers (list header)))
6605         (gnus-summary-remove-list-identifiers))
6606       (when old-header
6607         (mail-header-set-number header (mail-header-number old-header)))
6608       (setq gnus-newsgroup-sparse
6609             (delq (setq number (mail-header-number header))
6610                   gnus-newsgroup-sparse))
6611       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6612       (push number gnus-newsgroup-limit)
6613       (gnus-rebuild-thread (mail-header-id header) line)
6614       (gnus-summary-goto-subject number nil t))
6615     (when (and (numberp number)
6616                (> number 0))
6617       ;; We have to update the boundaries even if we can't fetch the
6618       ;; article if ID is a number -- so that the next `P' or `N'
6619       ;; command will fetch the previous (or next) article even
6620       ;; if the one we tried to fetch this time has been canceled.
6621       (when (> number gnus-newsgroup-end)
6622         (setq gnus-newsgroup-end number))
6623       (when (< number gnus-newsgroup-begin)
6624         (setq gnus-newsgroup-begin number))
6625       (setq gnus-newsgroup-unselected
6626             (delq number gnus-newsgroup-unselected)))
6627     ;; Report back a success?
6628     (and header (mail-header-number header))))
6629
6630 ;;; Process/prefix in the summary buffer
6631
6632 (defun gnus-summary-work-articles (n)
6633   "Return a list of articles to be worked upon.
6634 The prefix argument, the list of process marked articles, and the
6635 current article will be taken into consideration."
6636   (with-current-buffer gnus-summary-buffer
6637     (cond
6638      (n
6639       ;; A numerical prefix has been given.
6640       (setq n (prefix-numeric-value n))
6641       (let ((backward (< n 0))
6642             (n (abs (prefix-numeric-value n)))
6643             articles article)
6644         (save-excursion
6645           (while
6646               (and (> n 0)
6647                    (push (setq article (gnus-summary-article-number))
6648                          articles)
6649                    (if backward
6650                        (gnus-summary-find-prev nil article)
6651                      (gnus-summary-find-next nil article)))
6652             (decf n)))
6653         (nreverse articles)))
6654      ((and (gnus-region-active-p) (mark))
6655       (message "region active")
6656       ;; Work on the region between point and mark.
6657       (let ((max (max (point) (mark)))
6658             articles article)
6659         (save-excursion
6660           (goto-char (min (point) (mark)))
6661           (while
6662               (and
6663                (push (setq article (gnus-summary-article-number)) articles)
6664                (gnus-summary-find-next nil article)
6665                (< (point) max)))
6666           (nreverse articles))))
6667      (gnus-newsgroup-processable
6668       ;; There are process-marked articles present.
6669       ;; Save current state.
6670       (gnus-summary-save-process-mark)
6671       ;; Return the list.
6672       (reverse gnus-newsgroup-processable))
6673      (t
6674       ;; Just return the current article.
6675       (list (gnus-summary-article-number))))))
6676
6677 (defmacro gnus-summary-iterate (arg &rest forms)
6678   "Iterate over the process/prefixed articles and do FORMS.
6679 ARG is the interactive prefix given to the command.  FORMS will be
6680 executed with point over the summary line of the articles."
6681   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6682     `(let ((,articles (gnus-summary-work-articles ,arg)))
6683        (while ,articles
6684          (gnus-summary-goto-subject (car ,articles))
6685          ,@forms
6686          (pop ,articles)))))
6687
6688 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6689 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6690
6691 (defun gnus-summary-save-process-mark ()
6692   "Push the current set of process marked articles on the stack."
6693   (interactive)
6694   (push (copy-sequence gnus-newsgroup-processable)
6695         gnus-newsgroup-process-stack))
6696
6697 (defun gnus-summary-kill-process-mark ()
6698   "Push the current set of process marked articles on the stack and unmark."
6699   (interactive)
6700   (gnus-summary-save-process-mark)
6701   (gnus-summary-unmark-all-processable))
6702
6703 (defun gnus-summary-yank-process-mark ()
6704   "Pop the last process mark state off the stack and restore it."
6705   (interactive)
6706   (unless gnus-newsgroup-process-stack
6707     (error "Empty mark stack"))
6708   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6709
6710 (defun gnus-summary-process-mark-set (set)
6711   "Make SET into the current process marked articles."
6712   (gnus-summary-unmark-all-processable)
6713   (mapc 'gnus-summary-set-process-mark set))
6714
6715 ;;; Searching and stuff
6716
6717 (defun gnus-summary-search-group (&optional backward use-level)
6718   "Search for next unread newsgroup.
6719 If optional argument BACKWARD is non-nil, search backward instead."
6720   (with-current-buffer gnus-group-buffer
6721     (when (gnus-group-search-forward
6722            backward nil (if use-level (gnus-group-group-level) nil))
6723       (gnus-group-group-name))))
6724
6725 (defun gnus-summary-best-group (&optional exclude-group)
6726   "Find the name of the best unread group.
6727 If EXCLUDE-GROUP, do not go to this group."
6728   (with-current-buffer gnus-group-buffer
6729     (save-excursion
6730       (gnus-group-best-unread-group exclude-group))))
6731
6732 (defun gnus-summary-find-next (&optional unread article backward)
6733   (if backward
6734       (gnus-summary-find-prev unread article)
6735     (let* ((dummy (gnus-summary-article-intangible-p))
6736            (article (or article (gnus-summary-article-number)))
6737            (data (gnus-data-find-list article))
6738            result)
6739       (when (and (not dummy)
6740                  (or (not gnus-summary-check-current)
6741                      (not unread)
6742                      (not (gnus-data-unread-p (car data)))))
6743         (setq data (cdr data)))
6744       (when (setq result
6745                   (if unread
6746                       (progn
6747                         (while data
6748                           (unless (memq (gnus-data-number (car data))
6749                                         (cond
6750                                          ((eq gnus-auto-goto-ignores
6751                                               'always-undownloaded)
6752                                           gnus-newsgroup-undownloaded)
6753                                          (gnus-plugged
6754                                           nil)
6755                                          ((eq gnus-auto-goto-ignores
6756                                               'unfetched)
6757                                           gnus-newsgroup-unfetched)
6758                                          ((eq gnus-auto-goto-ignores
6759                                               'undownloaded)
6760                                           gnus-newsgroup-undownloaded)))
6761                             (when (gnus-data-unread-p (car data))
6762                               (setq result (car data)
6763                                     data nil)))
6764                           (setq data (cdr data)))
6765                         result)
6766                     (car data)))
6767         (goto-char (gnus-data-pos result))
6768         (gnus-data-number result)))))
6769
6770 (defun gnus-summary-find-prev (&optional unread article)
6771   (let* ((eobp (eobp))
6772          (article (or article (gnus-summary-article-number)))
6773          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6774          result)
6775     (when (and (not eobp)
6776                (or (not gnus-summary-check-current)
6777                    (not unread)
6778                    (not (gnus-data-unread-p (car data)))))
6779       (setq data (cdr data)))
6780     (when (setq result
6781                 (if unread
6782                     (progn
6783                       (while data
6784                         (unless (memq (gnus-data-number (car data))
6785                                       (cond
6786                                        ((eq gnus-auto-goto-ignores
6787                                             'always-undownloaded)
6788                                         gnus-newsgroup-undownloaded)
6789                                        (gnus-plugged
6790                                         nil)
6791                                        ((eq gnus-auto-goto-ignores
6792                                             'unfetched)
6793                                         gnus-newsgroup-unfetched)
6794                                        ((eq gnus-auto-goto-ignores
6795                                             'undownloaded)
6796                                         gnus-newsgroup-undownloaded)))
6797                           (when (gnus-data-unread-p (car data))
6798                             (setq result (car data)
6799                                   data nil)))
6800                         (setq data (cdr data)))
6801                       result)
6802                   (car data)))
6803       (goto-char (gnus-data-pos result))
6804       (gnus-data-number result))))
6805
6806 (defun gnus-summary-find-subject (subject &optional unread backward article)
6807   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6808          (article (or article (gnus-summary-article-number)))
6809          (articles (gnus-data-list backward))
6810          (arts (gnus-data-find-list article articles))
6811          result)
6812     (when (or (not gnus-summary-check-current)
6813               (not unread)
6814               (not (gnus-data-unread-p (car arts))))
6815       (setq arts (cdr arts)))
6816     (while arts
6817       (and (or (not unread)
6818                (gnus-data-unread-p (car arts)))
6819            (vectorp (gnus-data-header (car arts)))
6820            (gnus-subject-equal
6821             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6822            (setq result (car arts)
6823                  arts nil))
6824       (setq arts (cdr arts)))
6825     (and result
6826          (goto-char (gnus-data-pos result))
6827          (gnus-data-number result))))
6828
6829 (defun gnus-summary-search-forward (&optional unread subject backward)
6830   "Search forward for an article.
6831 If UNREAD, look for unread articles.  If SUBJECT, look for
6832 articles with that subject.  If BACKWARD, search backward instead."
6833   (cond (subject (gnus-summary-find-subject subject unread backward))
6834         (backward (gnus-summary-find-prev unread))
6835         (t (gnus-summary-find-next unread))))
6836
6837 (defun gnus-recenter (&optional n)
6838   "Center point in window and redisplay frame.
6839 Also do horizontal recentering."
6840   (interactive "P")
6841   (when (and gnus-auto-center-summary
6842              (not (eq gnus-auto-center-summary 'vertical)))
6843     (gnus-horizontal-recenter))
6844   (if (fboundp 'recenter-top-bottom)
6845       (recenter-top-bottom n)
6846     (recenter n)))
6847
6848 (put 'gnus-recenter 'isearch-scroll t)
6849
6850 (defun gnus-forward-line-ignore-invisible (n)
6851   "Move N lines forward (backward if N is negative).
6852 Like forward-line, but skip over (and don't count) invisible lines."
6853   (let (done)
6854     (while (and (> n 0) (not done))
6855       ;; If the following character is currently invisible,
6856       ;; skip all characters with that same `invisible' property value.
6857       (while (gnus-invisible-p (point))
6858         (goto-char (gnus-next-char-property-change (point))))
6859       (forward-line 1)
6860       (if (eobp)
6861           (setq done t)
6862         (setq n (1- n))))
6863     (while (and (< n 0) (not done))
6864       (forward-line -1)
6865       (if (bobp) (setq done t)
6866         (setq n (1+ n))
6867         (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6868           (goto-char (gnus-previous-char-property-change (point))))))))
6869
6870 (defun gnus-summary-recenter ()
6871   "Center point in the summary window.
6872 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6873 displayed, no centering will be performed."
6874   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6875   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6876   (interactive)
6877   ;; The user has to want it.
6878   (when gnus-auto-center-summary
6879     (let* ((top (cond ((< (window-height) 4) 0)
6880                       ((< (window-height) 7) 1)
6881                       (t (if (numberp gnus-auto-center-summary)
6882                              gnus-auto-center-summary
6883                            (/ (1- (window-height)) 2)))))
6884            (height (1- (window-height)))
6885            (bottom (save-excursion
6886                      (goto-char (point-max))
6887                      (gnus-forward-line-ignore-invisible (- height))
6888                      (point)))
6889            (window (get-buffer-window (current-buffer))))
6890       (when (get-buffer-window gnus-article-buffer)
6891         ;; Only do recentering when the article buffer is displayed,
6892         ;; Set the window start to either `bottom', which is the biggest
6893         ;; possible valid number, or the second line from the top,
6894         ;; whichever is the least.
6895         (let ((top-pos (save-excursion
6896                          (gnus-forward-line-ignore-invisible (- top))
6897                          (point))))
6898           (if (> bottom top-pos)
6899               ;; Keep the second line from the top visible
6900               (set-window-start window top-pos)
6901             ;; Try to keep the bottom line visible; if it's partially
6902             ;; obscured, either scroll one more line to make it fully
6903             ;; visible, or revert to using TOP-POS.
6904             (save-excursion
6905               (goto-char (point-max))
6906               (gnus-forward-line-ignore-invisible -1)
6907               (let ((last-line-start (point)))
6908                 (goto-char bottom)
6909                 (set-window-start window (point) t)
6910                 (when (not (pos-visible-in-window-p last-line-start window))
6911                   (gnus-forward-line-ignore-invisible 1)
6912                   (set-window-start window (min (point) top-pos) t)))))))
6913       ;; Do horizontal recentering while we're at it.
6914       (when (and (get-buffer-window (current-buffer) t)
6915                  (not (eq gnus-auto-center-summary 'vertical)))
6916         (let ((selected (selected-window)))
6917           (select-window (get-buffer-window (current-buffer) t))
6918           (gnus-summary-position-point)
6919           (gnus-horizontal-recenter)
6920           (select-window selected))))))
6921
6922 (defun gnus-summary-jump-to-group (newsgroup)
6923   "Move point to NEWSGROUP in group mode buffer."
6924   ;; Keep update point of group mode buffer if visible.
6925   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6926       (save-window-excursion
6927         ;; Take care of tree window mode.
6928         (when (get-buffer-window gnus-group-buffer)
6929           (pop-to-buffer gnus-group-buffer))
6930         (gnus-group-jump-to-group newsgroup))
6931     (save-excursion
6932       ;; Take care of tree window mode.
6933       (if (get-buffer-window gnus-group-buffer 0)
6934           (pop-to-buffer gnus-group-buffer)
6935         (set-buffer gnus-group-buffer))
6936       (gnus-group-jump-to-group newsgroup))))
6937
6938 ;; This function returns a list of article numbers based on the
6939 ;; difference between the ranges of read articles in this group and
6940 ;; the range of active articles.
6941 (defun gnus-list-of-unread-articles (group)
6942   (let* ((read (gnus-info-read (gnus-get-info group)))
6943          (active (or (gnus-active group) (gnus-activate-group group)))
6944          (last (or (cdr active)
6945                    (error "Group %s couldn't be activated " group)))
6946          (bottom (if gnus-newsgroup-maximum-articles
6947                      (max (car active)
6948                           (- last gnus-newsgroup-maximum-articles -1))
6949                    (car active)))
6950          first nlast unread)
6951     ;; If none are read, then all are unread.
6952     (if (not read)
6953         (setq first bottom)
6954       ;; If the range of read articles is a single range, then the
6955       ;; first unread article is the article after the last read
6956       ;; article.  Sounds logical, doesn't it?
6957       (if (and (not (listp (cdr read)))
6958                (or (< (car read) bottom)
6959                    (progn (setq read (list read))
6960                           nil)))
6961           (setq first (max bottom (1+ (cdr read))))
6962         ;; `read' is a list of ranges.
6963         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6964                                   (caar read)))
6965                   1)
6966           (setq first bottom))
6967         (while read
6968           (when first
6969             (while (< first nlast)
6970               (setq unread (cons first unread)
6971                     first (1+ first))))
6972           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6973           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6974           (setq read (cdr read)))))
6975     ;; And add the last unread articles.
6976     (while (<= first last)
6977       (setq unread (cons first unread)
6978             first (1+ first)))
6979     ;; Return the list of unread articles.
6980     (delq 0 (nreverse unread))))
6981
6982 (defun gnus-list-of-read-articles (group)
6983   "Return a list of unread, unticked and non-dormant articles."
6984   (let* ((info (gnus-get-info group))
6985          (marked (gnus-info-marks info))
6986          (active (gnus-active group)))
6987     (and info active
6988          (gnus-list-range-difference
6989           (gnus-list-range-difference
6990            (gnus-sorted-complement
6991             (gnus-uncompress-range
6992              (if gnus-newsgroup-maximum-articles
6993                  (cons (max (car active)
6994                             (- (cdr active)
6995                                gnus-newsgroup-maximum-articles
6996                                -1))
6997                        (cdr active))
6998                active))
6999             (gnus-list-of-unread-articles group))
7000            (cdr (assq 'dormant marked)))
7001           (cdr (assq 'tick marked))))))
7002
7003 ;; This function returns a sequence of article numbers based on the
7004 ;; difference between the ranges of read articles in this group and
7005 ;; the range of active articles.
7006 (defun gnus-sequence-of-unread-articles (group)
7007   (let* ((read (gnus-info-read (gnus-get-info group)))
7008          (active (or (gnus-active group) (gnus-activate-group group)))
7009          (last (cdr active))
7010          (bottom (if gnus-newsgroup-maximum-articles
7011                      (max (car active)
7012                           (- last gnus-newsgroup-maximum-articles -1))
7013                    (car active)))
7014          first nlast unread)
7015     ;; If none are read, then all are unread.
7016     (if (not read)
7017         (setq first bottom)
7018       ;; If the range of read articles is a single range, then the
7019       ;; first unread article is the article after the last read
7020       ;; article.  Sounds logical, doesn't it?
7021       (if (and (not (listp (cdr read)))
7022                (or (< (car read) bottom)
7023                    (progn (setq read (list read))
7024                           nil)))
7025           (setq first (max bottom (1+ (cdr read))))
7026         ;; `read' is a list of ranges.
7027         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
7028                                   (caar read)))
7029                   1)
7030           (setq first bottom))
7031         (while read
7032           (when first
7033             (push (cons first nlast) unread))
7034           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
7035           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
7036           (setq read (cdr read)))))
7037     ;; And add the last unread articles.
7038     (cond ((not (and first last))
7039            nil)
7040           ((< first last)
7041            (push (cons first last) unread))
7042           ((= first last)
7043            (push first unread)))
7044     ;; Return the sequence of unread articles.
7045     (delq 0 (nreverse unread))))
7046
7047 ;; Various summary commands
7048
7049 (defun gnus-summary-select-article-buffer ()
7050   "Reconfigure windows to show the article buffer.
7051 If `gnus-widen-article-window' is set, show only the article
7052 buffer."
7053   (interactive)
7054   (if (not (gnus-buffer-live-p gnus-article-buffer))
7055       (error "There is no article buffer for this summary buffer")
7056     (unless (get-buffer-window gnus-article-buffer)
7057       (gnus-summary-show-article))
7058     (gnus-configure-windows
7059      (if gnus-widen-article-window
7060          'only-article
7061        'article)
7062      t)
7063     (select-window (get-buffer-window gnus-article-buffer))))
7064
7065 (defun gnus-summary-universal-argument (arg)
7066   "Perform any operation on all articles that are process/prefixed."
7067   (interactive "P")
7068   (let ((articles (gnus-summary-work-articles arg))
7069         func article)
7070     (if (eq
7071          (setq
7072           func
7073           (key-binding
7074            (read-key-sequence
7075             (substitute-command-keys
7076              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
7077          'undefined)
7078         (gnus-error 1 "Undefined key")
7079       (save-excursion
7080         (while articles
7081           (gnus-summary-goto-subject (setq article (pop articles)))
7082           (let (gnus-newsgroup-processable)
7083             (command-execute func))
7084           (gnus-summary-remove-process-mark article)))))
7085   (gnus-summary-position-point))
7086
7087 (defun gnus-summary-toggle-truncation (&optional arg)
7088   "Toggle truncation of summary lines.
7089 With ARG, turn line truncation on if ARG is positive."
7090   (interactive "P")
7091   (setq truncate-lines
7092         (if (null arg) (not truncate-lines)
7093           (> (prefix-numeric-value arg) 0)))
7094   (redraw-display))
7095
7096 (defun gnus-summary-find-for-reselect ()
7097   "Return the number of an article to stay on across a reselect.
7098 The current article is considered, then following articles, then previous
7099 articles.  An article is sought which is not cancelled and isn't a temporary
7100 insertion from another group.  If there's no such then return a dummy 0."
7101   (let (found)
7102     (dolist (rev '(nil t))
7103       (unless found      ; don't demand the reverse list if we don't need it
7104         (let ((data (gnus-data-find-list
7105                      (gnus-summary-article-number) (gnus-data-list rev))))
7106           (while (and data (not found))
7107             (if (and (< 0 (gnus-data-number (car data)))
7108                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
7109                 (setq found (gnus-data-number (car data))))
7110             (setq data (cdr data))))))
7111     (or found 0)))
7112
7113 (defun gnus-summary-reselect-current-group (&optional all rescan)
7114   "Exit and then reselect the current newsgroup.
7115 The prefix argument ALL means to select all articles."
7116   (interactive "P")
7117   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
7118     (error "Ephemeral groups can't be reselected"))
7119   (let ((current-subject (gnus-summary-find-for-reselect))
7120         (group gnus-newsgroup-name))
7121     (setq gnus-newsgroup-begin nil)
7122     (gnus-summary-exit nil 'leave-hidden)
7123     ;; We have to adjust the point of group mode buffer because
7124     ;; point was moved to the next unread newsgroup by exiting.
7125     (gnus-summary-jump-to-group group)
7126     (when rescan
7127       (save-excursion
7128         (gnus-group-get-new-news-this-group 1)))
7129     (gnus-group-read-group all t)
7130     (gnus-summary-goto-subject current-subject nil t)))
7131
7132 (defun gnus-summary-rescan-group (&optional all)
7133   "Exit the newsgroup, ask for new articles, and select the newsgroup."
7134   (interactive "P")
7135   (let ((config gnus-current-window-configuration))
7136     (gnus-summary-reselect-current-group all t)
7137     (gnus-configure-windows config)
7138     (when (eq config 'article)
7139       (gnus-summary-select-article))))
7140
7141 (defun gnus-summary-update-info (&optional non-destructive)
7142   (save-excursion
7143     (let ((group gnus-newsgroup-name))
7144       (when group
7145         (when gnus-newsgroup-kill-headers
7146           (setq gnus-newsgroup-killed
7147                 (gnus-compress-sequence
7148                  (gnus-sorted-union
7149                   (gnus-list-range-intersection
7150                    gnus-newsgroup-unselected gnus-newsgroup-killed)
7151                   gnus-newsgroup-unreads)
7152                  t)))
7153         (unless (listp (cdr gnus-newsgroup-killed))
7154           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7155         (let ((headers gnus-newsgroup-headers)
7156               (ephemeral-p (gnus-ephemeral-group-p group))
7157               info)
7158           (unless ephemeral-p
7159             (setq info (copy-sequence (gnus-get-info group))
7160                   info (delq (gnus-info-params info) info)))
7161           ;; Set the new ranges of read articles.
7162           (with-current-buffer gnus-group-buffer
7163             (gnus-undo-force-boundary))
7164           (gnus-update-read-articles
7165            group (gnus-sorted-union
7166                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
7167           ;; Set the current article marks.
7168           (let ((gnus-newsgroup-scored
7169                  (if (and (not gnus-save-score)
7170                           (not non-destructive))
7171                      nil
7172                    gnus-newsgroup-scored)))
7173             (save-excursion
7174               (gnus-update-marks)))
7175           ;; Do the cross-ref thing.
7176           (when gnus-use-cross-reference
7177             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7178           ;; Do not switch windows but change the buffer to work.
7179           (set-buffer gnus-group-buffer)
7180           (unless ephemeral-p
7181             (gnus-group-update-group
7182              group nil
7183              (equal info
7184                     (setq info (copy-sequence (gnus-get-info group))
7185                           info (delq (gnus-info-params info) info))))))))))
7186
7187 (defun gnus-summary-save-newsrc (&optional force)
7188   "Save the current number of read/marked articles in the dribble buffer.
7189 The dribble buffer will then be saved.
7190 If FORCE (the prefix), also save the .newsrc file(s)."
7191   (interactive "P")
7192   (gnus-summary-update-info t)
7193   (if force
7194       (gnus-save-newsrc-file)
7195     (gnus-dribble-save)))
7196
7197 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7198
7199 (defun gnus-summary-exit (&optional temporary leave-hidden)
7200   "Exit reading current newsgroup, and then return to group selection mode.
7201 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
7202   (interactive)
7203   (gnus-set-global-variables)
7204   (when (gnus-buffer-live-p gnus-article-buffer)
7205     (with-current-buffer gnus-article-buffer
7206       (mm-destroy-parts gnus-article-mime-handles)
7207       ;; Set it to nil for safety reason.
7208       (setq gnus-article-mime-handle-alist nil)
7209       (setq gnus-article-mime-handles nil)))
7210   (gnus-kill-save-kill-buffer)
7211   (gnus-async-halt-prefetch)
7212   (let* ((group gnus-newsgroup-name)
7213          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7214          (gnus-group-is-exiting-p t)
7215          (article-buffer gnus-article-buffer)
7216          (mode major-mode)
7217          (group-point nil)
7218          (buf (current-buffer))
7219          ;; `gnus-single-article-buffer' is nil buffer-locally in
7220          ;; ephemeral group of which summary buffer will be killed,
7221          ;; but the global value may be non-nil.
7222          (single-article-buffer gnus-single-article-buffer))
7223     (unless quit-config
7224       ;; Do adaptive scoring, and possibly save score files.
7225       (when gnus-newsgroup-adaptive
7226         (gnus-score-adaptive))
7227       (when gnus-use-scoring
7228         (gnus-score-save)))
7229     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7230     (when gnus-use-cache
7231       (gnus-cache-possibly-remove-articles)
7232       (gnus-cache-save-buffers))
7233     (gnus-async-prefetch-remove-group group)
7234     (when gnus-suppress-duplicates
7235       (gnus-dup-enter-articles))
7236     (when gnus-use-trees
7237       (gnus-tree-close group))
7238     (when gnus-use-cache
7239       (gnus-cache-write-active))
7240     ;; Remove entries for this group.
7241     (nnmail-purge-split-history (gnus-group-real-name group))
7242     ;; Make all changes in this group permanent.
7243     (unless quit-config
7244       (gnus-run-hooks 'gnus-exit-group-hook)
7245       (gnus-summary-update-info))
7246     (gnus-close-group group)
7247     ;; Make sure where we were, and go to next newsgroup.
7248     (set-buffer gnus-group-buffer)
7249     (unless quit-config
7250       (gnus-group-jump-to-group group))
7251     (gnus-run-hooks 'gnus-summary-exit-hook)
7252     (unless (or quit-config
7253                 (not gnus-summary-next-group-on-exit)
7254                 ;; If this group has disappeared from the summary
7255                 ;; buffer, don't skip forwards.
7256                 (not (string= group (gnus-group-group-name))))
7257       (gnus-group-next-unread-group 1))
7258     (setq group-point (point))
7259     (if temporary
7260         nil                             ;Nothing to do.
7261       (set-buffer buf)
7262       (if (not gnus-kill-summary-on-exit)
7263           (progn
7264             (gnus-deaden-summary)
7265             (setq mode nil))
7266         (when (get-buffer gnus-article-buffer)
7267           (bury-buffer gnus-article-buffer))
7268         ;; Return to group mode buffer.
7269         (when (eq mode 'gnus-summary-mode)
7270           (gnus-kill-buffer buf)))
7271
7272       (setq gnus-current-select-method gnus-select-method)
7273       (set-buffer gnus-group-buffer)
7274       (if quit-config
7275           (gnus-handle-ephemeral-exit quit-config)
7276         (goto-char group-point)
7277         ;; If gnus-group-buffer is already displayed, make sure we also move
7278         ;; the cursor in the window that displays it.
7279         (let ((win (get-buffer-window (current-buffer) 0)))
7280           (if win (set-window-point win (point))))
7281         (unless leave-hidden
7282           (gnus-configure-windows 'group 'force)))
7283
7284       ;; If we have several article buffers, we kill them at exit.
7285       (unless single-article-buffer
7286         (when (gnus-buffer-live-p article-buffer)
7287           (with-current-buffer article-buffer
7288             ;; Don't kill sticky article buffers
7289             (unless (eq major-mode 'gnus-sticky-article-mode)
7290               (gnus-kill-buffer article-buffer)
7291               (setq gnus-article-current nil))))
7292         (gnus-kill-buffer gnus-original-article-buffer))
7293
7294       ;; Clear the current group name.
7295       (unless quit-config
7296         (setq gnus-newsgroup-name nil)))))
7297
7298 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7299 (defun gnus-summary-exit-no-update (&optional no-questions)
7300   "Quit reading current newsgroup without updating read article info."
7301   (interactive)
7302   (let* ((group gnus-newsgroup-name)
7303          (gnus-group-is-exiting-p t)
7304          (gnus-group-is-exiting-without-update-p t)
7305          (quit-config (gnus-group-quit-config group)))
7306     (when (or no-questions
7307               gnus-expert-user
7308               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7309       (gnus-async-halt-prefetch)
7310       (run-hooks 'gnus-summary-prepare-exit-hook)
7311       (when (gnus-buffer-live-p gnus-article-buffer)
7312         (with-current-buffer gnus-article-buffer
7313           (gnus-article-stop-animations)
7314           (mm-destroy-parts gnus-article-mime-handles)
7315           ;; Set it to nil for safety reason.
7316           (setq gnus-article-mime-handle-alist nil)
7317           (setq gnus-article-mime-handles nil)))
7318       ;; If we have several article buffers, we kill them at exit.
7319       (unless gnus-single-article-buffer
7320         (gnus-kill-buffer gnus-article-buffer)
7321         (gnus-kill-buffer gnus-original-article-buffer)
7322         (setq gnus-article-current nil))
7323       ;; Return to the group buffer.
7324       (gnus-configure-windows 'group 'force)
7325       (if (not gnus-kill-summary-on-exit)
7326           (gnus-deaden-summary)
7327         (gnus-close-group group)
7328         (gnus-kill-buffer gnus-summary-buffer))
7329       (unless gnus-single-article-buffer
7330         (setq gnus-article-current nil))
7331       (when gnus-use-trees
7332         (gnus-tree-close group))
7333       (gnus-async-prefetch-remove-group group)
7334       (when (get-buffer gnus-article-buffer)
7335         (bury-buffer gnus-article-buffer))
7336       ;; Clear the current group name.
7337       (setq gnus-newsgroup-name nil)
7338       (unless (gnus-ephemeral-group-p group)
7339         (gnus-group-update-group group nil t))
7340       (when (equal (gnus-group-group-name) group)
7341         (gnus-group-next-unread-group 1))
7342       (when quit-config
7343         (gnus-handle-ephemeral-exit quit-config)))))
7344
7345 (defun gnus-handle-ephemeral-exit (quit-config)
7346   "Handle movement when leaving an ephemeral group.
7347 The state which existed when entering the ephemeral is reset."
7348   (if (not (buffer-name (car quit-config)))
7349       (gnus-configure-windows 'group 'force)
7350     (set-buffer (car quit-config))
7351     (unless (eq (cdr quit-config) 'group)
7352       (setq gnus-current-select-method
7353             (gnus-find-method-for-group gnus-newsgroup-name)))
7354     (cond ((eq major-mode 'gnus-summary-mode)
7355            (gnus-set-global-variables))
7356           ((eq major-mode 'gnus-article-mode)
7357            (save-current-buffer
7358              ;; The `gnus-summary-buffer' variable may point
7359              ;; to the old summary buffer when using a single
7360              ;; article buffer.
7361              (unless (gnus-buffer-live-p gnus-summary-buffer)
7362                (set-buffer gnus-group-buffer))
7363              (set-buffer gnus-summary-buffer)
7364              (gnus-set-global-variables))))
7365     (if (or (eq (cdr quit-config) 'article)
7366             (eq (cdr quit-config) 'pick))
7367         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7368             (gnus-configure-windows 'pick 'force)
7369           (gnus-configure-windows (cdr quit-config) 'force))
7370       (gnus-configure-windows (cdr quit-config) 'force))
7371     (when (eq major-mode 'gnus-summary-mode)
7372       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7373                                                      next-unread-noselect))
7374           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7375                                   'next-noselect)
7376                               (gnus-summary-next-subject 1 nil t))
7377                              ((eq gnus-auto-select-on-ephemeral-exit
7378                                   'next-unread-noselect)
7379                               (gnus-summary-next-subject 1 t t))))
7380             ;; Hide the article buffer which displays the article different
7381             ;; from the one that the cursor points to in the summary buffer.
7382             (gnus-configure-windows 'summary 'force))
7383         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7384                (gnus-summary-next-subject 1))
7385               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7386                (gnus-summary-next-subject 1 t))))
7387       (gnus-summary-recenter)
7388       (gnus-summary-position-point))))
7389
7390 ;;; Dead summaries.
7391
7392 (defvar gnus-dead-summary-mode-map
7393   (let ((map (make-keymap)))
7394     (suppress-keymap map)
7395     (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7396     (dolist (key '("\C-d" "\r" "\177" [delete]))
7397       (define-key map key 'gnus-summary-wake-up-the-dead))
7398     (dolist (key '("q" "Q"))
7399       (define-key map key 'bury-buffer))
7400     map))
7401
7402 (define-minor-mode gnus-dead-summary-mode
7403   "Minor mode for Gnus summary buffers."
7404   :lighter " Dead" :keymap gnus-dead-summary-mode-map
7405   (unless (derived-mode-p 'gnus-summary-mode)
7406     (setq gnus-dead-summary-mode nil)))
7407
7408 (defun gnus-deaden-summary ()
7409   "Make the current summary buffer into a dead summary buffer."
7410   ;; Kill any previous dead summary buffer.
7411   (when (and gnus-dead-summary
7412              (buffer-name gnus-dead-summary))
7413     (with-current-buffer gnus-dead-summary
7414       (when gnus-dead-summary-mode
7415         (kill-buffer (current-buffer)))))
7416   ;; Make this the current dead summary.
7417   (setq gnus-dead-summary (current-buffer))
7418   (gnus-dead-summary-mode 1)
7419   (let ((name (buffer-name)))
7420     (when (string-match "Summary" name)
7421       (rename-buffer
7422        (concat (substring name 0 (match-beginning 0)) "Dead "
7423                (substring name (match-beginning 0)))
7424        t)
7425       (bury-buffer))))
7426
7427 (defun gnus-kill-or-deaden-summary (buffer)
7428   "Kill or deaden the summary BUFFER."
7429   (save-excursion
7430     (when (and (buffer-name buffer)
7431                (not gnus-single-article-buffer))
7432       (with-current-buffer buffer
7433         (gnus-kill-buffer gnus-article-buffer)
7434         (gnus-kill-buffer gnus-original-article-buffer)))
7435     (cond
7436      ;; Kill the buffer.
7437      (gnus-kill-summary-on-exit
7438       (when (and gnus-use-trees
7439                  (gnus-buffer-exists-p buffer))
7440         (with-current-buffer buffer
7441           (gnus-tree-close gnus-newsgroup-name)))
7442       (gnus-kill-buffer buffer))
7443      ;; Deaden the buffer.
7444      ((gnus-buffer-exists-p buffer)
7445       (with-current-buffer buffer
7446         (gnus-deaden-summary))))))
7447
7448 (defun gnus-summary-wake-up-the-dead (&rest args)
7449   "Wake up the dead summary buffer."
7450   (interactive)
7451   (gnus-dead-summary-mode -1)
7452   (let ((name (buffer-name)))
7453     (when (string-match "Dead " name)
7454       (rename-buffer
7455        (concat (substring name 0 (match-beginning 0))
7456                (substring name (match-end 0)))
7457        t)))
7458   (gnus-message 3 "This dead summary is now alive again"))
7459
7460 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7461 (defun gnus-summary-describe-group (&optional force)
7462   "Describe the current newsgroup."
7463   (interactive "P")
7464   (gnus-group-describe-group force gnus-newsgroup-name))
7465
7466 (defun gnus-summary-describe-briefly ()
7467   "Describe summary mode commands briefly."
7468   (interactive)
7469   (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")))
7470
7471 ;; Walking around group mode buffer from summary mode.
7472
7473 (defun gnus-summary-next-group (&optional no-article target-group backward)
7474   "Exit current newsgroup and then select next unread newsgroup.
7475 If prefix argument NO-ARTICLE is non-nil, no article is selected
7476 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7477 previous group instead."
7478   (interactive "P")
7479   ;; Stop pre-fetching.
7480   (gnus-async-halt-prefetch)
7481   (let ((current-group gnus-newsgroup-name)
7482         (current-buffer (current-buffer))
7483         entered)
7484     ;; First we semi-exit this group to update Xrefs and all variables.
7485     ;; We can't do a real exit, because the window conf must remain
7486     ;; the same in case the user is prompted for info, and we don't
7487     ;; want the window conf to change before that...
7488     (gnus-summary-exit t)
7489     (while (not entered)
7490       ;; Then we find what group we are supposed to enter.
7491       (set-buffer gnus-group-buffer)
7492       (gnus-group-jump-to-group current-group)
7493       (setq target-group
7494             (or target-group
7495                 (if (eq gnus-keep-same-level 'best)
7496                     (gnus-summary-best-group gnus-newsgroup-name)
7497                   (gnus-summary-search-group backward gnus-keep-same-level))))
7498       (if (not target-group)
7499           ;; There are no further groups, so we return to the group
7500           ;; buffer.
7501           (progn
7502             (gnus-message 5 "Returning to the group buffer")
7503             (setq entered t)
7504             (when (gnus-buffer-live-p current-buffer)
7505               (set-buffer current-buffer)
7506               (gnus-summary-exit))
7507             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7508         ;; We try to enter the target group.
7509         (gnus-group-jump-to-group target-group)
7510         (let ((unreads (gnus-group-group-unread)))
7511           (if (and (or (eq t unreads)
7512                        (and unreads (not (zerop unreads))))
7513                    (gnus-summary-read-group
7514                     target-group nil no-article
7515                     (and (buffer-name current-buffer) current-buffer)
7516                     nil backward))
7517               (setq entered t)
7518             (setq current-group target-group
7519                   target-group nil)))))))
7520
7521 (defun gnus-summary-prev-group (&optional no-article)
7522   "Exit current newsgroup and then select previous unread newsgroup.
7523 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7524   (interactive "P")
7525   (gnus-summary-next-group no-article nil t))
7526
7527 ;; Walking around summary lines.
7528
7529 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7530   "Go to the first subject satisfying any non-nil constraint.
7531 If UNREAD is non-nil, the article should be unread.
7532 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7533 If UNSEEN is non-nil, the article should be unseen as well as unread.
7534 Returns the article selected or nil if there are no matching articles."
7535   (interactive "P")
7536   (cond
7537    ;; Empty summary.
7538    ((null gnus-newsgroup-data)
7539     (gnus-message 3 "No articles in the group")
7540     nil)
7541    ;; Pick the first article.
7542    ((not (or unread undownloaded unseen))
7543     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7544     (gnus-data-number (car gnus-newsgroup-data)))
7545    ;; Find the first unread article.
7546    (t
7547     (let ((data gnus-newsgroup-data))
7548       (while (and data
7549                   (let ((num (gnus-data-number (car data))))
7550                     (or (memq num gnus-newsgroup-unfetched)
7551                         (not (or (and unread
7552                                       (memq num gnus-newsgroup-unreads))
7553                                  (and undownloaded
7554                                       (memq num gnus-newsgroup-undownloaded))
7555                                  (and unseen
7556                                       (memq num gnus-newsgroup-unseen)
7557                                       (memq num gnus-newsgroup-unreads)))))))
7558         (setq data (cdr data)))
7559       (prog1
7560           (if data
7561               (progn
7562                 (goto-char (gnus-data-pos (car data)))
7563                 (gnus-data-number (car data)))
7564             (gnus-message 3 "No more%s articles"
7565                           (let* ((r (when unread " unread"))
7566                                  (d (when undownloaded " undownloaded"))
7567                                  (s (when unseen " unseen"))
7568                                  (l (delq nil (list r d s))))
7569                             (cond ((= 3 (length l))
7570                                    (concat r "," d ", or" s))
7571                                   ((= 2 (length l))
7572                                    (concat (car l) ", or" (cadr l)))
7573                                   ((= 1 (length l))
7574                                    (car l))
7575                                   (t
7576                                    ""))))
7577             nil
7578             )
7579         (gnus-summary-position-point))))))
7580
7581 (defun gnus-summary-next-subject (n &optional unread dont-display)
7582   "Go to next N'th summary line.
7583 If N is negative, go to the previous N'th subject line.
7584 If UNREAD is non-nil, only unread articles are selected.
7585 The difference between N and the actual number of steps taken is
7586 returned."
7587   (interactive "p")
7588   (let ((backward (< n 0))
7589         (n (abs n)))
7590     (while (and (> n 0)
7591                 (if backward
7592                     (gnus-summary-find-prev unread)
7593                   (gnus-summary-find-next unread)))
7594       (unless (zerop (setq n (1- n)))
7595         (gnus-summary-show-thread)))
7596     (when (/= 0 n)
7597       (gnus-message 7 "No more%s articles"
7598                     (if unread " unread" "")))
7599     (unless dont-display
7600       (gnus-summary-recenter)
7601       (gnus-summary-position-point))
7602     n))
7603
7604 (defun gnus-summary-next-unread-subject (n)
7605   "Go to next N'th unread summary line."
7606   (interactive "p")
7607   (gnus-summary-next-subject n t))
7608
7609 (defun gnus-summary-prev-subject (n &optional unread)
7610   "Go to previous N'th summary line.
7611 If optional argument UNREAD is non-nil, only unread article is selected."
7612   (interactive "p")
7613   (gnus-summary-next-subject (- n) unread))
7614
7615 (defun gnus-summary-prev-unread-subject (n)
7616   "Go to previous N'th unread summary line."
7617   (interactive "p")
7618   (gnus-summary-next-subject (- n) t))
7619
7620 (defun gnus-summary-goto-subjects (articles)
7621   "Insert the subject header for ARTICLES in the current buffer."
7622   (save-excursion
7623     (dolist (article articles)
7624       (gnus-summary-goto-subject article t)))
7625   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7626   (gnus-summary-position-point))
7627
7628 (defun gnus-summary-goto-subject (article &optional force silent)
7629   "Go to the subject line of ARTICLE.
7630 If FORCE, also allow jumping to articles not currently shown."
7631   (interactive "nArticle number: ")
7632   (unless (numberp article)
7633     (error "Article %s is not a number" article))
7634   (let ((b (point))
7635         (data (gnus-data-find article)))
7636     ;; We read in the article if we have to.
7637     (and (not data)
7638          force
7639          (gnus-summary-insert-subject
7640           article
7641           (if (or (numberp force) (vectorp force)) force)
7642           t)
7643          (setq data (gnus-data-find article)))
7644     (goto-char b)
7645     (if (not data)
7646         (progn
7647           (unless silent
7648             (gnus-message 3 "Can't find article %d" article))
7649           nil)
7650       (let ((pt (gnus-data-pos data)))
7651         (goto-char pt)
7652         (gnus-summary-set-article-display-arrow pt))
7653       (gnus-summary-position-point)
7654       article)))
7655
7656 ;; Walking around summary lines with displaying articles.
7657
7658 (defun gnus-summary-expand-window (&optional arg)
7659   "Make the summary buffer take up the entire Emacs frame.
7660 Given a prefix, will force an `article' buffer configuration."
7661   (interactive "P")
7662   (if arg
7663       (gnus-configure-windows 'article 'force)
7664     (gnus-configure-windows 'summary 'force)))
7665
7666 (defun gnus-summary-display-article (article &optional all-header)
7667   "Display ARTICLE in article buffer."
7668   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7669                (with-current-buffer gnus-article-buffer
7670                  (eq major-mode 'gnus-article-mode)))
7671     (gnus-article-setup-buffer))
7672   (gnus-set-global-variables)
7673   (with-current-buffer gnus-article-buffer
7674     (setq gnus-article-charset gnus-newsgroup-charset)
7675     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7676     (mm-enable-multibyte))
7677   (if (null article)
7678       nil
7679     (prog1
7680         (if gnus-summary-display-article-function
7681             (funcall gnus-summary-display-article-function article all-header)
7682           (gnus-article-prepare article all-header))
7683       (gnus-run-hooks 'gnus-select-article-hook)
7684       (when (and gnus-current-article
7685                  (not (zerop gnus-current-article)))
7686         (gnus-summary-goto-subject gnus-current-article))
7687       (gnus-summary-recenter)
7688       (when (and gnus-use-trees gnus-show-threads)
7689         (gnus-possibly-generate-tree article)
7690         (gnus-highlight-selected-tree article))
7691       ;; Successfully display article.
7692       (gnus-article-set-window-start
7693        (cdr (assq article gnus-newsgroup-bookmarks))))))
7694
7695 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7696   "Select the current article.
7697 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7698 non-nil, the article will be re-fetched even if it already present in
7699 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7700 be displayed."
7701   ;; Make sure we are in the summary buffer to work around bbdb bug.
7702   (unless (eq major-mode 'gnus-summary-mode)
7703     (set-buffer gnus-summary-buffer))
7704   (let ((article (or article (gnus-summary-article-number)))
7705         (all-headers (not (not all-headers))) ;Must be t or nil.
7706         gnus-summary-display-article-function)
7707     (and (not pseudo)
7708          (gnus-summary-article-pseudo-p article)
7709          (error "This is a pseudo-article"))
7710     (with-current-buffer gnus-summary-buffer
7711       (if (or (and gnus-single-article-buffer
7712                    (or (null gnus-current-article)
7713                        (null gnus-article-current)
7714                        (null (get-buffer gnus-article-buffer))
7715                        (not (eq article (cdr gnus-article-current)))
7716                        (not (equal (car gnus-article-current)
7717                                    gnus-newsgroup-name))
7718                        (not (get-buffer gnus-original-article-buffer))))
7719               (and (not gnus-single-article-buffer)
7720                    (or (null gnus-current-article)
7721                        (not (get-buffer gnus-original-article-buffer))
7722                        (not (eq gnus-current-article article))))
7723               force)
7724           ;; The requested article is different from the current article.
7725           (progn
7726             (gnus-summary-display-article article all-headers)
7727             (when (gnus-buffer-live-p gnus-article-buffer)
7728               (with-current-buffer gnus-article-buffer
7729                 (if (not gnus-article-decoded-p) ;; a local variable
7730                     (mm-disable-multibyte))))
7731             (gnus-article-set-window-start
7732              (cdr (assq article gnus-newsgroup-bookmarks)))
7733             article)
7734         'old))))
7735
7736 (defun gnus-summary-force-verify-and-decrypt ()
7737   "Display buttons for signed/encrypted parts and verify/decrypt them."
7738   (interactive)
7739   (let ((mm-verify-option 'known)
7740         (mm-decrypt-option 'known)
7741         (gnus-article-emulate-mime t)
7742         (gnus-buttonized-mime-types (append (list "multipart/signed"
7743                                                   "multipart/encrypted")
7744                                             gnus-buttonized-mime-types)))
7745     (gnus-summary-select-article nil 'force)))
7746
7747 (defun gnus-summary-set-current-mark (&optional current-mark)
7748   "Obsolete function."
7749   nil)
7750
7751 (defun gnus-summary-next-article (&optional unread subject backward push)
7752   "Select the next article.
7753 If UNREAD, only unread articles are selected.
7754 If SUBJECT, only articles with SUBJECT are selected.
7755 If BACKWARD, the previous article is selected instead of the next."
7756   (interactive "P")
7757   ;; Make sure we are in the summary buffer.
7758   (unless (eq major-mode 'gnus-summary-mode)
7759     (set-buffer gnus-summary-buffer))
7760   (cond
7761    ;; Is there such an article?
7762    ((and (gnus-summary-search-forward unread subject backward)
7763          (or (gnus-summary-display-article (gnus-summary-article-number))
7764              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7765     (gnus-summary-position-point))
7766    ;; If not, we try the first unread, if that is wanted.
7767    ((and subject
7768          gnus-auto-select-same
7769          (gnus-summary-first-unread-article))
7770     (gnus-summary-position-point)
7771     (gnus-message 6 "Wrapped"))
7772    ;; Try to get next/previous article not displayed in this group.
7773    ((and gnus-auto-extend-newsgroup
7774          (not unread) (not subject))
7775     (gnus-summary-goto-article
7776      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7777      nil (count-lines (point-min) (point))))
7778    ;; Go to next/previous group.
7779    (t
7780     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7781       (gnus-summary-jump-to-group gnus-newsgroup-name))
7782     (let ((cmd (if (featurep 'xemacs)
7783                    last-command-char
7784                  last-command-event))
7785           (point
7786            (with-current-buffer gnus-group-buffer
7787              (point)))
7788           (current-summary (current-buffer))
7789           (group
7790            (if (eq gnus-keep-same-level 'best)
7791                (gnus-summary-best-group gnus-newsgroup-name)
7792              (gnus-summary-search-group backward gnus-keep-same-level))))
7793       ;; Select next unread newsgroup automagically.
7794       (cond
7795        ((or (not gnus-auto-select-next)
7796             (not cmd))
7797         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7798        ((or (eq gnus-auto-select-next 'quietly)
7799             (and (eq gnus-auto-select-next 'slightly-quietly)
7800                  push)
7801             (and (eq gnus-auto-select-next 'almost-quietly)
7802                  (gnus-summary-last-article-p)))
7803         ;; Select quietly.
7804         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7805             (gnus-summary-exit)
7806           (gnus-message 7 "No more%s articles (%s)..."
7807                         (if unread " unread" "")
7808                         (if group (concat "selecting " group)
7809                           "exiting"))
7810           (gnus-summary-next-group nil group backward)))
7811        (t
7812         (when (gnus-key-press-event-p last-input-event)
7813           ;; Somehow or other, we may now have selected a different
7814           ;; window.  Make point go back to the summary buffer.
7815           (when (eq current-summary (current-buffer))
7816             ;; FIXME: This burps when get-buffer-window returns nil.
7817             (select-window (get-buffer-window current-summary 0)))
7818           (gnus-summary-walk-group-buffer
7819            gnus-newsgroup-name cmd unread backward point))))))))
7820
7821 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7822   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7823                       (?\C-p (gnus-group-prev-unread-group 1))))
7824         (cursor-in-echo-area t)
7825         keve key group ended prompt)
7826     (with-current-buffer gnus-group-buffer
7827       (goto-char start)
7828       (setq group
7829             (if (eq gnus-keep-same-level 'best)
7830                 (gnus-summary-best-group gnus-newsgroup-name)
7831               (gnus-summary-search-group backward gnus-keep-same-level))))
7832     (while (not ended)
7833       (setq prompt
7834             (format
7835              "No more%s articles%s " (if unread " unread" "")
7836              (if (and group
7837                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7838                  (format " (Type %s for %s [%s])"
7839                          (single-key-description cmd)
7840                          (gnus-group-decoded-name group)
7841                          (gnus-group-unread group))
7842                (format " (Type %s to exit %s)"
7843                        (single-key-description cmd)
7844                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7845       ;; Confirm auto selection.
7846       (setq key (car (setq keve (gnus-read-event-char prompt)))
7847             ended t)
7848       (cond
7849        ((assq key keystrokes)
7850         (let ((obuf (current-buffer)))
7851           (switch-to-buffer gnus-group-buffer)
7852           (when group
7853             (gnus-group-jump-to-group group))
7854           (eval (cadr (assq key keystrokes)))
7855           (setq group (gnus-group-group-name))
7856           (switch-to-buffer obuf))
7857         (setq ended nil))
7858        ((equal key cmd)
7859         (if (or (not group)
7860                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7861             (gnus-summary-exit)
7862           (gnus-summary-next-group nil group backward)))
7863        (t
7864         (push (cdr keve) unread-command-events))))))
7865
7866 (defun gnus-summary-next-unread-article ()
7867   "Select unread article after current one."
7868   (interactive)
7869   (gnus-summary-next-article
7870    (or (not (eq gnus-summary-goto-unread 'never))
7871        (gnus-summary-last-article-p (gnus-summary-article-number)))
7872    (and gnus-auto-select-same
7873         (gnus-summary-article-subject))))
7874
7875 (defun gnus-summary-prev-article (&optional unread subject)
7876   "Select the article before the current one.
7877 If UNREAD is non-nil, only unread articles are selected."
7878   (interactive "P")
7879   (gnus-summary-next-article unread subject t))
7880
7881 (defun gnus-summary-prev-unread-article ()
7882   "Select unread article before current one."
7883   (interactive)
7884   (gnus-summary-prev-article
7885    (or (not (eq gnus-summary-goto-unread 'never))
7886        (gnus-summary-first-article-p (gnus-summary-article-number)))
7887    (and gnus-auto-select-same
7888         (gnus-summary-article-subject))))
7889
7890 (defun gnus-summary-next-page (&optional lines circular stop)
7891   "Show next page of the selected article.
7892 If at the end of the current article, select the next article.
7893 LINES says how many lines should be scrolled up.
7894
7895 If CIRCULAR is non-nil, go to the start of the article instead of
7896 selecting the next article when reaching the end of the current
7897 article.
7898
7899 If STOP is non-nil, just stop when reaching the end of the message.
7900
7901 Also see the variable `gnus-article-skip-boring'."
7902   (interactive "P")
7903   (setq gnus-summary-buffer (current-buffer))
7904   (gnus-set-global-variables)
7905   (let ((article (gnus-summary-article-number))
7906         (article-window (get-buffer-window gnus-article-buffer t))
7907         endp)
7908     ;; If the buffer is empty, we have no article.
7909     (unless article
7910       (error "No article to select"))
7911     (gnus-configure-windows 'article)
7912     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7913         (if (and (eq gnus-summary-goto-unread 'never)
7914                  (not (gnus-summary-last-article-p article)))
7915             (gnus-summary-next-article)
7916           (gnus-summary-next-unread-article))
7917       (if (or (null gnus-current-article)
7918               (null gnus-article-current)
7919               (/= article (cdr gnus-article-current))
7920               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7921           ;; Selected subject is different from current article's.
7922           (gnus-summary-display-article article)
7923         (when article-window
7924           (gnus-eval-in-buffer-window gnus-article-buffer
7925             (setq endp (or (gnus-article-next-page lines)
7926                            (gnus-article-only-boring-p))))
7927           (when endp
7928             (cond ((or stop gnus-summary-stop-at-end-of-message)
7929                    (gnus-message 3 "End of message"))
7930                   (circular
7931                    (gnus-summary-beginning-of-article))
7932                   (lines
7933                    (gnus-message 3 "End of message"))
7934                   ((null lines)
7935                    (if (and (eq gnus-summary-goto-unread 'never)
7936                             (not (gnus-summary-last-article-p article)))
7937                        (gnus-summary-next-article)
7938                      (gnus-summary-next-unread-article))))))))
7939     (gnus-summary-recenter)
7940     (gnus-summary-position-point)))
7941
7942 (defun gnus-summary-prev-page (&optional lines move)
7943   "Show previous page of selected article.
7944 Argument LINES specifies lines to be scrolled down.
7945 If MOVE, move to the previous unread article if point is at
7946 the beginning of the buffer."
7947   (interactive "P")
7948   (let ((article (gnus-summary-article-number))
7949         (article-window (get-buffer-window gnus-article-buffer t))
7950         endp)
7951     (gnus-configure-windows 'article)
7952     (if (or (null gnus-current-article)
7953             (null gnus-article-current)
7954             (/= article (cdr gnus-article-current))
7955             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7956         ;; Selected subject is different from current article's.
7957         (gnus-summary-display-article article)
7958       (gnus-summary-recenter)
7959       (when article-window
7960         (gnus-eval-in-buffer-window gnus-article-buffer
7961           (setq endp (gnus-article-prev-page lines)))
7962         (when (and move endp)
7963           (cond (lines
7964                  (gnus-message 3 "Beginning of message"))
7965                 ((null lines)
7966                  (if (and (eq gnus-summary-goto-unread 'never)
7967                           (not (gnus-summary-first-article-p article)))
7968                      (gnus-summary-prev-article)
7969                    (gnus-summary-prev-unread-article))))))))
7970   (gnus-summary-position-point))
7971
7972 (defun gnus-summary-prev-page-or-article (&optional lines)
7973   "Show previous page of selected article.
7974 Argument LINES specifies lines to be scrolled down.
7975 If at the beginning of the article, go to the next article."
7976   (interactive "P")
7977   (gnus-summary-prev-page lines t))
7978
7979 (defun gnus-summary-scroll-up (lines)
7980   "Scroll up (or down) one line current article.
7981 Argument LINES specifies lines to be scrolled up (or down if negative).
7982 If no article is selected, then the current article will be selected first."
7983   (interactive "p")
7984   (gnus-configure-windows 'article)
7985   (gnus-summary-show-thread)
7986   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7987     (gnus-eval-in-buffer-window gnus-article-buffer
7988       (cond ((> lines 0)
7989              (when (gnus-article-next-page lines)
7990                (gnus-message 3 "End of message")))
7991             ((< lines 0)
7992              (gnus-article-prev-page (- lines))))))
7993   (gnus-summary-recenter)
7994   (gnus-summary-position-point))
7995
7996 (defun gnus-summary-scroll-down (lines)
7997   "Scroll down (or up) one line current article.
7998 Argument LINES specifies lines to be scrolled down (or up if negative).
7999 If no article is selected, then the current article will be selected first."
8000   (interactive "p")
8001   (gnus-summary-scroll-up (- lines)))
8002
8003 (defun gnus-summary-next-same-subject ()
8004   "Select next article which has the same subject as current one."
8005   (interactive)
8006   (gnus-summary-next-article nil (gnus-summary-article-subject)))
8007
8008 (defun gnus-summary-prev-same-subject ()
8009   "Select previous article which has the same subject as current one."
8010   (interactive)
8011   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
8012
8013 (defun gnus-summary-next-unread-same-subject ()
8014   "Select next unread article which has the same subject as current one."
8015   (interactive)
8016   (gnus-summary-next-article t (gnus-summary-article-subject)))
8017
8018 (defun gnus-summary-prev-unread-same-subject ()
8019   "Select previous unread article which has the same subject as current one."
8020   (interactive)
8021   (gnus-summary-prev-article t (gnus-summary-article-subject)))
8022
8023 (defun gnus-summary-first-unread-article ()
8024   "Select the first unread article.
8025 Return nil if there are no unread articles."
8026   (interactive)
8027   (prog1
8028       (when (gnus-summary-first-subject t)
8029         (gnus-summary-show-thread)
8030         (gnus-summary-first-subject t)
8031         (gnus-summary-display-article (gnus-summary-article-number)))
8032     (gnus-summary-position-point)))
8033
8034 (defun gnus-summary-first-unread-subject ()
8035   "Place the point on the subject line of the first unread article.
8036 Return nil if there are no unread articles."
8037   (interactive)
8038   (prog1
8039       (when (gnus-summary-first-subject t)
8040         (gnus-summary-show-thread)
8041         (gnus-summary-first-subject t))
8042     (gnus-summary-position-point)))
8043
8044 (defun gnus-summary-first-unseen-subject ()
8045   "Place the point on the subject line of the first unseen article.
8046 Return nil if there are no unseen articles."
8047   (interactive)
8048   (prog1
8049       (when (gnus-summary-first-subject nil nil t)
8050         (gnus-summary-show-thread)
8051         (gnus-summary-first-subject nil nil t))
8052     (gnus-summary-position-point)))
8053
8054 (defun gnus-summary-first-unseen-or-unread-subject ()
8055   "Place the point on the subject line of the first unseen and unread article.
8056 If all article have been seen, on the subject line of the first unread
8057 article."
8058   (interactive)
8059   (prog1
8060       (unless (when (gnus-summary-first-subject nil nil t)
8061                 (gnus-summary-show-thread)
8062                 (gnus-summary-first-subject nil nil t))
8063         (when (gnus-summary-first-subject t)
8064           (gnus-summary-show-thread)
8065           (gnus-summary-first-subject t)))
8066     (gnus-summary-position-point)))
8067
8068 (defun gnus-summary-first-article ()
8069   "Select the first article.
8070 Return nil if there are no articles."
8071   (interactive)
8072   (prog1
8073       (when (gnus-summary-first-subject)
8074         (gnus-summary-show-thread)
8075         (gnus-summary-first-subject)
8076         (gnus-summary-display-article (gnus-summary-article-number)))
8077     (gnus-summary-position-point)))
8078
8079 (defun gnus-summary-best-unread-article (&optional arg)
8080   "Select the unread article with the highest score.
8081 If given a prefix argument, select the next unread article that has a
8082 score higher than the default score."
8083   (interactive "P")
8084   (let ((article (if arg
8085                      (gnus-summary-better-unread-subject)
8086                    (gnus-summary-best-unread-subject))))
8087     (if article
8088         (gnus-summary-goto-article article)
8089       (error "No unread articles"))))
8090
8091 (defun gnus-summary-best-unread-subject ()
8092   "Select the unread subject with the highest score."
8093   (interactive)
8094   (let ((best -1000000)
8095         (data gnus-newsgroup-data)
8096         article score)
8097     (while data
8098       (and (gnus-data-unread-p (car data))
8099            (> (setq score
8100                     (gnus-summary-article-score (gnus-data-number (car data))))
8101               best)
8102            (setq best score
8103                  article (gnus-data-number (car data))))
8104       (setq data (cdr data)))
8105     (when article
8106       (gnus-summary-goto-subject article))
8107     (gnus-summary-position-point)
8108     article))
8109
8110 (defun gnus-summary-better-unread-subject ()
8111   "Select the first unread subject that has a score over the default score."
8112   (interactive)
8113   (let ((data gnus-newsgroup-data)
8114         article score)
8115     (while (and (setq article (gnus-data-number (car data)))
8116                 (or (gnus-data-read-p (car data))
8117                     (not (> (gnus-summary-article-score article)
8118                             gnus-summary-default-score))))
8119       (setq data (cdr data)))
8120     (when article
8121       (gnus-summary-goto-subject article))
8122     (gnus-summary-position-point)
8123     article))
8124
8125 (defun gnus-summary-last-subject ()
8126   "Go to the last displayed subject line in the group."
8127   (let ((article (gnus-data-number (car (gnus-data-list t)))))
8128     (when article
8129       (gnus-summary-goto-subject article))))
8130
8131 (defun gnus-summary-goto-article (article &optional all-headers force)
8132   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
8133 If ALL-HEADERS is non-nil, no header lines are hidden.
8134 If FORCE, go to the article even if it isn't displayed.  If FORCE
8135 is a number, it is the line the article is to be displayed on."
8136   (interactive
8137    (list
8138     (gnus-completing-read
8139      "Article number or Message-ID"
8140      (mapcar 'int-to-string gnus-newsgroup-limit))
8141     current-prefix-arg
8142     t))
8143   (prog1
8144       (if (and (stringp article)
8145                (string-match "@\\|%40" article))
8146           (gnus-summary-refer-article article)
8147         (when (stringp article)
8148           (setq article (string-to-number article)))
8149         (if (gnus-summary-goto-subject article force)
8150             (gnus-summary-display-article article all-headers)
8151           (gnus-message 4 "Couldn't go to article %s" article) nil))
8152     (gnus-summary-position-point)))
8153
8154 (defun gnus-summary-goto-last-article ()
8155   "Go to the previously read article."
8156   (interactive)
8157   (prog1
8158       (when gnus-last-article
8159         (gnus-summary-goto-article gnus-last-article nil t))
8160     (gnus-summary-position-point)))
8161
8162 (defun gnus-summary-pop-article (number)
8163   "Pop one article off the history and go to the previous.
8164 NUMBER articles will be popped off."
8165   (interactive "p")
8166   (let (to)
8167     (setq gnus-newsgroup-history
8168           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8169     (if to
8170         (gnus-summary-goto-article (car to) nil t)
8171       (error "Article history empty")))
8172   (gnus-summary-position-point))
8173
8174 ;; Summary commands and functions for limiting the summary buffer.
8175
8176 (defun gnus-summary-limit-to-articles (n)
8177   "Limit the summary buffer to the next N articles.
8178 If not given a prefix, use the process marked articles instead."
8179   (interactive "P")
8180   (prog1
8181       (let ((articles (gnus-summary-work-articles n)))
8182         (setq gnus-newsgroup-processable nil)
8183         (gnus-summary-limit articles))
8184     (gnus-summary-position-point)))
8185
8186 (defun gnus-summary-pop-limit (&optional total)
8187   "Restore the previous limit.
8188 If given a prefix, remove all limits."
8189   (interactive "P")
8190   (when total
8191     (setq gnus-newsgroup-limits
8192           (list (mapcar (lambda (h) (mail-header-number h))
8193                         gnus-newsgroup-headers))))
8194   (unless gnus-newsgroup-limits
8195     (error "No limit to pop"))
8196   (prog1
8197       (gnus-summary-limit nil 'pop)
8198     (gnus-summary-position-point)))
8199
8200 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8201   "Limit the summary buffer to articles that have subjects that match a regexp.
8202 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8203   (interactive
8204    (list (read-string (if current-prefix-arg
8205                           "Exclude subject (regexp): "
8206                         "Limit to subject (regexp): "))
8207          nil current-prefix-arg))
8208   (unless header
8209     (setq header "subject"))
8210   (when (not (equal "" subject))
8211     (prog1
8212         (let ((articles (gnus-summary-find-matching
8213                          (or header "subject") subject 'all nil nil
8214                          not-matching)))
8215           (unless articles
8216             (error "Found no matches for \"%s\"" subject))
8217           (gnus-summary-limit articles))
8218       (gnus-summary-position-point))))
8219
8220 (defun gnus-summary-limit-to-author (from &optional not-matching)
8221   "Limit the summary buffer to articles that have authors that match a regexp.
8222 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8223   (interactive
8224    (list (read-string (if current-prefix-arg
8225                           "Exclude author (regexp): "
8226                         "Limit to author (regexp): "))
8227          current-prefix-arg))
8228   (gnus-summary-limit-to-subject from "from" not-matching))
8229
8230 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8231   "Limit the summary buffer to articles with the given RECIPIENT.
8232
8233 If NOT-MATCHING, exclude RECIPIENT.
8234
8235 To and Cc headers are checked.  You need to include them in
8236 `nnmail-extra-headers'."
8237   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8238   (interactive
8239    (list (read-string (format "%s recipient (regexp): "
8240                               (if current-prefix-arg "Exclude" "Limit to")))
8241          current-prefix-arg))
8242   (when (not (equal "" recipient))
8243     (prog1 (let* ((to
8244                    (if (memq 'To nnmail-extra-headers)
8245                        (gnus-summary-find-matching
8246                         (cons 'extra 'To) recipient 'all nil nil
8247                         not-matching)
8248                      (gnus-message
8249                       1 "`To' isn't present in `nnmail-extra-headers'")
8250                      (sit-for 1)
8251                      nil))
8252                   (cc
8253                    (if (memq 'Cc nnmail-extra-headers)
8254                        (gnus-summary-find-matching
8255                         (cons 'extra 'Cc) recipient 'all nil nil
8256                         not-matching)
8257                      (gnus-message
8258                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8259                      (sit-for 1)
8260                      nil))
8261                   (articles
8262                    (if not-matching
8263                        ;; We need the numbers that are in both lists:
8264                        (mapcar (lambda (a)
8265                                  (and (memq a to) a))
8266                                cc)
8267                      (nconc to cc))))
8268              (unless articles
8269                (error "Found no matches for \"%s\"" recipient))
8270              (gnus-summary-limit articles))
8271       (gnus-summary-position-point))))
8272
8273 (defun gnus-summary-limit-to-address (address &optional not-matching)
8274   "Limit the summary buffer to articles with the given ADDRESS.
8275
8276 If NOT-MATCHING, exclude ADDRESS.
8277
8278 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8279 in `nnmail-extra-headers'."
8280   (interactive
8281    (list (read-string (format "%s address (regexp): "
8282                               (if current-prefix-arg "Exclude" "Limit to")))
8283          current-prefix-arg))
8284   (when (not (equal "" address))
8285     (prog1 (let* ((to
8286                    (if (memq 'To nnmail-extra-headers)
8287                        (gnus-summary-find-matching
8288                         (cons 'extra 'To) address 'all nil nil
8289                         not-matching)
8290                      (gnus-message
8291                       1 "`To' isn't present in `nnmail-extra-headers'")
8292                      (sit-for 1)
8293                      t))
8294                   (cc
8295                    (if (memq 'Cc nnmail-extra-headers)
8296                        (gnus-summary-find-matching
8297                         (cons 'extra 'Cc) address 'all nil nil
8298                         not-matching)
8299                      (gnus-message
8300                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8301                      (sit-for 1)
8302                      t))
8303                   (from
8304                    (gnus-summary-find-matching "from" address
8305                                                'all nil nil not-matching))
8306                   (articles
8307                    (if not-matching
8308                        ;; We need the numbers that are in all lists:
8309                        (if (eq cc t)
8310                            (if (eq to t)
8311                                from
8312                              (mapcar (lambda (a) (car (memq a from))) to))
8313                          (if (eq to t)
8314                              (mapcar (lambda (a) (car (memq a from))) cc)
8315                            (mapcar (lambda (a) (car (memq a from)))
8316                                    (mapcar (lambda (a) (car (memq a to)))
8317                                            cc))))
8318                      (nconc (if (eq to t) nil to)
8319                             (if (eq cc t) nil cc)
8320                             from))))
8321              (unless articles
8322                (error "Found no matches for \"%s\"" address))
8323              (gnus-summary-limit articles))
8324       (gnus-summary-position-point))))
8325
8326 (defun gnus-summary-limit-strange-charsets-predicate (header)
8327   (when (fboundp 'char-charset)
8328     (let ((string (concat (mail-header-subject header)
8329                           (mail-header-from header)))
8330           charset found)
8331       (dotimes (i (1- (length string)))
8332         (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8333         (when (string-match "unicode\\|big\\|japanese" charset)
8334           (setq found t)))
8335       found)))
8336
8337 (defun gnus-summary-limit-to-predicate (predicate)
8338   "Limit to articles where PREDICATE returns non-nil.
8339 PREDICATE will be called with the header structures of the
8340 articles."
8341   (let ((articles nil)
8342         (case-fold-search t))
8343     (dolist (header gnus-newsgroup-headers)
8344       (when (funcall predicate header)
8345         (push (mail-header-number header) articles)))
8346     (gnus-summary-limit (nreverse articles))))
8347
8348 (defun gnus-summary-limit-to-age (age &optional younger-p)
8349   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8350 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8351 articles that are younger than AGE days."
8352   (interactive
8353    (let ((younger current-prefix-arg)
8354          (days-got nil)
8355          days)
8356      (while (not days-got)
8357        (setq days (if younger
8358                       (read-string "Limit to articles younger than (in days, older when negative): ")
8359                     (read-string
8360                      "Limit to articles older than (in days, younger when negative): ")))
8361        (when (> (length days) 0)
8362          (setq days (read days)))
8363        (if (numberp days)
8364            (progn
8365              (setq days-got t)
8366              (when (< days 0)
8367                (setq younger (not younger))
8368                (setq days (* days -1))))
8369          (message "Please enter a number.")
8370          (sleep-for 1)))
8371      (list days younger)))
8372   (prog1
8373       (let ((data gnus-newsgroup-data)
8374             (cutoff (days-to-time age))
8375             articles d date is-younger)
8376         (while (setq d (pop data))
8377           (when (and (vectorp (gnus-data-header d))
8378                      (setq date (mail-header-date (gnus-data-header d))))
8379             (setq is-younger (time-less-p
8380                               (time-since (gnus-date-get-time date))
8381                               cutoff))
8382             (when (if younger-p
8383                       is-younger
8384                     (not is-younger))
8385               (push (gnus-data-number d) articles))))
8386         (gnus-summary-limit (nreverse articles)))
8387     (gnus-summary-position-point)))
8388
8389 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8390   "Limit the summary buffer to articles that match an 'extra' header."
8391   (interactive
8392    (let ((header
8393           (intern
8394            (gnus-completing-read
8395             (if current-prefix-arg
8396                 "Exclude extra header"
8397               "Limit extra header")
8398             (mapcar 'symbol-name gnus-extra-headers)
8399             t nil nil
8400             (symbol-name (car gnus-extra-headers))))))
8401      (list header
8402            (read-string (format "%s header %s (regexp): "
8403                                 (if current-prefix-arg "Exclude" "Limit to")
8404                                 header))
8405            current-prefix-arg)))
8406   (when (not (equal "" regexp))
8407     (prog1
8408         (let ((articles (gnus-summary-find-matching
8409                          (cons 'extra header) regexp 'all nil nil
8410                          not-matching)))
8411           (unless articles
8412             (error "Found no matches for \"%s\"" regexp))
8413           (gnus-summary-limit articles))
8414       (gnus-summary-position-point))))
8415
8416 (defun gnus-summary-limit-to-display-predicate ()
8417   "Limit the summary buffer to the predicated in the `display' group parameter."
8418   (interactive)
8419   (unless gnus-newsgroup-display
8420     (error "There is no `display' group parameter"))
8421   (let (articles)
8422     (dolist (gnus-number gnus-newsgroup-articles)
8423       (when (funcall gnus-newsgroup-display)
8424         (push gnus-number articles)))
8425     (gnus-summary-limit articles))
8426   (gnus-summary-position-point))
8427
8428 (defun gnus-summary-limit-to-unread (&optional all)
8429   "Limit the summary buffer to articles that are not marked as read.
8430 If ALL is non-nil, limit strictly to unread articles."
8431   (interactive "P")
8432   (if all
8433       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8434     (gnus-summary-limit-to-marks
8435      ;; Concat all the marks that say that an article is read and have
8436      ;; those removed.
8437      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8438            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8439            gnus-low-score-mark gnus-expirable-mark
8440            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8441            gnus-duplicate-mark)
8442      'reverse)))
8443
8444 (defun gnus-summary-limit-to-headers (match &optional reverse)
8445   "Limit the summary buffer to articles that have headers that match MATCH.
8446 If REVERSE (the prefix), limit to articles that don't match."
8447   (interactive "sMatch headers (regexp): \nP")
8448   (gnus-summary-limit-to-bodies match reverse t))
8449
8450 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8451   "Limit the summary buffer to articles that have bodies that match MATCH.
8452 If REVERSE (the prefix), limit to articles that don't match."
8453   (interactive "sMatch body (regexp): \nP")
8454   (let ((articles nil)
8455         (gnus-select-article-hook nil)  ;Disable hook.
8456         (gnus-article-prepare-hook nil)
8457         (gnus-use-article-prefetch nil)
8458         (gnus-keep-backlog nil)
8459         (gnus-break-pages nil)
8460         (gnus-summary-display-arrow nil)
8461         (gnus-updated-mode-lines nil)
8462         (gnus-auto-center-summary nil)
8463         (gnus-display-mime-function nil))
8464     (dolist (data gnus-newsgroup-data)
8465       (let (gnus-mark-article-hook)
8466         (gnus-summary-select-article t t nil (gnus-data-number data)))
8467       (with-current-buffer gnus-article-buffer
8468         (article-goto-body)
8469         (let* ((case-fold-search t)
8470                (found (if headersp
8471                           (re-search-backward match nil t)
8472                         (re-search-forward match nil t))))
8473           (when (or (and found
8474                          (not reverse))
8475                     (and (not found)
8476                          reverse))
8477             (push (gnus-data-number data) articles)))))
8478     (if (not articles)
8479         (message "No messages matched")
8480       (gnus-summary-limit articles)))
8481   (gnus-summary-position-point))
8482
8483 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8484   "Limit the summary buffer to articles that aren't part on any thread.
8485 If THREADSP (the prefix), limit to articles that are in threads."
8486   (interactive "P")
8487   (let ((articles nil)
8488         thread-articles
8489         threads)
8490     (dolist (thread gnus-newsgroup-threads)
8491       (if (stringp (car thread))
8492           (dolist (thread (cdr thread))
8493             (push thread threads))
8494         (push thread threads)))
8495     (dolist (thread threads)
8496       (setq thread-articles (gnus-articles-in-thread thread))
8497       (when (or (and threadsp
8498                      (> (length thread-articles) 1))
8499                 (and (not threadsp)
8500                      (= (length thread-articles) 1)))
8501         (setq articles (nconc thread-articles articles))))
8502     (if (not articles)
8503         (message "No messages matched")
8504       (gnus-summary-limit articles))
8505     (gnus-summary-position-point)))
8506
8507 (defun gnus-summary-limit-to-replied (&optional unreplied)
8508   "Limit the summary buffer to replied articles.
8509 If UNREPLIED (the prefix), limit to unreplied articles."
8510   (interactive "P")
8511   (if unreplied
8512       (gnus-summary-limit
8513        (gnus-set-difference gnus-newsgroup-articles
8514         gnus-newsgroup-replied))
8515     (gnus-summary-limit gnus-newsgroup-replied))
8516   (gnus-summary-position-point))
8517
8518 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8519   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8520 If REVERSE, limit the summary buffer to articles that are marked
8521 with MARKS.  MARKS can either be a string of marks or a list of marks.
8522 Returns how many articles were removed."
8523   (interactive "sMarks: ")
8524   (gnus-summary-limit-to-marks marks t))
8525
8526 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8527   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8528 If REVERSE (the prefix), limit the summary buffer to articles that are
8529 not marked with MARKS.  MARKS can either be a string of marks or a
8530 list of marks.
8531 Returns how many articles were removed."
8532   (interactive "sMarks: \nP")
8533   (prog1
8534       (let ((data gnus-newsgroup-data)
8535             (marks (if (listp marks) marks
8536                      (append marks nil))) ; Transform to list.
8537             articles)
8538         (while data
8539           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8540                   (memq (gnus-data-mark (car data)) marks))
8541             (push (gnus-data-number (car data)) articles))
8542           (setq data (cdr data)))
8543         (gnus-summary-limit articles))
8544     (gnus-summary-position-point)))
8545
8546 (defun gnus-summary-limit-to-score (score)
8547   "Limit to articles with score at or above SCORE."
8548   (interactive "NLimit to articles with score of at least: ")
8549   (let ((data gnus-newsgroup-data)
8550         articles)
8551     (while data
8552       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8553                 score)
8554         (push (gnus-data-number (car data)) articles))
8555       (setq data (cdr data)))
8556     (prog1
8557         (gnus-summary-limit articles)
8558       (gnus-summary-position-point))))
8559
8560 (defun gnus-summary-limit-to-unseen ()
8561   "Limit to unseen articles."
8562   (interactive)
8563   (prog1
8564       (gnus-summary-limit gnus-newsgroup-unseen)
8565     (gnus-summary-position-point)))
8566
8567 (defun gnus-summary-limit-include-thread (id)
8568   "Display all the hidden articles that is in the thread with ID in it.
8569 When called interactively, ID is the Message-ID of the current
8570 article."
8571   (interactive (list (mail-header-id (gnus-summary-article-header))))
8572   (let ((articles (gnus-articles-in-thread
8573                    (gnus-id-to-thread (gnus-root-id id))))
8574         ;;we REALLY want the whole thread---this prevents cut-threads
8575         ;;from removing the thread we want to include.
8576         (gnus-fetch-old-headers nil)
8577         (gnus-build-sparse-threads nil))
8578     (prog1
8579         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8580       (gnus-summary-limit-include-matching-articles
8581        "subject"
8582        (regexp-quote (gnus-simplify-subject-re
8583                       (mail-header-subject (gnus-id-to-header id)))))
8584       (gnus-summary-position-point))))
8585
8586 (defun gnus-summary-limit-include-matching-articles (header regexp)
8587   "Display all the hidden articles that have HEADERs that match REGEXP."
8588   (interactive (list (read-string "Match on header: ")
8589                      (read-string "Regexp: ")))
8590   (let ((articles (gnus-find-matching-articles header regexp)))
8591     (prog1
8592         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8593       (gnus-summary-position-point))))
8594
8595 (defun gnus-summary-insert-dormant-articles ()
8596   "Insert all the dormant articles for this group into the current buffer."
8597   (interactive)
8598   (let ((gnus-verbose (max 6 gnus-verbose)))
8599     (if (not gnus-newsgroup-dormant)
8600         (gnus-message 3 "No dormant articles for this group")
8601       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8602
8603 (defun gnus-summary-insert-ticked-articles ()
8604   "Insert ticked articles for this group into the current buffer."
8605   (interactive)
8606   (let ((gnus-verbose (max 6 gnus-verbose)))
8607     (if (not gnus-newsgroup-marked)
8608         (gnus-message 3 "No ticked articles for this group")
8609       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8610
8611 (defun gnus-summary-limit-include-dormant ()
8612   "Display all the hidden articles that are marked as dormant.
8613 Note that this command only works on a subset of the articles currently
8614 fetched for this group."
8615   (interactive)
8616   (unless gnus-newsgroup-dormant
8617     (error "There are no dormant articles in this group"))
8618   (prog1
8619       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8620     (gnus-summary-position-point)))
8621
8622 (defun gnus-summary-include-articles (articles)
8623   "Fetch the headers for ARTICLES and then display the summary lines."
8624   (let ((gnus-inhibit-demon t)
8625         (gnus-agent nil)
8626         (gnus-read-all-available-headers t))
8627     (setq gnus-newsgroup-headers
8628           (gnus-merge
8629            'list gnus-newsgroup-headers
8630            (gnus-fetch-headers articles nil t)
8631            'gnus-article-sort-by-number))
8632     (gnus-summary-limit (append articles gnus-newsgroup-limit))))
8633
8634 (defun gnus-summary-limit-exclude-dormant ()
8635   "Hide all dormant articles."
8636   (interactive)
8637   (prog1
8638       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8639     (gnus-summary-position-point)))
8640
8641 (defun gnus-summary-limit-exclude-childless-dormant ()
8642   "Hide all dormant articles that have no children."
8643   (interactive)
8644   (let ((data (gnus-data-list t))
8645         articles d children)
8646     ;; Find all articles that are either not dormant or have
8647     ;; children.
8648     (while (setq d (pop data))
8649       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8650                 (and (setq children
8651                            (gnus-article-children (gnus-data-number d)))
8652                      (let (found)
8653                        (while children
8654                          (when (memq (car children) articles)
8655                            (setq children nil
8656                                  found t))
8657                          (pop children))
8658                        found)))
8659         (push (gnus-data-number d) articles)))
8660     ;; Do the limiting.
8661     (prog1
8662         (gnus-summary-limit articles)
8663       (gnus-summary-position-point))))
8664
8665 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8666   "Mark all unread excluded articles as read.
8667 If ALL, mark even excluded ticked and dormants as read."
8668   (interactive "P")
8669   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8670   (let ((articles (gnus-sorted-ndifference
8671                    (sort
8672                     (mapcar (lambda (h) (mail-header-number h))
8673                             gnus-newsgroup-headers)
8674                     '<)
8675                    gnus-newsgroup-limit))
8676         article)
8677     (setq gnus-newsgroup-unreads
8678           (gnus-sorted-intersection gnus-newsgroup-unreads
8679                                     gnus-newsgroup-limit))
8680     (if all
8681         (setq gnus-newsgroup-dormant nil
8682               gnus-newsgroup-marked nil
8683               gnus-newsgroup-reads
8684               (nconc
8685                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8686                gnus-newsgroup-reads))
8687       (while (setq article (pop articles))
8688         (unless (or (memq article gnus-newsgroup-dormant)
8689                     (memq article gnus-newsgroup-marked))
8690           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8691
8692 (defun gnus-summary-limit (articles &optional pop)
8693   (if pop
8694       ;; We pop the previous limit off the stack and use that.
8695       (setq articles (car gnus-newsgroup-limits)
8696             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8697     ;; We use the new limit, so we push the old limit on the stack.
8698     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8699   ;; Set the limit.
8700   (setq gnus-newsgroup-limit articles)
8701   (let ((total (length gnus-newsgroup-data))
8702         (data (gnus-data-find-list (gnus-summary-article-number)))
8703         (gnus-summary-mark-below nil)   ; Inhibit this.
8704         found)
8705     ;; This will do all the work of generating the new summary buffer
8706     ;; according to the new limit.
8707     (gnus-summary-prepare)
8708     ;; Hide any threads, possibly.
8709     (gnus-summary-maybe-hide-threads)
8710     ;; Try to return to the article you were at, or one in the
8711     ;; neighborhood.
8712     (when data
8713       ;; We try to find some article after the current one.
8714       (while data
8715         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8716           (setq data nil
8717                 found t))
8718         (setq data (cdr data))))
8719     (unless found
8720       ;; If there is no data, that means that we were after the last
8721       ;; article.  The same goes when we can't find any articles
8722       ;; after the current one.
8723       (goto-char (point-max))
8724       (gnus-summary-find-prev))
8725     (gnus-set-mode-line 'summary)
8726     ;; We return how many articles were removed from the summary
8727     ;; buffer as a result of the new limit.
8728     (- total (length gnus-newsgroup-data))))
8729
8730 (defsubst gnus-invisible-cut-children (threads)
8731   (let ((num 0))
8732     (while threads
8733       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8734         (incf num))
8735       (pop threads))
8736     (< num 2)))
8737
8738 (defsubst gnus-cut-thread (thread)
8739   "Go forwards in the thread until we find an article that we want to display."
8740   (when (or (eq gnus-fetch-old-headers 'some)
8741             (eq gnus-fetch-old-headers 'invisible)
8742             (numberp gnus-fetch-old-headers)
8743             (eq gnus-build-sparse-threads 'some)
8744             (eq gnus-build-sparse-threads 'more))
8745     ;; Deal with old-fetched headers and sparse threads.
8746     (while (and
8747             thread
8748             (or
8749              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8750              (gnus-summary-article-ancient-p
8751               (mail-header-number (car thread))))
8752             (if (or (<= (length (cdr thread)) 1)
8753                     (eq gnus-fetch-old-headers 'invisible))
8754                 (setq gnus-newsgroup-limit
8755                       (delq (mail-header-number (car thread))
8756                             gnus-newsgroup-limit)
8757                       thread (cadr thread))
8758               (when (gnus-invisible-cut-children (cdr thread))
8759                 (let ((th (cdr thread)))
8760                   (while th
8761                     (if (memq (mail-header-number (caar th))
8762                               gnus-newsgroup-limit)
8763                         (setq thread (car th)
8764                               th nil)
8765                       (setq th (cdr th))))))))))
8766   thread)
8767
8768 (defun gnus-cut-threads (threads)
8769   "Cut off all uninteresting articles from the beginning of THREADS."
8770   (when (or (eq gnus-fetch-old-headers 'some)
8771             (eq gnus-fetch-old-headers 'invisible)
8772             (numberp gnus-fetch-old-headers)
8773             (eq gnus-build-sparse-threads 'some)
8774             (eq gnus-build-sparse-threads 'more))
8775     (let ((th threads))
8776       (while th
8777         (setcar th (gnus-cut-thread (car th)))
8778         (setq th (cdr th)))))
8779   ;; Remove nixed out threads.
8780   (delq nil threads))
8781
8782 (defun gnus-summary-initial-limit (&optional show-if-empty)
8783   "Figure out what the initial limit is supposed to be on group entry.
8784 This entails weeding out unwanted dormants, low-scored articles,
8785 fetch-old-headers verbiage, and so on."
8786   ;; Most groups have nothing to remove.
8787   (unless (or gnus-inhibit-limiting
8788               (and (null gnus-newsgroup-dormant)
8789                    (eq gnus-newsgroup-display 'gnus-not-ignore)
8790                    (not (eq gnus-fetch-old-headers 'some))
8791                    (not (numberp gnus-fetch-old-headers))
8792                    (not (eq gnus-fetch-old-headers 'invisible))
8793                    (null gnus-summary-expunge-below)
8794                    (not (eq gnus-build-sparse-threads 'some))
8795                    (not (eq gnus-build-sparse-threads 'more))
8796                    (null gnus-thread-expunge-below)))
8797     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8798     (setq gnus-newsgroup-limit nil)
8799     (mapatoms
8800      (lambda (node)
8801        (unless (car (symbol-value node))
8802          ;; These threads have no parents -- they are roots.
8803          (let ((nodes (cdr (symbol-value node)))
8804                thread)
8805            (while nodes
8806              (if (and gnus-thread-expunge-below
8807                       (< (gnus-thread-total-score (car nodes))
8808                          gnus-thread-expunge-below))
8809                  (gnus-expunge-thread (pop nodes))
8810                (setq thread (pop nodes))
8811                (gnus-summary-limit-children thread))))))
8812      gnus-newsgroup-dependencies)
8813     ;; If this limitation resulted in an empty group, we might
8814     ;; pop the previous limit and use it instead.
8815     (when (and (not gnus-newsgroup-limit)
8816                show-if-empty)
8817       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8818     gnus-newsgroup-limit))
8819
8820 (defun gnus-summary-limit-children (thread)
8821   "Return 1 if this subthread is visible and 0 if it is not."
8822   ;; First we get the number of visible children to this thread.  This
8823   ;; is done by recursing down the thread using this function, so this
8824   ;; will really go down to a leaf article first, before slowly
8825   ;; working its way up towards the root.
8826   (when thread
8827     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8828            (children
8829            (if (cdr thread)
8830                (apply '+ (mapcar 'gnus-summary-limit-children
8831                                  (cdr thread)))
8832              0))
8833            (number (mail-header-number (car thread)))
8834            score)
8835       (if (and
8836            (not (memq number gnus-newsgroup-marked))
8837            (or
8838             ;; If this article is dormant and has absolutely no visible
8839             ;; children, then this article isn't visible.
8840             (and (memq number gnus-newsgroup-dormant)
8841                  (zerop children))
8842             ;; If this is "fetch-old-headered" and there is no
8843             ;; visible children, then we don't want this article.
8844             (and (or (eq gnus-fetch-old-headers 'some)
8845                      (numberp gnus-fetch-old-headers))
8846                  (gnus-summary-article-ancient-p number)
8847                  (zerop children))
8848             ;; If this is "fetch-old-headered" and `invisible', then
8849             ;; we don't want this article.
8850             (and (eq gnus-fetch-old-headers 'invisible)
8851                  (gnus-summary-article-ancient-p number))
8852             ;; If this is a sparsely inserted article with no children,
8853             ;; we don't want it.
8854             (and (eq gnus-build-sparse-threads 'some)
8855                  (gnus-summary-article-sparse-p number)
8856                  (zerop children))
8857             ;; If we use expunging, and this article is really
8858             ;; low-scored, then we don't want this article.
8859             (when (and gnus-summary-expunge-below
8860                        (< (setq score
8861                                 (or (cdr (assq number gnus-newsgroup-scored))
8862                                     gnus-summary-default-score))
8863                           gnus-summary-expunge-below))
8864               ;; We increase the expunge-tally here, but that has
8865               ;; nothing to do with the limits, really.
8866               (incf gnus-newsgroup-expunged-tally)
8867               ;; We also mark as read here, if that's wanted.
8868               (when (and gnus-summary-mark-below
8869                          (< score gnus-summary-mark-below))
8870                 (setq gnus-newsgroup-unreads
8871                       (delq number gnus-newsgroup-unreads))
8872                 (if gnus-newsgroup-auto-expire
8873                     (push number gnus-newsgroup-expirable)
8874                   (push (cons number gnus-low-score-mark)
8875                         gnus-newsgroup-reads)))
8876               t)
8877             ;; Do the `display' group parameter.
8878             (and gnus-newsgroup-display
8879                  (let ((gnus-number number))
8880                    (not (funcall gnus-newsgroup-display))))))
8881           ;; Nope, invisible article.
8882           0
8883         ;; Ok, this article is to be visible, so we add it to the limit
8884         ;; and return 1.
8885         (push number gnus-newsgroup-limit)
8886         1))))
8887
8888 (defun gnus-expunge-thread (thread)
8889   "Mark all articles in THREAD as read."
8890   (let* ((number (mail-header-number (car thread))))
8891     (incf gnus-newsgroup-expunged-tally)
8892     ;; We also mark as read here, if that's wanted.
8893     (setq gnus-newsgroup-unreads
8894           (delq number gnus-newsgroup-unreads))
8895     (if gnus-newsgroup-auto-expire
8896         (push number gnus-newsgroup-expirable)
8897       (push (cons number gnus-low-score-mark)
8898             gnus-newsgroup-reads)))
8899   ;; Go recursively through all subthreads.
8900   (mapcar 'gnus-expunge-thread (cdr thread)))
8901
8902 ;; Summary article oriented commands
8903
8904 (defun gnus-summary-refer-parent-article (n)
8905   "Refer parent article N times.
8906 If N is negative, go to ancestor -N instead.
8907 The difference between N and the number of articles fetched is returned."
8908   (interactive "p")
8909   (let ((skip 1)
8910         error header ref)
8911     (when (not (natnump n))
8912       (setq skip (abs n)
8913             n 1))
8914     (while (and (> n 0)
8915                 (not error))
8916       (setq header (gnus-summary-article-header))
8917       (if (and (eq (mail-header-number header)
8918                    (cdr gnus-article-current))
8919                (equal gnus-newsgroup-name
8920                       (car gnus-article-current)))
8921           ;; If we try to find the parent of the currently
8922           ;; displayed article, then we take a look at the actual
8923           ;; References header, since this is slightly more
8924           ;; reliable than the References field we got from the
8925           ;; server.
8926           (with-current-buffer gnus-original-article-buffer
8927             (nnheader-narrow-to-headers)
8928             (unless (setq ref (message-fetch-field "references"))
8929               (when (setq ref (message-fetch-field "in-reply-to"))
8930                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8931             (widen))
8932         (setq ref
8933               ;; It's not the current article, so we take a bet on
8934               ;; the value we got from the server.
8935               (mail-header-references header)))
8936       (if (and ref
8937                (not (equal ref "")))
8938           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8939             (gnus-message 1 "Couldn't find parent"))
8940         (gnus-message 1 "No references in article %d"
8941                       (gnus-summary-article-number))
8942         (setq error t))
8943       (decf n))
8944     (gnus-summary-position-point)
8945     n))
8946
8947 (defun gnus-summary-refer-references ()
8948   "Fetch all articles mentioned in the References header.
8949 Return the number of articles fetched."
8950   (interactive)
8951   (let ((ref (mail-header-references (gnus-summary-article-header)))
8952         (current (gnus-summary-article-number))
8953         (n 0))
8954     (if (or (not ref)
8955             (equal ref ""))
8956         (error "No References in the current article")
8957       ;; For each Message-ID in the References header...
8958       (while (string-match "<[^>]*>" ref)
8959         (incf n)
8960         ;; ... fetch that article.
8961         (gnus-summary-refer-article
8962          (prog1 (match-string 0 ref)
8963            (setq ref (substring ref (match-end 0))))))
8964       (gnus-summary-goto-subject current)
8965       (gnus-summary-position-point)
8966       n)))
8967
8968 (defun gnus-delete-duplicate-headers (headers)
8969   ;; First remove leading duplicates.
8970   (while (and (> (length headers) 1)
8971               (= (mail-header-number (car headers))
8972                  (mail-header-number (cadr headers))))
8973     (pop headers))
8974   ;; Then the rest.
8975   (let ((result headers))
8976     (while (> (length headers) 1)
8977       (if (= (mail-header-number (car headers))
8978              (mail-header-number (cadr headers)))
8979           (setcdr headers (cddr headers))
8980         (pop headers)))
8981     result))
8982
8983 (defun gnus-summary-refer-thread (&optional limit)
8984   "Fetch all articles in the current thread. For backends that
8985 know how to search for threads (currently only 'nnimap) a
8986 non-numeric prefix arg will use nnir to search the entire
8987 server; without a prefix arg only the current group is
8988 searched. If the variable `gnus-refer-thread-use-nnir' is
8989 non-nil the prefix arg has the reverse meaning. If no
8990 backend-specific 'request-thread function is available fetch
8991 LIMIT (the numerical prefix) old headers. If LIMIT is
8992 non-numeric or nil fetch the number specified by the
8993 `gnus-refer-thread-limit' variable."
8994   (interactive "P")
8995   (gnus-warp-to-article)
8996   (let* ((header (gnus-summary-article-header))
8997          (id (mail-header-id header))
8998          (gnus-inhibit-demon t)
8999          (gnus-summary-ignore-duplicates t)
9000          (gnus-read-all-available-headers t)
9001          (gnus-refer-thread-use-nnir
9002           (if (and (not (null limit)) (listp limit))
9003               (not gnus-refer-thread-use-nnir) gnus-refer-thread-use-nnir))
9004          (new-headers
9005           (if (gnus-check-backend-function
9006                'request-thread gnus-newsgroup-name)
9007               (gnus-request-thread header gnus-newsgroup-name)
9008             (let* ((limit (if (numberp limit) (prefix-numeric-value limit)
9009                             gnus-refer-thread-limit))
9010                    (last (if (numberp limit)
9011                              (min (+ (mail-header-number header)
9012                                      limit)
9013                                   gnus-newsgroup-highest)
9014                            gnus-newsgroup-highest))
9015                    (subject (gnus-simplify-subject
9016                              (mail-header-subject header)))
9017                    (refs (split-string (or (mail-header-references header)
9018                                            "")))
9019                    (gnus-parse-headers-hook
9020                     `(lambda () (goto-char (point-min))
9021                       (keep-lines
9022                        (regexp-opt ',(append refs (list id subject)))))))
9023               (gnus-fetch-headers (list last) (if (numberp limit)
9024                                                   (* 2 limit) limit) t)))))
9025     (when (listp new-headers)
9026       (dolist (header new-headers)
9027         (when (member (mail-header-number header) gnus-newsgroup-unselected)
9028           (push (mail-header-number header) gnus-newsgroup-unreads)
9029           (setq gnus-newsgroup-unselected
9030                 (delete (mail-header-number header)
9031                         gnus-newsgroup-unselected))))
9032       (setq gnus-newsgroup-headers
9033             (gnus-delete-duplicate-headers
9034              (gnus-merge
9035               'list gnus-newsgroup-headers new-headers
9036               'gnus-article-sort-by-number)))
9037       (gnus-summary-limit-include-thread id))))
9038
9039 (defun gnus-summary-refer-article (message-id)
9040   "Fetch an article specified by MESSAGE-ID."
9041   (interactive "sMessage-ID: ")
9042   (gnus-warp-to-article)
9043   (when (and (stringp message-id)
9044              (not (zerop (length message-id))))
9045     (setq message-id (gnus-replace-in-string message-id " " ""))
9046     ;; Construct the correct Message-ID if necessary.
9047     ;; Suggested by tale@pawl.rpi.edu.
9048     (unless (string-match "^<" message-id)
9049       (setq message-id (concat "<" message-id)))
9050     (unless (string-match ">$" message-id)
9051       (setq message-id (concat message-id ">")))
9052     ;; People often post MIDs from URLs, so unhex it:
9053     (unless (string-match "@" message-id)
9054       (setq message-id (gnus-url-unhex-string message-id)))
9055     (let* ((header (gnus-id-to-header message-id))
9056            (sparse (and header
9057                         (gnus-summary-article-sparse-p
9058                          (mail-header-number header))
9059                         (memq (mail-header-number header)
9060                               gnus-newsgroup-limit)))
9061            number)
9062       (cond
9063        ;; If the article is present in the buffer we just go to it.
9064        ((and header
9065              (or (not (gnus-summary-article-sparse-p
9066                        (mail-header-number header)))
9067                  sparse))
9068         (prog1
9069             (gnus-summary-goto-article
9070              (mail-header-number header) nil t)
9071           (when sparse
9072             (gnus-summary-update-article (mail-header-number header)))))
9073        (t
9074         ;; We fetch the article.
9075         (catch 'found
9076           (dolist (gnus-override-method (gnus-refer-article-methods))
9077             (when (and (gnus-check-server gnus-override-method)
9078                        ;; Fetch the header,
9079                        (setq number (gnus-summary-insert-subject message-id)))
9080               ;; and display the article.
9081               (gnus-summary-select-article nil nil nil number)
9082               (throw 'found t)))
9083           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
9084
9085 (defun gnus-refer-article-methods ()
9086   "Return a list of referable methods."
9087   (cond
9088    ;; No method, so we default to current and native.
9089    ((null gnus-refer-article-method)
9090     (list gnus-current-select-method gnus-select-method))
9091    ;; Current.
9092    ((eq 'current gnus-refer-article-method)
9093     (list gnus-current-select-method))
9094    ;; List of select methods.
9095    ((not (and (symbolp (car gnus-refer-article-method))
9096               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
9097     (let (out)
9098       (dolist (method gnus-refer-article-method)
9099         (push (if (eq 'current method)
9100                   gnus-current-select-method
9101                 (if (eq 'nnir (car method))
9102                     (list
9103                      'nnir
9104                      (or (cadr method)
9105                          (gnus-method-to-server gnus-current-select-method)))
9106                   method))
9107               out))
9108       (nreverse out)))
9109    ;; One single select method.
9110    (t
9111     (list gnus-refer-article-method))))
9112
9113 (defun gnus-summary-edit-parameters ()
9114   "Edit the group parameters of the current group."
9115   (interactive)
9116   (gnus-group-edit-group gnus-newsgroup-name 'params))
9117
9118 (defun gnus-summary-customize-parameters ()
9119   "Customize the group parameters of the current group."
9120   (interactive)
9121   (gnus-group-customize gnus-newsgroup-name))
9122
9123 (defun gnus-summary-enter-digest-group (&optional force)
9124   "Enter an nndoc group based on the current article.
9125 If FORCE, force a digest interpretation.  If not, try to guess
9126 what the document format is.
9127
9128 To control what happens when you exit the group, see the
9129 `gnus-auto-select-on-ephemeral-exit' variable."
9130   (interactive "P")
9131   (let ((conf gnus-current-window-configuration))
9132     (save-window-excursion
9133       (save-excursion
9134         (let (gnus-article-prepare-hook
9135               gnus-display-mime-function
9136               gnus-break-pages)
9137           (gnus-summary-select-article))))
9138     (setq gnus-current-window-configuration conf)
9139     (let* ((name (format "%s-%d"
9140                          (gnus-group-prefixed-name
9141                           gnus-newsgroup-name (list 'nndoc ""))
9142                          (with-current-buffer gnus-summary-buffer
9143                            gnus-current-article)))
9144            (ogroup gnus-newsgroup-name)
9145            (params (append (gnus-info-params (gnus-get-info ogroup))
9146                            (list (cons 'to-group ogroup))
9147                            (list (cons 'parent-group ogroup))
9148                            (list (cons 'save-article-group ogroup))))
9149            (case-fold-search t)
9150            (buf (current-buffer))
9151            dig to-address)
9152       (with-current-buffer gnus-original-article-buffer
9153         ;; Have the digest group inherit the main mail address of
9154         ;; the parent article.
9155         (when (setq to-address (or (gnus-fetch-field "reply-to")
9156                                    (gnus-fetch-field "from")))
9157           (setq params
9158                 (append
9159                  (list (cons 'to-address
9160                              (funcall gnus-decode-encoded-address-function
9161                                       to-address))))))
9162         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
9163         (insert-buffer-substring gnus-original-article-buffer)
9164         ;; Remove lines that may lead nndoc to misinterpret the
9165         ;; document type.
9166         (narrow-to-region
9167          (goto-char (point-min))
9168          (or (search-forward "\n\n" nil t) (point)))
9169         (goto-char (point-min))
9170         (delete-matching-lines "^Path:\\|^From ")
9171         (widen))
9172       (unwind-protect
9173           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
9174                     (gnus-newsgroup-ephemeral-ignored-charsets
9175                      gnus-newsgroup-ignored-charsets))
9176                 (gnus-group-read-ephemeral-group
9177                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
9178                               (nndoc-article-type
9179                                ,(if force 'mbox 'guess)))
9180                  t nil nil nil
9181                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
9182                                                         "ADAPT")))))
9183               ;; Make all postings to this group go to the parent group.
9184               (nconc (gnus-info-params (gnus-get-info name))
9185                      params)
9186             ;; Couldn't select this doc group.
9187             (switch-to-buffer buf)
9188             (gnus-set-global-variables)
9189             (gnus-configure-windows 'summary)
9190             (gnus-message 3 "Article couldn't be entered?"))
9191         (kill-buffer dig)))))
9192
9193 (defun gnus-summary-read-document (n)
9194   "Open a new group based on the current article(s).
9195 This will allow you to read digests and other similar
9196 documents as newsgroups.
9197 Obeys the standard process/prefix convention."
9198   (interactive "P")
9199   (let* ((ogroup gnus-newsgroup-name)
9200          (params (append (gnus-info-params (gnus-get-info ogroup))
9201                          (list (cons 'to-group ogroup))))
9202          group egroup groups vgroup)
9203     (dolist (article (gnus-summary-work-articles n))
9204       (setq group (format "%s-%d" gnus-newsgroup-name article))
9205       (gnus-summary-remove-process-mark article)
9206       (when (gnus-summary-display-article article)
9207         (save-excursion ;;What for?
9208           (with-temp-buffer
9209             (insert-buffer-substring gnus-original-article-buffer)
9210             ;; Remove some headers that may lead nndoc to make
9211             ;; the wrong guess.
9212             (message-narrow-to-head)
9213             (goto-char (point-min))
9214             (delete-matching-lines "^Path:\\|^From ")
9215             (widen)
9216             (if (setq egroup
9217                       (gnus-group-read-ephemeral-group
9218                        group `(nndoc ,group (nndoc-address ,(current-buffer))
9219                                      (nndoc-article-type guess))
9220                        t nil t))
9221                 (progn
9222                   ;; Make all postings to this group go to the parent group.
9223                   (nconc (gnus-info-params (gnus-get-info egroup))
9224                          params)
9225                   (push egroup groups))
9226               ;; Couldn't select this doc group.
9227               (gnus-error 3 "Article couldn't be entered"))))))
9228     ;; Now we have selected all the documents.
9229     (cond
9230      ((not groups)
9231       (error "None of the articles could be interpreted as documents"))
9232      ((gnus-group-read-ephemeral-group
9233        (setq vgroup (format
9234                      "nnvirtual:%s-%s" gnus-newsgroup-name
9235                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9236        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9237        t
9238        (cons (current-buffer) 'summary)))
9239      (t
9240       (error "Couldn't select virtual nndoc group")))))
9241
9242 (defun gnus-summary-widget-forward (arg)
9243   "Move point to the next field or button in the article.
9244 With optional ARG, move across that many fields."
9245   (interactive "p")
9246   (gnus-summary-select-article)
9247   (gnus-configure-windows 'article)
9248   (select-window (gnus-get-buffer-window gnus-article-buffer))
9249   (widget-forward arg))
9250
9251 (defun gnus-summary-isearch-article (&optional regexp-p)
9252   "Do incremental search forward on the current article.
9253 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9254   (interactive "P")
9255   (gnus-summary-select-article)
9256   (gnus-configure-windows 'article)
9257   (gnus-eval-in-buffer-window gnus-article-buffer
9258     (save-restriction
9259       (widen)
9260       (isearch-forward regexp-p))))
9261
9262 (defun gnus-summary-repeat-search-article-forward ()
9263   "Repeat the previous search forwards."
9264   (interactive)
9265   (unless gnus-last-search-regexp
9266     (error "No previous search"))
9267   (gnus-summary-search-article-forward gnus-last-search-regexp))
9268
9269 (defun gnus-summary-repeat-search-article-backward ()
9270   "Repeat the previous search backwards."
9271   (interactive)
9272   (unless gnus-last-search-regexp
9273     (error "No previous search"))
9274   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9275
9276 (defun gnus-summary-search-article-forward (regexp &optional backward)
9277   "Search for an article containing REGEXP forward.
9278 If BACKWARD, search backward instead."
9279   (interactive
9280    (list (read-string
9281           (format "Search article %s (regexp%s): "
9282                   (if current-prefix-arg "backward" "forward")
9283                   (if gnus-last-search-regexp
9284                       (concat ", default " gnus-last-search-regexp)
9285                     "")))
9286          current-prefix-arg))
9287   (if (string-equal regexp "")
9288       (setq regexp (or gnus-last-search-regexp ""))
9289     (setq gnus-last-search-regexp regexp)
9290     (setq gnus-article-before-search gnus-current-article))
9291   ;; Intentionally set gnus-last-article.
9292   (setq gnus-last-article gnus-article-before-search)
9293   (let ((gnus-last-article gnus-last-article))
9294     (if (gnus-summary-search-article regexp backward)
9295         (gnus-summary-show-thread)
9296       (signal 'search-failed (list regexp)))))
9297
9298 (defun gnus-summary-search-article-backward (regexp)
9299   "Search for an article containing REGEXP backward."
9300   (interactive
9301    (list (read-string
9302           (format "Search article backward (regexp%s): "
9303                   (if gnus-last-search-regexp
9304                       (concat ", default " gnus-last-search-regexp)
9305                     "")))))
9306   (gnus-summary-search-article-forward regexp 'backward))
9307
9308 (defun gnus-summary-search-article (regexp &optional backward)
9309   "Search for an article containing REGEXP.
9310 Optional argument BACKWARD means do search for backward.
9311 `gnus-select-article-hook' is not called during the search."
9312   ;; We have to require this here to make sure that the following
9313   ;; dynamic binding isn't shadowed by autoloading.
9314   (require 'gnus-async)
9315   (require 'gnus-art)
9316   (let ((gnus-select-article-hook nil)  ;Disable hook.
9317         (gnus-article-prepare-hook nil)
9318         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9319         (gnus-use-article-prefetch nil)
9320         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9321         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9322         (gnus-visual nil)
9323         (gnus-keep-backlog nil)
9324         (gnus-break-pages nil)
9325         (gnus-summary-display-arrow nil)
9326         (gnus-updated-mode-lines nil)
9327         (gnus-auto-center-summary nil)
9328         (sum (current-buffer))
9329         (gnus-display-mime-function nil)
9330         (found nil)
9331         point)
9332     (gnus-save-hidden-threads
9333       (gnus-summary-select-article)
9334       (set-buffer gnus-article-buffer)
9335       (goto-char (window-point (get-buffer-window (current-buffer))))
9336       (when backward
9337         (forward-line -1))
9338       (while (not found)
9339         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9340         (if (if backward
9341                 (re-search-backward regexp nil t)
9342               (re-search-forward regexp nil t))
9343             ;; We found the regexp.
9344             (progn
9345               (setq found 'found)
9346               (beginning-of-line)
9347               (set-window-start
9348                (get-buffer-window (current-buffer))
9349                (point))
9350               (forward-line 1)
9351               (set-window-point
9352                (get-buffer-window (current-buffer))
9353                (point))
9354               (set-buffer sum)
9355               (setq point (point)))
9356           ;; We didn't find it, so we go to the next article.
9357           (set-buffer sum)
9358           (setq found 'not)
9359           (while (eq found 'not)
9360             (if (not (if backward (gnus-summary-find-prev)
9361                        (gnus-summary-find-next)))
9362                 ;; No more articles.
9363                 (setq found t)
9364               ;; Select the next article and adjust point.
9365               (unless (gnus-summary-article-sparse-p
9366                        (gnus-summary-article-number))
9367                 (setq found nil)
9368                 (gnus-summary-select-article)
9369                 (set-buffer gnus-article-buffer)
9370                 (widen)
9371                 (goto-char (if backward (point-max) (point-min))))))))
9372       (gnus-message 7 ""))
9373     ;; Return whether we found the regexp.
9374     (when (eq found 'found)
9375       (goto-char point)
9376       (gnus-summary-show-thread)
9377       (gnus-summary-goto-subject gnus-current-article)
9378       (gnus-summary-position-point)
9379       t)))
9380
9381 (defun gnus-find-matching-articles (header regexp)
9382   "Return a list of all articles that match REGEXP on HEADER.
9383 This search includes all articles in the current group that Gnus has
9384 fetched headers for, whether they are displayed or not."
9385   (let ((articles nil)
9386         ;; Can't eta-reduce because it's a macro.
9387         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9388         (case-fold-search t))
9389     (dolist (header gnus-newsgroup-headers)
9390       (when (string-match regexp (funcall func header))
9391         (push (mail-header-number header) articles)))
9392     (nreverse articles)))
9393
9394 (defun gnus-summary-find-matching (header regexp &optional backward unread
9395                                           not-case-fold not-matching)
9396   "Return a list of all articles that match REGEXP on HEADER.
9397 The search stars on the current article and goes forwards unless
9398 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9399 If UNREAD is non-nil, only unread articles will
9400 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9401 in the comparisons. If NOT-MATCHING, return a list of all articles that
9402 not match REGEXP on HEADER."
9403   (let ((case-fold-search (not not-case-fold))
9404         articles d func)
9405     (if (consp header)
9406         (if (eq (car header) 'extra)
9407             (setq func
9408                   `(lambda (h)
9409                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9410                          "")))
9411           (error "%s is an invalid header" header))
9412       (unless (fboundp (intern (concat "mail-header-" header)))
9413         (error "%s is not a valid header" header))
9414       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9415     (dolist (d (if (eq backward 'all)
9416                    gnus-newsgroup-data
9417                  (gnus-data-find-list
9418                   (gnus-summary-article-number)
9419                   (gnus-data-list backward))))
9420       (when (and (or (not unread)       ; We want all articles...
9421                      (gnus-data-unread-p d)) ; Or just unreads.
9422                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9423                  (if not-matching
9424                      (not (string-match
9425                            regexp
9426                            (funcall func (gnus-data-header d))))
9427                    (string-match regexp
9428                                  (funcall func (gnus-data-header d)))))
9429         (push (gnus-data-number d) articles))) ; Success!
9430     (nreverse articles)))
9431
9432 (defun gnus-summary-execute-command (header regexp command &optional backward)
9433   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9434 If HEADER is an empty string (or nil), the match is done on the entire
9435 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9436   (interactive
9437    (list (let ((completion-ignore-case t))
9438            (gnus-completing-read
9439             "Header name"
9440             (mapcar 'symbol-name
9441                     (append
9442                      '(Number Subject From Lines Date
9443                        Message-ID Xref References Body)
9444                      gnus-extra-headers))
9445             'require-match))
9446          (read-string "Regexp: ")
9447          (read-key-sequence "Command: ")
9448          current-prefix-arg))
9449   (when (equal header "Body")
9450     (setq header ""))
9451   ;; Hidden thread subtrees must be searched as well.
9452   (gnus-summary-show-all-threads)
9453   ;; We don't want to change current point nor window configuration.
9454   (save-excursion
9455     (save-window-excursion
9456       (let (gnus-visual
9457             gnus-treat-strip-trailing-blank-lines
9458             gnus-treat-strip-leading-blank-lines
9459             gnus-treat-strip-multiple-blank-lines
9460             gnus-treat-hide-boring-headers
9461             gnus-treat-fold-newsgroups
9462             gnus-article-prepare-hook)
9463         (gnus-message 6 "Executing %s..." (key-description command))
9464         ;; We'd like to execute COMMAND interactively so as to give arguments.
9465         (gnus-execute header regexp
9466                       `(call-interactively ',(key-binding command))
9467                       backward)
9468         (gnus-message 6 "Executing %s...done" (key-description command))))))
9469
9470 (defun gnus-summary-beginning-of-article ()
9471   "Scroll the article back to the beginning."
9472   (interactive)
9473   (gnus-summary-select-article)
9474   (gnus-configure-windows 'article)
9475   (gnus-eval-in-buffer-window gnus-article-buffer
9476     (widen)
9477     (goto-char (point-min))
9478     (when gnus-break-pages
9479       (gnus-narrow-to-page))))
9480
9481 (defun gnus-summary-end-of-article ()
9482   "Scroll to the end of the article."
9483   (interactive)
9484   (gnus-summary-select-article)
9485   (gnus-configure-windows 'article)
9486   (gnus-eval-in-buffer-window gnus-article-buffer
9487     (widen)
9488     (goto-char (point-max))
9489     (recenter -3)
9490     (when gnus-break-pages
9491       (gnus-narrow-to-page))))
9492
9493 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9494   "Truncate to LEN and quote all \"(\"'s in STRING."
9495   (gnus-replace-in-string (if (and len (> (length string) len))
9496                               (substring string 0 len)
9497                             string)
9498                           "[()]" "\\\\\\&"))
9499
9500 (defun gnus-summary-print-article (&optional filename n)
9501   "Generate and print a PostScript image of the process-marked (mail) articles.
9502
9503 If used interactively, print the current article if none are
9504 process-marked.  With prefix arg, prompt the user for the name of the
9505 file to save in.
9506
9507 When used from Lisp, accept two optional args FILENAME and N.  N means
9508 to print the next N articles.  If N is negative, print the N previous
9509 articles.  If N is nil and articles have been marked with the process
9510 mark, print these instead.
9511
9512 If the optional first argument FILENAME is nil, send the image to the
9513 printer.  If FILENAME is a string, save the PostScript image in a file with
9514 that name.  If FILENAME is a number, prompt the user for the name of the file
9515 to save in."
9516   (interactive (list (ps-print-preprint current-prefix-arg)))
9517   (dolist (article (gnus-summary-work-articles n))
9518     (gnus-summary-select-article nil nil 'pseudo article)
9519     (gnus-eval-in-buffer-window gnus-article-buffer
9520       (gnus-print-buffer))
9521     (gnus-summary-remove-process-mark article))
9522   (ps-despool filename))
9523
9524 (defun gnus-print-buffer ()
9525   (let ((ps-left-header
9526          (list
9527           (concat "("
9528                   (gnus-summary-print-truncate-and-quote
9529                    (mail-header-subject gnus-current-headers)
9530                    66) ")")
9531           (concat "("
9532                   (gnus-summary-print-truncate-and-quote
9533                    (mail-header-from gnus-current-headers)
9534                    45) ")")))
9535         (ps-right-header
9536          (list
9537           "/pagenumberstring load"
9538           (concat "("
9539                   (mail-header-date gnus-current-headers) ")"))))
9540     (gnus-run-hooks 'gnus-ps-print-hook)
9541     (save-excursion
9542       (if ps-print-color-p
9543           (ps-spool-buffer-with-faces)
9544         (ps-spool-buffer)))))
9545
9546 (defun gnus-summary-show-complete-article ()
9547   "Show a complete version of the current article.
9548 This is only useful if you're looking at a partial version of the
9549 article currently."
9550   (interactive)
9551   (let ((gnus-keep-backlog nil)
9552         (gnus-use-cache nil)
9553         (gnus-agent nil)
9554         (variable (intern
9555                    (format "%s-fetch-partial-articles"
9556                            (car (gnus-find-method-for-group
9557                                  gnus-newsgroup-name)))
9558                    obarray))
9559         old-val)
9560     (unwind-protect
9561         (progn
9562           (setq old-val (symbol-value variable))
9563           (set variable nil)
9564           (gnus-flush-original-article-buffer)
9565           (gnus-summary-show-article))
9566       (set variable old-val))))
9567
9568 (defun gnus-summary-show-article (&optional arg)
9569   "Force redisplaying of the current article.
9570 If ARG (the prefix) is a number, show the article with the charset
9571 defined in `gnus-summary-show-article-charset-alist', or the charset
9572 input.
9573 If ARG (the prefix) is non-nil and not a number, show the article,
9574 but without running any of the article treatment functions
9575 article.  Normally, the keystroke is `C-u g'.  When using `C-u
9576 C-u g', show the raw article."
9577   (interactive "P")
9578   (cond
9579    ((numberp arg)
9580     (gnus-summary-show-article t)
9581     (let ((gnus-newsgroup-charset
9582            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9583                (mm-read-coding-system
9584                 "View as charset: " ;; actually it is coding system.
9585                 (with-current-buffer gnus-article-buffer
9586                   (mm-detect-coding-region (point) (point-max))))))
9587           (gnus-newsgroup-ignored-charsets 'gnus-all))
9588       (gnus-summary-select-article nil 'force)
9589       (let ((deps gnus-newsgroup-dependencies)
9590             head header lines)
9591         (with-current-buffer gnus-original-article-buffer
9592           (save-restriction
9593             (message-narrow-to-head)
9594             (setq head (buffer-string))
9595             (goto-char (point-min))
9596             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9597               (goto-char (point-max))
9598               (widen)
9599               (setq lines (1- (count-lines (point) (point-max))))))
9600           (with-temp-buffer
9601             (insert (format "211 %d Article retrieved.\n"
9602                             (cdr gnus-article-current)))
9603             (insert head)
9604             (if lines (insert (format "Lines: %d\n" lines)))
9605             (insert ".\n")
9606             (let ((nntp-server-buffer (current-buffer)))
9607               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9608         (gnus-data-set-header
9609          (gnus-data-find (cdr gnus-article-current))
9610          header)
9611         (gnus-summary-update-article-line
9612          (cdr gnus-article-current) header)
9613         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9614           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9615    ((not arg)
9616     ;; Select the article the normal way.
9617     (gnus-summary-select-article nil 'force))
9618    ((equal arg '(16))
9619     ;; C-u C-u g
9620     (let ((gnus-inhibit-article-treatments t))
9621       (gnus-summary-select-article nil 'force)))
9622    (t
9623     ;; We have to require this here to make sure that the following
9624     ;; dynamic binding isn't shadowed by autoloading.
9625     (require 'gnus-async)
9626     (require 'gnus-art)
9627     ;; Bind the article treatment functions to nil.
9628     (let ((gnus-have-all-headers t)
9629           gnus-article-prepare-hook
9630           gnus-article-decode-hook
9631           gnus-display-mime-function
9632           gnus-break-pages)
9633       ;; Destroy any MIME parts.
9634       (when (gnus-buffer-live-p gnus-article-buffer)
9635         (with-current-buffer gnus-article-buffer
9636           (gnus-article-stop-animations)
9637           (mm-destroy-parts gnus-article-mime-handles)
9638           ;; Set it to nil for safety reason.
9639           (setq gnus-article-mime-handle-alist nil)
9640           (setq gnus-article-mime-handles nil)))
9641       (gnus-summary-select-article nil 'force))))
9642   (gnus-summary-goto-subject gnus-current-article)
9643   (gnus-summary-position-point))
9644
9645 (defun gnus-summary-show-raw-article ()
9646   "Show the raw article without any article massaging functions being run."
9647   (interactive)
9648   (gnus-summary-show-article t))
9649
9650 (defun gnus-summary-verbose-headers (&optional arg)
9651   "Toggle permanent full header display.
9652 If ARG is a positive number, turn header display on.
9653 If ARG is a negative number, turn header display off."
9654   (interactive "P")
9655   (setq gnus-show-all-headers
9656         (cond ((or (not (numberp arg))
9657                    (zerop arg))
9658                (not gnus-show-all-headers))
9659               ((natnump arg)
9660                t)))
9661   (gnus-summary-show-article))
9662
9663 (defun gnus-summary-toggle-header (&optional arg)
9664   "Show the headers if they are hidden, or hide them if they are shown.
9665 If ARG is a positive number, show the entire header.
9666 If ARG is a negative number, hide the unwanted header lines."
9667   (interactive "P")
9668   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9669                      (get-buffer-window gnus-article-buffer t))))
9670     (with-current-buffer gnus-article-buffer
9671       (widen)
9672       (article-narrow-to-head)
9673       (let* ((inhibit-read-only t)
9674              (inhibit-point-motion-hooks t)
9675              (hidden (if (numberp arg)
9676                          (>= arg 0)
9677                        (or (not (looking-at "[^ \t\n]+:"))
9678                            (gnus-article-hidden-text-p 'headers))))
9679              s e)
9680         (delete-region (point-min) (point-max))
9681         (with-current-buffer gnus-original-article-buffer
9682           (goto-char (setq s (point-min)))
9683           (setq e (if (search-forward "\n\n" nil t)
9684                       (1- (point))
9685                     (point-max))))
9686         (insert-buffer-substring gnus-original-article-buffer s e)
9687         (run-hooks 'gnus-article-decode-hook)
9688         (if hidden
9689             (let ((gnus-treat-hide-headers nil)
9690                   (gnus-treat-hide-boring-headers nil))
9691               (gnus-delete-wash-type 'headers)
9692               (gnus-treat-article 'head))
9693           (gnus-treat-article 'head))
9694         (widen)
9695         (if window
9696             (set-window-start window (goto-char (point-min))))
9697         (if gnus-break-pages
9698             (gnus-narrow-to-page)
9699           (when (gnus-visual-p 'page-marker)
9700             (let ((inhibit-read-only t))
9701               (gnus-remove-text-with-property 'gnus-prev)
9702               (gnus-remove-text-with-property 'gnus-next))))
9703         (gnus-set-mode-line 'article)))))
9704
9705 (defun gnus-summary-show-all-headers ()
9706   "Make all header lines visible."
9707   (interactive)
9708   (gnus-summary-toggle-header 1))
9709
9710 (defun gnus-summary-caesar-message (&optional arg)
9711   "Caesar rotate the current article by 13.
9712 With a non-numerical prefix, also rotate headers.  A numerical
9713 prefix specifies how many places to rotate each letter forward."
9714   (interactive "P")
9715   (gnus-summary-select-article)
9716   (let ((mail-header-separator ""))
9717     (gnus-eval-in-buffer-window gnus-article-buffer
9718       (save-restriction
9719         (widen)
9720         (let ((start (window-start))
9721               (inhibit-read-only t))
9722           (if (equal arg '(4))
9723               (message-caesar-buffer-body nil t)
9724             (message-caesar-buffer-body arg))
9725           (set-window-start (get-buffer-window (current-buffer)) start)))))
9726   ;; Create buttons and stuff...
9727   (gnus-treat-article nil))
9728
9729 (declare-function idna-to-unicode "ext:idna" (str))
9730
9731 (defun gnus-summary-idna-message (&optional arg)
9732   "Decode IDNA encoded domain names in the current articles.
9733 IDNA encoded domain names looks like `xn--bar'.  If a string
9734 remain unencoded after running this function, it is likely an
9735 invalid IDNA string (`xn--bar' is invalid).
9736
9737 You must have GNU Libidn (URL `http://www.gnu.org/software/libidn/')
9738 installed for this command to work."
9739   (interactive "P")
9740   (if (not (and (condition-case nil (require 'idna)
9741                   (file-error))
9742                 (mm-coding-system-p 'utf-8)
9743                 (executable-find (symbol-value 'idna-program))))
9744       (gnus-message
9745        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9746     (gnus-summary-select-article)
9747     (let ((mail-header-separator ""))
9748       (gnus-eval-in-buffer-window gnus-article-buffer
9749         (save-restriction
9750           (widen)
9751           (let ((start (window-start))
9752                 buffer-read-only)
9753             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9754               (replace-match (idna-to-unicode (match-string 1))))
9755             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9756
9757 (defun gnus-summary-morse-message (&optional arg)
9758   "Morse decode the current article."
9759   (interactive "P")
9760   (gnus-summary-select-article)
9761   (let ((mail-header-separator ""))
9762     (gnus-eval-in-buffer-window gnus-article-buffer
9763       (save-excursion
9764         (save-restriction
9765           (widen)
9766           (let ((pos (window-start))
9767                 (inhibit-read-only t))
9768             (goto-char (point-min))
9769             (when (message-goto-body)
9770               (gnus-narrow-to-body))
9771             (goto-char (point-min))
9772             (while (search-forward "·" (point-max) t)
9773               (replace-match "."))
9774             (unmorse-region (point-min) (point-max))
9775             (widen)
9776             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9777
9778 (defun gnus-summary-stop-page-breaking ()
9779   "Stop page breaking in the current article."
9780   (interactive)
9781   (gnus-summary-select-article)
9782   (gnus-eval-in-buffer-window gnus-article-buffer
9783     (widen)
9784     (when (gnus-visual-p 'page-marker)
9785       (let ((inhibit-read-only t))
9786         (gnus-remove-text-with-property 'gnus-prev)
9787         (gnus-remove-text-with-property 'gnus-next))
9788       (setq gnus-page-broken nil))))
9789
9790 (defun gnus-summary-move-article (&optional n to-newsgroup
9791                                             select-method action)
9792   "Move the current article to a different newsgroup.
9793 If N is a positive number, move the N next articles.
9794 If N is a negative number, move the N previous articles.
9795 If N is nil and any articles have been marked with the process mark,
9796 move those articles instead.
9797 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9798 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9799 re-spool using this method.
9800
9801 When called interactively with TO-NEWSGROUP being nil, the value of
9802 the variable `gnus-move-split-methods' is used for finding a default
9803 for the target newsgroup.
9804
9805 For this function to work, both the current newsgroup and the
9806 newsgroup that you want to move to have to support the `request-move'
9807 and `request-accept' functions.
9808
9809 ACTION can be either `move' (the default), `crosspost' or `copy'."
9810   (interactive "P")
9811   (unless action
9812     (setq action 'move))
9813   ;; Check whether the source group supports the required functions.
9814   (cond ((and (eq action 'move)
9815               (not (gnus-check-backend-function
9816                     'request-move-article gnus-newsgroup-name)))
9817          (error "The current group does not support article moving"))
9818         ((and (eq action 'crosspost)
9819               (not (gnus-check-backend-function
9820                     'request-replace-article gnus-newsgroup-name)))
9821          (error "The current group does not support article editing")))
9822   (let ((articles (gnus-summary-work-articles n))
9823         (prefix (if (gnus-check-backend-function
9824                      'request-move-article gnus-newsgroup-name)
9825                     (funcall gnus-move-group-prefix-function
9826                              gnus-newsgroup-name)
9827                   ""))
9828         (names '((move "Move" "Moving")
9829                  (copy "Copy" "Copying")
9830                  (crosspost "Crosspost" "Crossposting")))
9831         (copy-buf (save-excursion
9832                     (nnheader-set-temp-buffer " *copy article*")))
9833         art-group to-method new-xref article to-groups
9834         articles-to-update-marks encoded)
9835     (unless (assq action names)
9836       (error "Unknown action %s" action))
9837     ;; Read the newsgroup name.
9838     (when (and (not to-newsgroup)
9839                (not select-method))
9840       (if (and gnus-move-split-methods
9841                (not
9842                 (and (memq gnus-current-article articles)
9843                      (gnus-buffer-live-p gnus-original-article-buffer))))
9844           ;; When `gnus-move-split-methods' is non-nil, we have to
9845           ;; select an article to give `gnus-read-move-group-name' an
9846           ;; opportunity to suggest an appropriate default.  However,
9847           ;; we needn't render or mark the article.
9848           (let ((gnus-display-mime-function nil)
9849                 (gnus-article-prepare-hook nil)
9850                 (gnus-mark-article-hook nil))
9851             (gnus-summary-select-article nil nil nil (car articles))))
9852       (setq to-newsgroup (gnus-read-move-group-name
9853                           (cadr (assq action names))
9854                           (symbol-value
9855                            (intern (format "gnus-current-%s-group" action)))
9856                           articles prefix)
9857             encoded to-newsgroup
9858             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9859       (set (intern (format "gnus-current-%s-group" action))
9860            (mm-decode-coding-string
9861             to-newsgroup
9862             (gnus-group-name-charset to-method to-newsgroup))))
9863     (unless to-method
9864       (setq to-method (or select-method
9865                           (gnus-server-to-method
9866                            (gnus-group-method to-newsgroup)))))
9867     (setq to-newsgroup
9868           (or encoded
9869               (and to-newsgroup
9870                    (mm-encode-coding-string
9871                     to-newsgroup
9872                     (gnus-group-name-charset to-method to-newsgroup)))))
9873     ;; Check the method we are to move this article to...
9874     (unless (gnus-check-backend-function
9875              'request-accept-article (car to-method))
9876       (error "%s does not support article copying" (car to-method)))
9877     (unless (gnus-check-server to-method)
9878       (error "Can't open server %s" (car to-method)))
9879     (gnus-message 6 "%s to %s: %s..."
9880                   (caddr (assq action names))
9881                   (or (car select-method)
9882                       (gnus-group-decoded-name to-newsgroup))
9883                   articles)
9884     (while articles
9885       (setq article (pop articles))
9886       ;; Set any marks that may have changed in the summary buffer.
9887       (when gnus-preserve-marks
9888         (gnus-summary-push-marks-to-backend article))
9889       (setq
9890        art-group
9891        (cond
9892         ;; Move the article.
9893         ((eq action 'move)
9894          ;; Remove this article from future suppression.
9895          (gnus-dup-unsuppress-article article)
9896          (let* ((from-method (gnus-find-method-for-group
9897                               gnus-newsgroup-name))
9898                 (to-method (or select-method
9899                                (gnus-find-method-for-group to-newsgroup)))
9900                 (move-is-internal (gnus-server-equal from-method to-method)))
9901            (gnus-request-move-article
9902             article                     ; Article to move
9903             gnus-newsgroup-name         ; From newsgroup
9904             (nth 1 (gnus-find-method-for-group
9905                     gnus-newsgroup-name)) ; Server
9906             (list 'gnus-request-accept-article
9907                   to-newsgroup (list 'quote select-method)
9908                   (not articles) t)     ; Accept form
9909             (not articles)              ; Only save nov last time
9910             (and move-is-internal
9911                  to-newsgroup           ; Not respooling
9912                                         ; Is this move internal?
9913                  (gnus-group-real-name to-newsgroup)))))
9914         ;; Copy the article.
9915         ((eq action 'copy)
9916          (with-current-buffer copy-buf
9917            (when (gnus-request-article-this-buffer article
9918                                                    gnus-newsgroup-name)
9919              (save-restriction
9920                (nnheader-narrow-to-headers)
9921                (dolist (hdr gnus-copy-article-ignored-headers)
9922                  (message-remove-header hdr t)))
9923              (gnus-request-accept-article
9924               to-newsgroup select-method (not articles) t))))
9925         ;; Crosspost the article.
9926         ((eq action 'crosspost)
9927          (let ((xref (message-tokenize-header
9928                       (mail-header-xref (gnus-summary-article-header
9929                                          article))
9930                       " ")))
9931            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9932                                   ":" (number-to-string article)))
9933            (unless xref
9934              (setq xref (list (system-name))))
9935            (setq new-xref
9936                  (concat
9937                   (mapconcat 'identity
9938                              (delete "Xref:" (delete new-xref xref))
9939                              " ")
9940                   " " new-xref))
9941            (with-current-buffer copy-buf
9942              ;; First put the article in the destination group.
9943              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9944              (when (consp (setq art-group
9945                                 (gnus-request-accept-article
9946                                  to-newsgroup select-method (not articles)
9947                                  t)))
9948                (setq new-xref (concat new-xref " " (car art-group)
9949                                       ":"
9950                                       (number-to-string (cdr art-group))))
9951                ;; Now we have the new Xrefs header, so we insert
9952                ;; it and replace the new article.
9953                (nnheader-replace-header "Xref" new-xref)
9954                (gnus-request-replace-article
9955                 (cdr art-group) to-newsgroup (current-buffer) t)
9956                art-group))))))
9957       (cond
9958        ((not art-group)
9959         (gnus-message 1 "Couldn't %s article %s: %s"
9960                       (cadr (assq action names)) article
9961                       (nnheader-get-report (car to-method))))
9962        ((eq art-group 'junk)
9963         (when (eq action 'move)
9964           (gnus-summary-mark-article article gnus-canceled-mark)
9965           (gnus-message 4 "Deleted article %s" article)
9966           ;; run the delete hook
9967           (run-hook-with-args 'gnus-summary-article-delete-hook
9968                               action
9969                               (gnus-data-header
9970                                (assoc article (gnus-data-list nil)))
9971                               gnus-newsgroup-name nil
9972                               select-method)))
9973        (t
9974         (let* ((pto-group (gnus-group-prefixed-name
9975                            (car art-group) to-method))
9976                (info (gnus-get-info pto-group))
9977                (to-group (gnus-info-group info))
9978                to-marks)
9979           ;; Update the group that has been moved to.
9980           (when (and info
9981                      (memq action '(move copy)))
9982             (unless (member to-group to-groups)
9983               (push to-group to-groups))
9984
9985             (when (and (not (memq article gnus-newsgroup-unreads))
9986                        (cdr art-group))
9987               (push 'read to-marks)
9988               (gnus-info-set-read
9989                info (gnus-add-to-range (gnus-info-read info)
9990                                        (list (cdr art-group)))))
9991
9992             ;; See whether the article is to be put in the cache.
9993             (let* ((expirable (gnus-group-auto-expirable-p to-group))
9994                    (marks (if expirable
9995                               gnus-article-mark-lists
9996                             (delete '(expirable . expire)
9997                                     (copy-sequence
9998                                      gnus-article-mark-lists))))
9999                    (to-article (cdr art-group)))
10000
10001               ;; Enter the article into the cache in the new group,
10002               ;; if that is required.
10003               (when (and to-article
10004                          gnus-use-cache)
10005                 (gnus-cache-possibly-enter-article
10006                  to-group to-article
10007                  (memq article gnus-newsgroup-marked)
10008                  (memq article gnus-newsgroup-dormant)
10009                  (memq article gnus-newsgroup-unreads)))
10010
10011               (when (and gnus-preserve-marks
10012                          to-article)
10013                 ;; Copy any marks over to the new group.
10014                 (when (and (equal to-group gnus-newsgroup-name)
10015                            (not (memq article gnus-newsgroup-unreads)))
10016                   ;; Mark this article as read in this group.
10017                   (push (cons to-article gnus-read-mark)
10018                         gnus-newsgroup-reads)
10019                   ;; Increase the active status of this group.
10020                   (setcdr (gnus-active to-group) to-article)
10021                   (setcdr gnus-newsgroup-active to-article))
10022
10023                 (while marks
10024                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10025                     (when (memq article (symbol-value
10026                                          (intern (format "gnus-newsgroup-%s"
10027                                                          (caar marks)))))
10028                       (push (cdar marks) to-marks)
10029                       ;; If the other group is the same as this group,
10030                       ;; then we have to add the mark to the list.
10031                       (when (equal to-group gnus-newsgroup-name)
10032                         (set (intern (format "gnus-newsgroup-%s"
10033                                              (caar marks)))
10034                              (cons to-article
10035                                    (symbol-value
10036                                     (intern (format "gnus-newsgroup-%s"
10037                                                     (caar marks)))))))
10038                       ;; Copy the marks to other group.
10039                       (gnus-add-marked-articles
10040                        to-group (cdar marks) (list to-article) info)))
10041                   (setq marks (cdr marks)))
10042
10043                 (when (and expirable
10044                            gnus-mark-copied-or-moved-articles-as-expirable
10045                            (not (memq 'expire to-marks)))
10046                   ;; Mark this article as expirable.
10047                   (push 'expire to-marks)
10048                   (when (equal to-group gnus-newsgroup-name)
10049                     (push to-article gnus-newsgroup-expirable))
10050                   ;; Copy the expirable mark to other group.
10051                   (gnus-add-marked-articles
10052                    to-group 'expire (list to-article) info))
10053
10054                 (when to-marks
10055                   (gnus-request-set-mark
10056                    to-group (list (list (list to-article) 'add to-marks)))))
10057
10058               (gnus-dribble-enter
10059                (concat "(gnus-group-set-info '"
10060                        (gnus-prin1-to-string (gnus-get-info to-group))
10061                        ")")
10062                (concat "^(gnus-group-set-info '(\""
10063                        (regexp-quote to-group) "\""))))
10064
10065           ;; Update the Xref header in this article to point to
10066           ;; the new crossposted article we have just created.
10067           (when (eq action 'crosspost)
10068             (with-current-buffer copy-buf
10069               (gnus-request-article-this-buffer article gnus-newsgroup-name)
10070               (nnheader-replace-header "Xref" new-xref)
10071               (gnus-request-replace-article
10072                article gnus-newsgroup-name (current-buffer) t)))
10073
10074           ;; run the move/copy/crosspost/respool hook
10075           (run-hook-with-args 'gnus-summary-article-move-hook
10076                               action
10077                               (gnus-data-header
10078                                (assoc article (gnus-data-list nil)))
10079                               gnus-newsgroup-name
10080                               to-newsgroup
10081                               select-method))
10082
10083         ;;;!!!Why is this necessary?
10084         (set-buffer gnus-summary-buffer)
10085
10086         (when (eq action 'move)
10087           (save-excursion
10088             (gnus-summary-goto-subject article)
10089             (gnus-summary-mark-article article gnus-canceled-mark)))))
10090       (push article articles-to-update-marks))
10091
10092     (save-excursion
10093       (apply 'gnus-summary-remove-process-mark articles-to-update-marks))
10094     ;; Re-activate all groups that have been moved to.
10095     (with-current-buffer gnus-group-buffer
10096       (let ((gnus-group-marked to-groups))
10097         (gnus-group-get-new-news-this-group nil t)))
10098
10099     (gnus-kill-buffer copy-buf)
10100     (gnus-summary-position-point)
10101     (gnus-set-mode-line 'summary)))
10102
10103 (defun gnus-summary-push-marks-to-backend (article)
10104   (let ((set nil)
10105         (marks gnus-article-mark-lists))
10106     (unless (memq article gnus-newsgroup-unreads)
10107       (push 'read set))
10108     (while marks
10109       (when (and (eq (gnus-article-mark-to-type (cdar marks)) 'list)
10110                  (memq article (symbol-value
10111                                 (intern (format "gnus-newsgroup-%s"
10112                                                 (caar marks))))))
10113         (push (cdar marks) set))
10114       (pop marks))
10115     (gnus-request-set-mark gnus-newsgroup-name `(((,article) set ,set)))))
10116
10117 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
10118   "Copy the current article to some other group.
10119 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
10120 When called interactively, if TO-NEWSGROUP is nil, use the value of
10121 the variable `gnus-move-split-methods' for finding a default target
10122 newsgroup.
10123 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
10124 re-spool using this method."
10125   (interactive "P")
10126   (gnus-summary-move-article n to-newsgroup select-method 'copy))
10127
10128 (defun gnus-summary-crosspost-article (&optional n)
10129   "Crosspost the current article to some other group."
10130   (interactive "P")
10131   (gnus-summary-move-article n nil nil 'crosspost))
10132
10133 (defcustom gnus-summary-respool-default-method nil
10134   "Default method type for respooling an article.
10135 If nil, use to the current newsgroup method."
10136   :type 'symbol
10137   :group 'gnus-summary-mail)
10138
10139 (defun gnus-summary-respool-article (&optional n method)
10140   "Respool the current article.
10141 The article will be squeezed through the mail spooling process again,
10142 which means that it will be put in some mail newsgroup or other
10143 depending on `nnmail-split-methods'.
10144 If N is a positive number, respool the N next articles.
10145 If N is a negative number, respool the N previous articles.
10146 If N is nil and any articles have been marked with the process mark,
10147 respool those articles instead.
10148
10149 Respooling can be done both from mail groups and \"real\" newsgroups.
10150 In the former case, the articles in question will be moved from the
10151 current group into whatever groups they are destined to.  In the
10152 latter case, they will be copied into the relevant groups."
10153   (interactive
10154    (list current-prefix-arg
10155          (let* ((methods (mapcar #'car (gnus-methods-using 'respool)))
10156                 (methname
10157                  (symbol-name (or gnus-summary-respool-default-method
10158                                   (car (gnus-find-method-for-group
10159                                         gnus-newsgroup-name)))))
10160                 (method
10161                  (gnus-completing-read
10162                   "Backend to use when respooling"
10163                   methods t nil 'gnus-mail-method-history methname))
10164                 ms)
10165            (cond
10166             ((zerop (length (setq ms (gnus-servers-using-backend
10167                                       (intern method)))))
10168              (list (intern method) ""))
10169             ((= 1 (length ms))
10170              (car ms))
10171             (t
10172              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
10173                (cdr (assoc (gnus-completing-read "Server name" ms-alist t)
10174                            ms-alist))))))))
10175   (unless method
10176     (error "No method given for respooling"))
10177   (if (assoc (symbol-name
10178               (car (gnus-find-method-for-group gnus-newsgroup-name)))
10179              (gnus-methods-using 'respool))
10180       (gnus-summary-move-article n nil method)
10181     (gnus-summary-copy-article n nil method)))
10182
10183 (defun gnus-summary-import-article (file &optional edit)
10184   "Import an arbitrary file into a mail newsgroup."
10185   (interactive "fImport file: \nP")
10186   (let ((group gnus-newsgroup-name)
10187         (now (current-time))
10188         atts lines group-art)
10189     (unless (gnus-check-backend-function 'request-accept-article group)
10190       (error "%s does not support article importing" group))
10191     (or (file-readable-p file)
10192         (not (file-regular-p file))
10193         (error "Can't read %s" file))
10194     (with-current-buffer (gnus-get-buffer-create " *import file*")
10195       (erase-buffer)
10196       (nnheader-insert-file-contents file)
10197       (goto-char (point-min))
10198       (if (nnheader-article-p)
10199           (save-restriction
10200             (goto-char (point-min))
10201             (search-forward "\n\n" nil t)
10202             (narrow-to-region (point-min) (1- (point)))
10203             (goto-char (point-min))
10204             (unless (re-search-forward "^date:" nil t)
10205               (goto-char (point-max))
10206               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
10207        ;; This doesn't look like an article, so we fudge some headers.
10208         (setq atts (file-attributes file)
10209               lines (count-lines (point-min) (point-max)))
10210         (insert "From: " (read-string "From: ") "\n"
10211                 "Subject: " (read-string "Subject: ") "\n"
10212                 "Date: " (message-make-date (nth 5 atts)) "\n"
10213                 "Message-ID: " (message-make-message-id) "\n"
10214                 "Lines: " (int-to-string lines) "\n"
10215                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
10216       (setq group-art (gnus-request-accept-article group nil t))
10217       (kill-buffer (current-buffer)))
10218     (setq gnus-newsgroup-active (gnus-activate-group group))
10219     (forward-line 1)
10220     (gnus-summary-goto-article (cdr group-art) nil t)
10221     (when edit
10222       (gnus-summary-edit-article))))
10223
10224 (defun gnus-summary-create-article ()
10225   "Create an article in a mail newsgroup."
10226   (interactive)
10227   (let ((group gnus-newsgroup-name)
10228         (now (current-time))
10229         group-art)
10230     (unless (gnus-check-backend-function 'request-accept-article group)
10231       (error "%s does not support article importing" group))
10232     (with-current-buffer (gnus-get-buffer-create " *import file*")
10233       (erase-buffer)
10234       (goto-char (point-min))
10235       ;; This doesn't look like an article, so we fudge some headers.
10236       (insert "From: " (read-string "From: ") "\n"
10237               "Subject: " (read-string "Subject: ") "\n"
10238               "Date: " (message-make-date now) "\n"
10239               "Message-ID: " (message-make-message-id) "\n")
10240       (setq group-art (gnus-request-accept-article group nil t))
10241       (kill-buffer (current-buffer)))
10242     (setq gnus-newsgroup-active (gnus-activate-group group))
10243     (forward-line 1)
10244     (gnus-summary-goto-article (cdr group-art) nil t)
10245     (gnus-summary-edit-article)))
10246
10247 (defun gnus-summary-article-posted-p ()
10248   "Say whether the current (mail) article is available from news as well.
10249 This will be the case if the article has both been mailed and posted."
10250   (interactive)
10251   (let ((id (mail-header-references (gnus-summary-article-header)))
10252         (gnus-override-method (car (gnus-refer-article-methods))))
10253     (if (gnus-request-head id "")
10254         (gnus-message 2 "The current message was found on %s"
10255                       gnus-override-method)
10256       (gnus-message 2 "The current message couldn't be found on %s"
10257                     gnus-override-method)
10258       nil)))
10259
10260 (defun gnus-summary-expire-articles (&optional now)
10261   "Expire all articles that are marked as expirable in the current group."
10262   (interactive)
10263   (when (and (not gnus-group-is-exiting-without-update-p)
10264              (gnus-check-backend-function
10265               'request-expire-articles gnus-newsgroup-name))
10266     ;; This backend supports expiry.
10267     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
10268            (expirable (if total
10269                           (progn
10270                             ;; We need to update the info for
10271                             ;; this group for `gnus-list-of-read-articles'
10272                             ;; to give us the right answer.
10273                             (gnus-run-hooks 'gnus-exit-group-hook)
10274                             (gnus-summary-update-info)
10275                             (gnus-list-of-read-articles gnus-newsgroup-name))
10276                         (setq gnus-newsgroup-expirable
10277                               (sort gnus-newsgroup-expirable '<))))
10278            (expiry-wait (if now 'immediate
10279                           (gnus-group-find-parameter
10280                            gnus-newsgroup-name 'expiry-wait)))
10281            (nnmail-expiry-target
10282             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
10283                 nnmail-expiry-target))
10284            es)
10285       (when expirable
10286         ;; There are expirable articles in this group, so we run them
10287         ;; through the expiry process.
10288         (gnus-message 6 "Expiring articles...")
10289         (unless (gnus-check-group gnus-newsgroup-name)
10290           (error "Can't open server for %s" gnus-newsgroup-name))
10291         ;; The list of articles that weren't expired is returned.
10292         (save-excursion
10293           (if expiry-wait
10294               (let ((nnmail-expiry-wait-function nil)
10295                     (nnmail-expiry-wait expiry-wait))
10296                 (setq es (gnus-request-expire-articles
10297                           expirable gnus-newsgroup-name)))
10298             (setq es (gnus-request-expire-articles
10299                       expirable gnus-newsgroup-name)))
10300           (unless total
10301             (setq gnus-newsgroup-expirable es))
10302           ;; We go through the old list of expirable, and mark all
10303           ;; really expired articles as nonexistent.
10304           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10305             (let ((gnus-use-cache nil))
10306               (dolist (article expirable)
10307                 (when (and (not (memq article es))
10308                            (gnus-data-find article))
10309                   (gnus-summary-mark-article article gnus-canceled-mark)
10310                   (run-hook-with-args 'gnus-summary-article-expire-hook
10311                                       'delete
10312                                       (gnus-data-header
10313                                        (assoc article (gnus-data-list nil)))
10314                                       gnus-newsgroup-name
10315                                       nil
10316                                       nil))))))
10317         (gnus-message 6 "Expiring articles...done")))))
10318
10319 (defun gnus-summary-expire-articles-now ()
10320   "Expunge all expirable articles in the current group.
10321 This means that *all* articles that are marked as expirable will be
10322 deleted forever, right now."
10323   (interactive)
10324   (or gnus-expert-user
10325       (gnus-yes-or-no-p
10326        "Are you really, really sure you want to delete all expirable messages? ")
10327       (error "Phew!"))
10328   (gnus-summary-expire-articles t))
10329
10330 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10331 (defun gnus-summary-delete-article (&optional n)
10332   "Delete the N next (mail) articles.
10333 This command actually deletes articles.  This is not a marking
10334 command.  The article will disappear forever from your life, never to
10335 return.
10336
10337 If N is negative, delete backwards.
10338 If N is nil and articles have been marked with the process mark,
10339 delete these instead.
10340
10341 If `gnus-novice-user' is non-nil you will be asked for
10342 confirmation before the articles are deleted."
10343   (interactive "P")
10344   (unless (gnus-check-backend-function 'request-expire-articles
10345                                        gnus-newsgroup-name)
10346     (error "The current newsgroup does not support article deletion"))
10347   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10348     (error "Couldn't open server"))
10349   ;; Compute the list of articles to delete.
10350   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10351         (nnmail-expiry-target 'delete)
10352         not-deleted)
10353     (if (and gnus-novice-user
10354              (not (gnus-yes-or-no-p
10355                    (format "Do you really want to delete %s forever? "
10356                            (if (> (length articles) 1)
10357                                (format "these %s articles" (length articles))
10358                              "this article")))))
10359         ()
10360       ;; Delete the articles.
10361       (setq not-deleted (gnus-request-expire-articles
10362                          articles gnus-newsgroup-name 'force))
10363       (save-excursion
10364         (while articles
10365           (gnus-summary-remove-process-mark (car articles))
10366           ;; The backend might not have been able to delete the article
10367           ;; after all.
10368           (unless (memq (car articles) not-deleted)
10369             (gnus-summary-mark-article (car articles) gnus-canceled-mark)
10370             (let* ((article (car articles))
10371                    (ghead  (gnus-data-header
10372                             (assoc article (gnus-data-list nil)))))
10373               (run-hook-with-args 'gnus-summary-article-delete-hook
10374                                   'delete ghead gnus-newsgroup-name nil
10375                                   nil)))
10376           (setq articles (cdr articles))))
10377       (when not-deleted
10378         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10379     (gnus-summary-position-point)
10380     (gnus-set-mode-line 'summary)
10381     not-deleted))
10382
10383 (defun gnus-summary-edit-article (&optional arg)
10384   "Edit the current article.
10385 This will have permanent effect only in mail groups.
10386 If ARG is nil, edit the decoded articles.
10387 If ARG is 1, edit the raw articles.
10388 If ARG is 2, edit the raw articles even in read-only groups.
10389 If ARG is 3, edit the articles with the current handles.
10390 Otherwise, allow editing of articles even in read-only
10391 groups."
10392   (interactive "P")
10393   (let (force raw current-handles)
10394     (cond
10395      ((null arg))
10396      ((eq arg 1)
10397       (setq raw t))
10398      ((eq arg 2)
10399       (setq raw t
10400             force t))
10401      ((eq arg 3)
10402       (setq current-handles
10403             (and (gnus-buffer-live-p gnus-article-buffer)
10404                  (with-current-buffer gnus-article-buffer
10405                    (prog1
10406                        gnus-article-mime-handles
10407                      (setq gnus-article-mime-handles nil))))))
10408      (t
10409       (setq force t)))
10410     (when (and raw (not force)
10411                (member gnus-newsgroup-name '("nndraft:delayed"
10412                                              "nndraft:drafts"
10413                                              "nndraft:queue")))
10414       (error "Can't edit the raw article in group %s"
10415              gnus-newsgroup-name))
10416     (with-current-buffer gnus-summary-buffer
10417       (let ((mail-parse-charset gnus-newsgroup-charset)
10418             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10419         (gnus-set-global-variables)
10420         (when (and (not force)
10421                    (gnus-group-read-only-p))
10422           (error "The current newsgroup does not support article editing"))
10423         (gnus-summary-show-article t)
10424         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10425           (with-current-buffer gnus-article-buffer
10426             (mm-enable-multibyte)))
10427         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10428             (setq raw t))
10429         (gnus-article-edit-article
10430          (if raw 'ignore
10431            `(lambda ()
10432               (let ((mbl mml-buffer-list))
10433                 (setq mml-buffer-list nil)
10434                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10435                   (mime-to-mml ,'current-handles))
10436                 (let ((mbl1 mml-buffer-list))
10437                   (setq mml-buffer-list mbl)
10438                   (set (make-local-variable 'mml-buffer-list) mbl1))
10439                 (gnus-make-local-hook 'kill-buffer-hook)
10440                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10441          `(lambda (no-highlight)
10442             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10443                   (message-options message-options)
10444                   (message-options-set-recipient)
10445                   (mail-parse-ignored-charsets
10446                    ',gnus-newsgroup-ignored-charsets)
10447                   (rfc2047-header-encoding-alist
10448                    ',(let ((charset (gnus-group-name-charset
10449                                      (gnus-find-method-for-group
10450                                       gnus-newsgroup-name)
10451                                      gnus-newsgroup-name)))
10452                        (append (list (cons "Newsgroups" charset)
10453                                      (cons "Followup-To" charset)
10454                                      (cons "Xref" charset))
10455                                rfc2047-header-encoding-alist))))
10456               ,(if (not raw) '(progn
10457                                 (mml-to-mime)
10458                                 (mml-destroy-buffers)
10459                                 (remove-hook 'kill-buffer-hook
10460                                              'mml-destroy-buffers t)
10461                                 (kill-local-variable 'mml-buffer-list)))
10462               (gnus-summary-edit-article-done
10463                ,(or (mail-header-references gnus-current-headers) "")
10464                ,(gnus-group-read-only-p)
10465                ,gnus-summary-buffer no-highlight))))))))
10466
10467 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10468
10469 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10470                                                  no-highlight)
10471   "Make edits to the current article permanent."
10472   (interactive)
10473   (save-excursion
10474     ;; The buffer restriction contains the entire article if it exists.
10475     (when (article-goto-body)
10476       (let ((lines (count-lines (point) (point-max)))
10477             (length (- (point-max) (point)))
10478             (case-fold-search t)
10479             (body (copy-marker (point))))
10480         (goto-char (point-min))
10481         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10482           (delete-region (match-beginning 1) (match-end 1))
10483           (insert (number-to-string length)))
10484         (goto-char (point-min))
10485         (when (re-search-forward
10486                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10487           (delete-region (match-beginning 1) (match-end 1))
10488           (insert (number-to-string length)))
10489         (goto-char (point-min))
10490         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10491           (delete-region (match-beginning 1) (match-end 1))
10492           (insert (number-to-string lines))))))
10493   ;; Replace the article.
10494   (let ((buf (current-buffer))
10495         (article (cdr gnus-article-current))
10496         replace-result)
10497     (with-temp-buffer
10498       (insert-buffer-substring buf)
10499       (if (and (not read-only)
10500                (not (setq replace-result
10501                           (gnus-request-replace-article
10502                            article (car gnus-article-current)
10503                            (current-buffer) t))))
10504           (error "Couldn't replace article")
10505         ;; If we got a number back, then that's the new article number
10506         ;; for this article.  Otherwise, the article number didn't change.
10507         (when (numberp replace-result)
10508           (with-current-buffer gnus-summary-buffer
10509             (setq gnus-newsgroup-limit (delq article gnus-newsgroup-limit))
10510             (gnus-summary-limit gnus-newsgroup-limit)
10511             (setq article replace-result)
10512             (gnus-summary-goto-subject article t)))
10513         ;; Update the summary buffer.
10514         (if (and references
10515                  (equal (message-tokenize-header references " ")
10516                         (message-tokenize-header
10517                          (or (message-fetch-field "references") "") " ")))
10518             ;; We only have to update this line.
10519             (save-excursion
10520               (save-restriction
10521                 (message-narrow-to-head)
10522                 (let ((head (buffer-substring-no-properties
10523                              (point-min) (point-max)))
10524                       header)
10525                   (with-temp-buffer
10526                     (insert (format "211 %d Article retrieved.\n" article))
10527                     (insert head)
10528                     (insert ".\n")
10529                     (let ((nntp-server-buffer (current-buffer)))
10530                       (setq header (car (gnus-get-newsgroup-headers nil t))))
10531                     (with-current-buffer gnus-summary-buffer
10532                       (gnus-data-set-header (gnus-data-find article) header)
10533                       (gnus-summary-update-article-line article header)
10534                       (if (gnus-summary-goto-subject article nil t)
10535                           (gnus-summary-update-secondary-mark article)))))))
10536           ;; Update threads.
10537           (set-buffer (or buffer gnus-summary-buffer))
10538           (gnus-summary-update-article article)
10539           (if (gnus-summary-goto-subject article nil t)
10540               (gnus-summary-update-secondary-mark article)))
10541         ;; Prettify the article buffer again.
10542         (unless no-highlight
10543           (with-current-buffer gnus-article-buffer
10544             ;;!!! Fix this -- article should be rehighlighted.
10545             ;;(gnus-run-hooks 'gnus-article-display-hook)
10546             (set-buffer gnus-original-article-buffer)
10547             (gnus-request-article
10548              article (car gnus-article-current) (current-buffer))))
10549         ;; Prettify the summary buffer line.
10550         (when (gnus-visual-p 'summary-highlight 'highlight)
10551           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10552
10553 (defun gnus-summary-edit-wash (key)
10554   "Perform editing command KEY in the article buffer."
10555   (interactive
10556    (list
10557     (progn
10558       (message "%s" (concat (this-command-keys) "- "))
10559       (read-char))))
10560   (message "")
10561   (gnus-summary-edit-article)
10562   (execute-kbd-macro (concat (this-command-keys) key))
10563   (gnus-article-edit-done))
10564
10565 ;;; Respooling
10566
10567 (defun gnus-summary-respool-query (&optional silent trace)
10568   "Query where the respool algorithm would put this article."
10569   (interactive)
10570   (let (gnus-mark-article-hook)
10571     (gnus-summary-select-article)
10572     (with-current-buffer gnus-original-article-buffer
10573       (let ((groups (nnmail-article-group 'identity trace)))
10574         (unless silent
10575           (if groups
10576               (message "This message would go to %s"
10577                        (mapconcat 'car groups ", "))
10578             (message "This message would go to no groups"))
10579           groups)))))
10580
10581 (defun gnus-summary-respool-trace ()
10582   "Trace where the respool algorithm would put this article.
10583 Display a buffer showing all fancy splitting patterns which matched."
10584   (interactive)
10585   (gnus-summary-respool-query nil t))
10586
10587 ;; Summary marking commands.
10588
10589 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10590   "Mark articles which has the same subject as read, and then select the next.
10591 If UNMARK is positive, remove any kind of mark.
10592 If UNMARK is negative, tick articles."
10593   (interactive "P")
10594   (when unmark
10595     (setq unmark (prefix-numeric-value unmark)))
10596   (let ((count
10597          (gnus-summary-mark-same-subject
10598           (gnus-summary-article-subject) unmark)))
10599     ;; Select next unread article.  If auto-select-same mode, should
10600     ;; select the first unread article.
10601     (gnus-summary-next-article t (and gnus-auto-select-same
10602                                       (gnus-summary-article-subject)))
10603     (gnus-message 7 "%d article%s marked as %s"
10604                   count (if (= count 1) " is" "s are")
10605                   (if unmark "unread" "read"))))
10606
10607 (defun gnus-summary-kill-same-subject (&optional unmark)
10608   "Mark articles which has the same subject as read.
10609 If UNMARK is positive, remove any kind of mark.
10610 If UNMARK is negative, tick articles."
10611   (interactive "P")
10612   (when unmark
10613     (setq unmark (prefix-numeric-value unmark)))
10614   (let ((count
10615          (gnus-summary-mark-same-subject
10616           (gnus-summary-article-subject) unmark)))
10617     ;; If marked as read, go to next unread subject.
10618     (when (null unmark)
10619       ;; Go to next unread subject.
10620       (gnus-summary-next-subject 1 t))
10621     (gnus-message 7 "%d articles are marked as %s"
10622                   count (if unmark "unread" "read"))))
10623
10624 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10625   "Mark articles with same SUBJECT as read, and return marked number.
10626 If optional argument UNMARK is positive, remove any kinds of marks.
10627 If optional argument UNMARK is negative, mark articles as unread instead."
10628   (let ((count 1))
10629     (save-excursion
10630       (cond
10631        ((null unmark)                   ; Mark as read.
10632         (while (and
10633                 (progn
10634                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10635                   (gnus-summary-show-thread) t)
10636                 (gnus-summary-find-subject subject))
10637           (setq count (1+ count))))
10638        ((> unmark 0)                    ; Tick.
10639         (while (and
10640                 (progn
10641                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10642                   (gnus-summary-show-thread) t)
10643                 (gnus-summary-find-subject subject))
10644           (setq count (1+ count))))
10645        (t                               ; Mark as unread.
10646         (while (and
10647                 (progn
10648                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10649                   (gnus-summary-show-thread) t)
10650                 (gnus-summary-find-subject subject))
10651           (setq count (1+ count)))))
10652       (gnus-set-mode-line 'summary)
10653       ;; Return the number of marked articles.
10654       count)))
10655
10656 (defun gnus-summary-mark-as-processable (n &optional unmark)
10657   "Set the process mark on the next N articles.
10658 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10659 the process mark instead.  The difference between N and the actual
10660 number of articles marked is returned."
10661   (interactive "P")
10662   (if (and (null n) (gnus-region-active-p))
10663       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10664     (setq n (prefix-numeric-value n))
10665     (let ((backward (< n 0))
10666           (n (abs n)))
10667       (while (and
10668               (> n 0)
10669               (if unmark
10670                   (gnus-summary-remove-process-mark
10671                    (gnus-summary-article-number))
10672                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10673               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10674         (setq n (1- n)))
10675       (when (/= 0 n)
10676         (gnus-message 7 "No more articles"))
10677       (gnus-summary-recenter)
10678       (gnus-summary-position-point)
10679       n)))
10680
10681 (defun gnus-summary-unmark-as-processable (n)
10682   "Remove the process mark from the next N articles.
10683 If N is negative, unmark backward instead.  The difference between N and
10684 the actual number of articles unmarked is returned."
10685   (interactive "P")
10686   (gnus-summary-mark-as-processable n t))
10687
10688 (defun gnus-summary-unmark-all-processable ()
10689   "Remove the process mark from all articles."
10690   (interactive)
10691   (save-excursion
10692     (while gnus-newsgroup-processable
10693       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10694   (gnus-summary-position-point))
10695
10696 (defun gnus-summary-add-mark (article type)
10697   "Mark ARTICLE with a mark of TYPE."
10698   (let ((vtype (car (assq type gnus-article-mark-lists)))
10699         var)
10700     (if (not vtype)
10701         (error "No such mark type: %s" type)
10702       (setq var (intern (format "gnus-newsgroup-%s" type)))
10703       (set var (cons article (symbol-value var)))
10704       (if (memq type '(processable cached replied forwarded recent saved))
10705           (gnus-summary-update-secondary-mark article)
10706         ;;; !!! This is bogus.  We should find out what primary
10707         ;;; !!! mark we want to set.
10708         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10709
10710 (defun gnus-summary-mark-as-expirable (n)
10711   "Mark N articles forward as expirable.
10712 If N is negative, mark backward instead.  The difference between N and
10713 the actual number of articles marked is returned."
10714   (interactive "p")
10715   (gnus-summary-mark-forward n gnus-expirable-mark))
10716
10717 (defun gnus-summary-mark-as-spam (n)
10718   "Mark N articles forward as spam.
10719 If N is negative, mark backward instead.  The difference between N and
10720 the actual number of articles marked is returned."
10721   (interactive "p")
10722   (gnus-summary-mark-forward n gnus-spam-mark))
10723
10724 (defun gnus-summary-mark-article-as-replied (article)
10725   "Mark ARTICLE as replied to and update the summary line.
10726 ARTICLE can also be a list of articles."
10727   (interactive (list (gnus-summary-article-number)))
10728   (let ((articles (if (listp article) article (list article))))
10729     (dolist (article articles)
10730       (unless (numberp article)
10731         (error "%s is not a number" article))
10732       (push article gnus-newsgroup-replied)
10733       (let ((inhibit-read-only t))
10734         (when (gnus-summary-goto-subject article nil t)
10735           (gnus-summary-update-secondary-mark article))))))
10736
10737 (defun gnus-summary-mark-article-as-forwarded (article)
10738   "Mark ARTICLE as forwarded and update the summary line.
10739 ARTICLE can also be a list of articles."
10740   (let ((articles (if (listp article) article (list article))))
10741     (dolist (article articles)
10742       (push article gnus-newsgroup-forwarded)
10743       (let ((inhibit-read-only t))
10744         (when (gnus-summary-goto-subject article nil t)
10745           (gnus-summary-update-secondary-mark article))))))
10746
10747 (defun gnus-summary-set-bookmark (article)
10748   "Set a bookmark in current article."
10749   (interactive (list (gnus-summary-article-number)))
10750   (when (or (not (get-buffer gnus-article-buffer))
10751             (not gnus-current-article)
10752             (not gnus-article-current)
10753             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10754     (error "No current article selected"))
10755   ;; Remove old bookmark, if one exists.
10756   (gnus-alist-pull article gnus-newsgroup-bookmarks)
10757   ;; Set the new bookmark, which is on the form
10758   ;; (article-number . line-number-in-body).
10759   (push
10760    (cons article
10761          (with-current-buffer gnus-article-buffer
10762            (count-lines
10763             (min (point)
10764                  (save-excursion
10765                    (article-goto-body)
10766                    (point)))
10767             (point))))
10768    gnus-newsgroup-bookmarks)
10769   (gnus-message 6 "A bookmark has been added to the current article."))
10770
10771 (defun gnus-summary-remove-bookmark (article)
10772   "Remove the bookmark from the current article."
10773   (interactive (list (gnus-summary-article-number)))
10774   ;; Remove old bookmark, if one exists.
10775   (if (not (assq article gnus-newsgroup-bookmarks))
10776       (gnus-message 6 "No bookmark in current article.")
10777     (gnus-alist-pull article gnus-newsgroup-bookmarks)
10778     (gnus-message 6 "Removed bookmark.")))
10779
10780 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10781 (defun gnus-summary-mark-as-dormant (n)
10782   "Mark N articles forward as dormant.
10783 If N is negative, mark backward instead.  The difference between N and
10784 the actual number of articles marked is returned."
10785   (interactive "p")
10786   (gnus-summary-mark-forward n gnus-dormant-mark))
10787
10788 (defun gnus-summary-set-process-mark (article)
10789   "Set the process mark on ARTICLE and update the summary line."
10790   (setq gnus-newsgroup-processable
10791         (cons article
10792               (delq article gnus-newsgroup-processable)))
10793   (when (gnus-summary-goto-subject article)
10794     (gnus-summary-show-thread)
10795     (gnus-summary-goto-subject article)
10796     (gnus-summary-update-secondary-mark article)))
10797
10798 (defun gnus-summary-remove-process-mark (&rest articles)
10799   "Remove the process mark from ARTICLES and update the summary line."
10800   (dolist (article articles)
10801     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10802     (when (gnus-summary-goto-subject article)
10803       (gnus-summary-show-thread)
10804       (gnus-summary-goto-subject article)
10805       (gnus-summary-update-secondary-mark article)))
10806   t)
10807
10808 (defun gnus-summary-set-saved-mark (article)
10809   "Set the process mark on ARTICLE and update the summary line."
10810   (push article gnus-newsgroup-saved)
10811   (when (gnus-summary-goto-subject article)
10812     (gnus-summary-update-secondary-mark article)))
10813
10814 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10815   "Mark N articles as read forwards.
10816 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10817 The difference between N and the actual number of articles marked is
10818 returned.
10819 If NO-EXPIRE, auto-expiry will be inhibited."
10820   (interactive "p")
10821   (gnus-summary-show-thread)
10822   (let ((backward (< n 0))
10823         (gnus-summary-goto-unread
10824          (and gnus-summary-goto-unread
10825               (not (eq gnus-summary-goto-unread 'never))
10826               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10827                                     gnus-ticked-mark gnus-dormant-mark)))))
10828         (n (abs n))
10829         (mark (or mark gnus-del-mark)))
10830     (while (and (> n 0)
10831                 (gnus-summary-mark-article nil mark no-expire)
10832                 (zerop (gnus-summary-next-subject
10833                         (if backward -1 1)
10834                         (and gnus-summary-goto-unread
10835                              (not (eq gnus-summary-goto-unread 'never)))
10836                         t)))
10837       (setq n (1- n)))
10838     (when (/= 0 n)
10839       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10840     (gnus-summary-recenter)
10841     (gnus-summary-position-point)
10842     (gnus-set-mode-line 'summary)
10843     n))
10844
10845 (defun gnus-summary-mark-article-as-read (mark)
10846   "Mark the current article quickly as read with MARK."
10847   (let ((article (gnus-summary-article-number)))
10848     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10849     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10850     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10851     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10852     (push (cons article mark) gnus-newsgroup-reads)
10853     ;; Possibly remove from cache, if that is used.
10854     (when gnus-use-cache
10855       (gnus-cache-enter-remove-article article))
10856     ;; Allow the backend to change the mark.
10857     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10858     ;; Check for auto-expiry.
10859     (when (and gnus-newsgroup-auto-expire
10860                (memq mark gnus-auto-expirable-marks))
10861       (setq mark gnus-expirable-mark)
10862       ;; Let the backend know about the mark change.
10863       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10864       (push article gnus-newsgroup-expirable))
10865     ;; Set the mark in the buffer.
10866     (gnus-summary-update-mark mark 'unread)
10867     t))
10868
10869 (defun gnus-summary-mark-article-as-unread (mark)
10870   "Mark the current article quickly as unread with MARK."
10871   (let* ((article (gnus-summary-article-number))
10872          (old-mark (gnus-summary-article-mark article)))
10873     ;; Allow the backend to change the mark.
10874     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10875     (if (eq mark old-mark)
10876         t
10877       (if (<= article 0)
10878           (progn
10879             (gnus-error 1 "Can't mark negative article numbers")
10880             nil)
10881         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10882         (setq gnus-newsgroup-spam-marked
10883               (delq article gnus-newsgroup-spam-marked))
10884         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10885         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10886         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10887         (cond ((= mark gnus-ticked-mark)
10888                (setq gnus-newsgroup-marked
10889                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10890                                               article)))
10891               ((= mark gnus-spam-mark)
10892                (setq gnus-newsgroup-spam-marked
10893                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10894                                               article)))
10895               ((= mark gnus-dormant-mark)
10896                (setq gnus-newsgroup-dormant
10897                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10898                                               article)))
10899               (t
10900                (setq gnus-newsgroup-unreads
10901                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10902                                               article))))
10903         (gnus-alist-pull article gnus-newsgroup-reads)
10904
10905         ;; See whether the article is to be put in the cache.
10906         (and gnus-use-cache
10907              (vectorp (gnus-summary-article-header article))
10908              (save-excursion
10909                (gnus-cache-possibly-enter-article
10910                 gnus-newsgroup-name article
10911                 (= mark gnus-ticked-mark)
10912                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10913
10914         ;; Fix the mark.
10915         (gnus-summary-update-mark mark 'unread)
10916         t))))
10917
10918 (defun gnus-summary-mark-article (&optional article mark no-expire)
10919   "Mark ARTICLE with MARK.  MARK can be any character.
10920 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10921 `??' (dormant) and `?E' (expirable).
10922 If MARK is nil, then the default character `?r' is used.
10923 If ARTICLE is nil, then the article on the current line will be
10924 marked.
10925 If NO-EXPIRE, auto-expiry will be inhibited."
10926   ;; The mark might be a string.
10927   (when (stringp mark)
10928     (setq mark (aref mark 0)))
10929   ;; If no mark is given, then we check auto-expiring.
10930   (when (null mark)
10931     (setq mark gnus-del-mark))
10932   (when (and (not no-expire)
10933              gnus-newsgroup-auto-expire
10934              (memq mark gnus-auto-expirable-marks))
10935     (setq mark gnus-expirable-mark))
10936   (let ((article (or article (gnus-summary-article-number)))
10937         (old-mark (gnus-summary-article-mark article)))
10938     ;; Allow the backend to change the mark.
10939     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10940     (if (eq mark old-mark)
10941         t
10942       (unless article
10943         (error "No article on current line"))
10944       (if (not (if (or (= mark gnus-unread-mark)
10945                        (= mark gnus-ticked-mark)
10946                        (= mark gnus-spam-mark)
10947                        (= mark gnus-dormant-mark))
10948                    (gnus-mark-article-as-unread article mark)
10949                  (gnus-mark-article-as-read article mark)))
10950           t
10951         ;; See whether the article is to be put in the cache.
10952         (and gnus-use-cache
10953              (not (= mark gnus-canceled-mark))
10954              (vectorp (gnus-summary-article-header article))
10955              (save-excursion
10956                (gnus-cache-possibly-enter-article
10957                 gnus-newsgroup-name article
10958                 (= mark gnus-ticked-mark)
10959                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10960
10961         (when (gnus-summary-goto-subject article nil t)
10962           (let ((inhibit-read-only t))
10963             (gnus-summary-show-thread)
10964             ;; Fix the mark.
10965             (gnus-summary-update-mark mark 'unread)
10966             t))))))
10967
10968 (defun gnus-summary-update-secondary-mark (article)
10969   "Update the secondary (read, process, cache) mark."
10970   (gnus-summary-update-mark
10971    (cond ((memq article gnus-newsgroup-processable)
10972           gnus-process-mark)
10973          ((memq article gnus-newsgroup-cached)
10974           gnus-cached-mark)
10975          ((memq article gnus-newsgroup-replied)
10976           gnus-replied-mark)
10977          ((memq article gnus-newsgroup-forwarded)
10978           gnus-forwarded-mark)
10979          ((memq article gnus-newsgroup-saved)
10980           gnus-saved-mark)
10981          ((memq article gnus-newsgroup-recent)
10982           gnus-recent-mark)
10983          ((memq article gnus-newsgroup-unseen)
10984           gnus-unseen-mark)
10985          (t gnus-no-mark))
10986    'replied)
10987   (when (gnus-visual-p 'summary-highlight 'highlight)
10988     (gnus-summary-highlight-line)
10989     (gnus-run-hooks 'gnus-summary-update-hook))
10990   t)
10991
10992 (defun gnus-summary-update-download-mark (article)
10993   "Update the download mark."
10994   (gnus-summary-update-mark
10995    (cond ((memq article gnus-newsgroup-undownloaded)
10996           gnus-undownloaded-mark)
10997          (gnus-newsgroup-agentized
10998           gnus-downloaded-mark)
10999          (t
11000           gnus-no-mark))
11001    'download)
11002   (gnus-summary-update-line t)
11003   t)
11004
11005 (defun gnus-summary-update-mark (mark type)
11006   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
11007         (inhibit-read-only t))
11008     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
11009     (when forward
11010       (when (looking-at "\r")
11011         (incf forward))
11012       (when (<= (+ forward (point)) (point-max))
11013         ;; Go to the right position on the line.
11014         (goto-char (+ forward (point)))
11015         ;; Replace the old mark with the new mark.
11016         (let ((to-insert
11017                (mm-subst-char-in-string
11018                 (char-after) mark
11019                 (buffer-substring (point) (1+ (point))))))
11020           (delete-region (point) (1+ (point)))
11021           (insert to-insert))
11022         ;; Optionally update the marks by some user rule.
11023         (when (eq type 'unread)
11024           (gnus-data-set-mark
11025            (gnus-data-find (gnus-summary-article-number)) mark)
11026           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
11027
11028 (defun gnus-mark-article-as-read (article &optional mark)
11029   "Enter ARTICLE in the pertinent lists and remove it from others."
11030   ;; Make the article expirable.
11031   (let ((mark (or mark gnus-del-mark)))
11032     (setq gnus-newsgroup-expirable
11033           (if (= mark gnus-expirable-mark)
11034               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
11035             (delq article gnus-newsgroup-expirable)))
11036     ;; Remove from unread and marked lists.
11037     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11038     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
11039     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
11040     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
11041     (push (cons article mark) gnus-newsgroup-reads)
11042     ;; Possibly remove from cache, if that is used.
11043     (when gnus-use-cache
11044       (gnus-cache-enter-remove-article article))
11045     t))
11046
11047 (defun gnus-mark-article-as-unread (article &optional mark)
11048   "Enter ARTICLE in the pertinent lists and remove it from others."
11049   (let ((mark (or mark gnus-ticked-mark)))
11050     (if (<= article 0)
11051         (progn
11052           (gnus-error 1 "Can't mark negative article numbers")
11053           nil)
11054       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
11055             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
11056             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
11057             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
11058             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
11059
11060       ;; Unsuppress duplicates?
11061       (when gnus-suppress-duplicates
11062         (gnus-dup-unsuppress-article article))
11063
11064       (cond ((= mark gnus-ticked-mark)
11065              (setq gnus-newsgroup-marked
11066                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
11067             ((= mark gnus-spam-mark)
11068              (setq gnus-newsgroup-spam-marked
11069                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
11070                                             article)))
11071             ((= mark gnus-dormant-mark)
11072              (setq gnus-newsgroup-dormant
11073                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
11074             (t
11075              (setq gnus-newsgroup-unreads
11076                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
11077       (gnus-alist-pull article gnus-newsgroup-reads)
11078       t)))
11079
11080 (defun gnus-summary-tick-article-forward (n)
11081   "Tick N articles forwards.
11082 If N is negative, tick backwards instead.
11083 The difference between N and the number of articles ticked is returned."
11084   (interactive "p")
11085   (gnus-summary-mark-forward n gnus-ticked-mark))
11086
11087 (defun gnus-summary-tick-article-backward (n)
11088   "Tick N articles backwards.
11089 The difference between N and the number of articles ticked is returned."
11090   (interactive "p")
11091   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
11092
11093 (defun gnus-summary-tick-article (&optional article clear-mark)
11094   "Mark current article as unread.
11095 Optional 1st argument ARTICLE specifies article number to be marked as unread.
11096 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
11097   (interactive)
11098   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
11099                                        gnus-ticked-mark)))
11100
11101 (defun gnus-summary-mark-as-read-forward (n)
11102   "Mark N articles as read forwards.
11103 If N is negative, mark backwards instead.
11104 The difference between N and the actual number of articles marked is
11105 returned."
11106   (interactive "p")
11107   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
11108
11109 (defun gnus-summary-mark-as-read-backward (n)
11110   "Mark the N articles as read backwards.
11111 The difference between N and the actual number of articles marked is
11112 returned."
11113   (interactive "p")
11114   (gnus-summary-mark-forward
11115    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
11116
11117 (defun gnus-summary-mark-as-read (&optional article mark)
11118   "Mark current article as read.
11119 ARTICLE specifies the article to be marked as read.
11120 MARK specifies a string to be inserted at the beginning of the line."
11121   (gnus-summary-mark-article article mark))
11122
11123 (defun gnus-summary-clear-mark-forward (n)
11124   "Clear marks from N articles forward.
11125 If N is negative, clear backward instead.
11126 The difference between N and the number of marks cleared is returned."
11127   (interactive "p")
11128   (gnus-summary-mark-forward n gnus-unread-mark))
11129
11130 (defun gnus-summary-clear-mark-backward (n)
11131   "Clear marks from N articles backward.
11132 The difference between N and the number of marks cleared is returned."
11133   (interactive "p")
11134   (gnus-summary-mark-forward (- n) gnus-unread-mark))
11135
11136 (defun gnus-summary-mark-unread-as-read ()
11137   "Intended to be used by `gnus-mark-article-hook'."
11138   (when (memq gnus-current-article gnus-newsgroup-unreads)
11139     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
11140
11141 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
11142   "Intended to be used by `gnus-mark-article-hook'."
11143   (let ((mark (gnus-summary-article-mark)))
11144     (when (or (gnus-unread-mark-p mark)
11145               (gnus-read-mark-p mark))
11146       (gnus-summary-mark-article gnus-current-article
11147                                  (or new-mark gnus-read-mark)))))
11148
11149 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
11150   "Intended to be used by `gnus-mark-article-hook'."
11151   (let ((mark (gnus-summary-article-mark)))
11152     (when (or (gnus-unread-mark-p mark)
11153               (gnus-read-mark-p mark))
11154       (gnus-summary-mark-article (gnus-summary-article-number)
11155                                  (or new-mark gnus-read-mark)))))
11156
11157 (defun gnus-summary-mark-unread-as-ticked ()
11158   "Intended to be used by `gnus-mark-article-hook'."
11159   (when (memq gnus-current-article gnus-newsgroup-unreads)
11160     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
11161
11162 (defun gnus-summary-mark-region-as-read (point mark all)
11163   "Mark all unread articles between point and mark as read.
11164 If given a prefix, mark all articles between point and mark as read,
11165 even ticked and dormant ones."
11166   (interactive "r\nP")
11167   (save-excursion
11168     (let (article)
11169       (goto-char point)
11170       (beginning-of-line)
11171       (while (and
11172               (< (point) mark)
11173               (progn
11174                 (when (or all
11175                           (memq (setq article (gnus-summary-article-number))
11176                                 gnus-newsgroup-unreads))
11177                   (gnus-summary-mark-article article gnus-del-mark))
11178                 t)
11179               (gnus-summary-find-next))))))
11180
11181 (defun gnus-summary-mark-below (score mark)
11182   "Mark articles with score less than SCORE with MARK."
11183   (interactive "P\ncMark: ")
11184   (setq score (if score
11185                   (prefix-numeric-value score)
11186                 (or gnus-summary-default-score 0)))
11187   (with-current-buffer gnus-summary-buffer
11188     (goto-char (point-min))
11189     (while
11190         (progn
11191           (and (< (gnus-summary-article-score) score)
11192                (gnus-summary-mark-article nil mark))
11193           (gnus-summary-find-next)))))
11194
11195 (defun gnus-summary-kill-below (&optional score)
11196   "Mark articles with score below SCORE as read."
11197   (interactive "P")
11198   (gnus-summary-mark-below score gnus-killed-mark))
11199
11200 (defun gnus-summary-clear-above (&optional score)
11201   "Clear all marks from articles with score above SCORE."
11202   (interactive "P")
11203   (gnus-summary-mark-above score gnus-unread-mark))
11204
11205 (defun gnus-summary-tick-above (&optional score)
11206   "Tick all articles with score above SCORE."
11207   (interactive "P")
11208   (gnus-summary-mark-above score gnus-ticked-mark))
11209
11210 (defun gnus-summary-mark-above (score mark)
11211   "Mark articles with score over SCORE with MARK."
11212   (interactive "P\ncMark: ")
11213   (setq score (if score
11214                   (prefix-numeric-value score)
11215                 (or gnus-summary-default-score 0)))
11216   (with-current-buffer gnus-summary-buffer
11217     (goto-char (point-min))
11218     (while (and (progn
11219                   (when (> (gnus-summary-article-score) score)
11220                     (gnus-summary-mark-article nil mark))
11221                   t)
11222                 (gnus-summary-find-next)))))
11223
11224 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
11225 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
11226 (defun gnus-summary-limit-include-expunged (&optional no-error)
11227   "Display all the hidden articles that were expunged for low scores."
11228   (interactive)
11229   (let ((inhibit-read-only t))
11230     (let ((scored gnus-newsgroup-scored)
11231           headers h)
11232       (while scored
11233         (unless (gnus-summary-article-header (caar scored))
11234           (and (setq h (gnus-number-to-header (caar scored)))
11235                (< (cdar scored) gnus-summary-expunge-below)
11236                (push h headers)))
11237         (setq scored (cdr scored)))
11238       (if (not headers)
11239           (when (not no-error)
11240             (error "No expunged articles hidden"))
11241         (goto-char (point-min))
11242         (push gnus-newsgroup-limit gnus-newsgroup-limits)
11243         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
11244         (dolist (x headers)
11245           (push (mail-header-number x) gnus-newsgroup-limit))
11246         (gnus-summary-prepare-unthreaded (nreverse headers))
11247         (goto-char (point-min))
11248         (gnus-summary-position-point)
11249         t))))
11250
11251 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
11252   "Mark all unread articles in this newsgroup as read.
11253 If prefix argument ALL is non-nil, ticked and dormant articles will
11254 also be marked as read.
11255 If QUIETLY is non-nil, no questions will be asked.
11256
11257 If TO-HERE is non-nil, it should be a point in the buffer.  All
11258 articles before (after, if REVERSE is set) this point will be marked
11259 as read.
11260
11261 Note that this function will only catch up the unread article
11262 in the current summary buffer limitation.
11263
11264 The number of articles marked as read is returned."
11265   (interactive "P")
11266   (prog1
11267       (save-excursion
11268         (when (or quietly
11269                   (not gnus-interactive-catchup) ;Without confirmation?
11270                   gnus-expert-user
11271                   (gnus-y-or-n-p
11272                    (if all
11273                        "Mark absolutely all articles as read? "
11274                      "Mark all unread articles as read? ")))
11275           (if (and not-mark
11276                    (not gnus-newsgroup-adaptive)
11277                    (not gnus-newsgroup-auto-expire)
11278                    (not gnus-suppress-duplicates)
11279                    (or (not gnus-use-cache)
11280                        (eq gnus-use-cache 'passive)))
11281               (progn
11282                 (when all
11283                   (setq gnus-newsgroup-marked nil
11284                         gnus-newsgroup-spam-marked nil
11285                         gnus-newsgroup-dormant nil))
11286                 (setq gnus-newsgroup-unreads
11287                       (gnus-sorted-nunion
11288                        (gnus-sorted-intersection gnus-newsgroup-unreads
11289                                                  gnus-newsgroup-downloadable)
11290                        (gnus-sorted-difference gnus-newsgroup-unfetched
11291                                                gnus-newsgroup-cached))))
11292             ;; We actually mark all articles as canceled, which we
11293             ;; have to do when using auto-expiry or adaptive scoring.
11294             (gnus-summary-show-all-threads)
11295             (if (and to-here reverse)
11296                 (progn
11297                   (goto-char to-here)
11298                   (gnus-summary-mark-current-read-and-unread-as-read
11299                    gnus-catchup-mark)
11300                   (while (gnus-summary-find-next (not all))
11301                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11302               (when (gnus-summary-first-subject (not all))
11303                 (while (and
11304                         (if to-here (< (point) to-here) t)
11305                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11306                         (gnus-summary-find-next (not all))))))
11307             (gnus-set-mode-line 'summary))
11308           t))
11309     (gnus-summary-position-point)))
11310
11311 (defun gnus-summary-catchup-to-here (&optional all)
11312   "Mark all unticked articles before the current one as read.
11313 If ALL is non-nil, also mark ticked and dormant articles as read."
11314   (interactive "P")
11315   (save-excursion
11316     (gnus-save-hidden-threads
11317       (let ((beg (point)))
11318         ;; We check that there are unread articles.
11319         (when (or all (gnus-summary-find-prev))
11320           (gnus-summary-catchup all t beg)))))
11321   (gnus-summary-position-point))
11322
11323 (defun gnus-summary-catchup-from-here (&optional all)
11324   "Mark all unticked articles after (and including) the current one as read.
11325 If ALL is non-nil, also mark ticked and dormant articles as read."
11326   (interactive "P")
11327   (save-excursion
11328     (gnus-save-hidden-threads
11329       (let ((beg (point)))
11330         ;; We check that there are unread articles.
11331         (when (or all (gnus-summary-find-next))
11332           (gnus-summary-catchup all t beg nil t)))))
11333   (gnus-summary-position-point))
11334
11335 (defun gnus-summary-catchup-all (&optional quietly)
11336   "Mark all articles in this newsgroup as read.
11337 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11338 instead, which marks only unread articles as read."
11339   (interactive "P")
11340   (gnus-summary-catchup t quietly))
11341
11342 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11343   "Mark all unread articles in this group as read, then exit.
11344 If prefix argument ALL is non-nil, all articles are marked as read.
11345 If QUIETLY is non-nil, no questions will be asked."
11346   (interactive "P")
11347   (when (gnus-summary-catchup all quietly nil 'fast)
11348     ;; Select next newsgroup or exit.
11349     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11350              (eq gnus-auto-select-next 'quietly))
11351         (gnus-summary-next-group nil)
11352       (gnus-summary-exit))))
11353
11354 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11355   "Mark all articles in this newsgroup as read, and then exit.
11356 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11357 instead, which marks only unread articles as read."
11358   (interactive "P")
11359   (gnus-summary-catchup-and-exit t quietly))
11360
11361 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11362   "Mark all articles in this group as read and select the next group.
11363 If given a prefix, mark all articles, unread as well as ticked, as
11364 read."
11365   (interactive "P")
11366   (save-excursion
11367     (gnus-summary-catchup all))
11368   (gnus-summary-next-group))
11369
11370 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11371   "Mark all articles in this group as read and select the previous group.
11372 If given a prefix, mark all articles, unread as well as ticked, as
11373 read."
11374   (interactive "P")
11375   (save-excursion
11376     (gnus-summary-catchup all))
11377   (gnus-summary-next-group nil nil t))
11378
11379 ;;;
11380 ;;; with article
11381 ;;;
11382
11383 (defmacro gnus-with-article (article &rest forms)
11384   "Select ARTICLE and perform FORMS in the original article buffer.
11385 Then replace the article with the result."
11386   `(progn
11387      ;; We don't want the article to be marked as read.
11388      (let (gnus-mark-article-hook)
11389        (gnus-summary-select-article t t nil ,article))
11390      (set-buffer gnus-original-article-buffer)
11391      ,@forms
11392      (if (not (gnus-check-backend-function
11393                'request-replace-article (car gnus-article-current)))
11394          (gnus-message 5 "Read-only group; not replacing")
11395        (unless (gnus-request-replace-article
11396                 ,article (car gnus-article-current)
11397                 (current-buffer) t)
11398          (error "Couldn't replace article")))
11399      ;; The cache and backlog have to be flushed somewhat.
11400      (when gnus-keep-backlog
11401        (gnus-backlog-remove-article
11402         (car gnus-article-current) (cdr gnus-article-current)))
11403      (when gnus-use-cache
11404        (gnus-cache-update-article
11405         (car gnus-article-current) (cdr gnus-article-current)))))
11406
11407 (put 'gnus-with-article 'lisp-indent-function 1)
11408 (put 'gnus-with-article 'edebug-form-spec '(form body))
11409
11410 ;; Thread-based commands.
11411
11412 (defun gnus-summary-articles-in-thread (&optional article)
11413   "Return a list of all articles in the current thread.
11414 If ARTICLE is non-nil, return all articles in the thread that starts
11415 with that article."
11416   (let* ((article (or article (gnus-summary-article-number)))
11417          (data (gnus-data-find-list article))
11418          (top-level (gnus-data-level (car data)))
11419          (top-subject
11420           (cond ((null gnus-thread-operation-ignore-subject)
11421                  (gnus-simplify-subject-re
11422                   (mail-header-subject (gnus-data-header (car data)))))
11423                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11424                  (gnus-simplify-subject-fuzzy
11425                   (mail-header-subject (gnus-data-header (car data)))))
11426                 (t nil)))
11427          (end-point (save-excursion
11428                       (goto-char (gnus-data-pos (car data)))
11429                       (if (gnus-summary-go-to-next-thread)
11430                           (point) (point-max))))
11431          articles)
11432     (while (and data
11433                 (< (gnus-data-pos (car data)) end-point))
11434       (when (or (not top-subject)
11435                 (string= top-subject
11436                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11437                              (gnus-simplify-subject-fuzzy
11438                               (mail-header-subject
11439                                (gnus-data-header (car data))))
11440                            (gnus-simplify-subject-re
11441                             (mail-header-subject
11442                              (gnus-data-header (car data)))))))
11443         (push (gnus-data-number (car data)) articles))
11444       (unless (and (setq data (cdr data))
11445                    (> (gnus-data-level (car data)) top-level))
11446         (setq data nil)))
11447     ;; Return the list of articles.
11448     (nreverse articles)))
11449
11450 (defun gnus-summary-rethread-current ()
11451   "Rethread the thread the current article is part of."
11452   (interactive)
11453   (let* ((gnus-show-threads t)
11454          (article (gnus-summary-article-number))
11455          (id (mail-header-id (gnus-summary-article-header)))
11456          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11457     (unless id
11458       (error "No article on the current line"))
11459     (gnus-rebuild-thread id)
11460     (gnus-summary-goto-subject article)))
11461
11462 (defun gnus-summary-reparent-thread ()
11463   "Make the current article child of the marked (or previous) article.
11464
11465 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11466 is non-nil or the Subject: of both articles are the same."
11467   (interactive)
11468   (unless (not (gnus-group-read-only-p))
11469     (error "The current newsgroup does not support article editing"))
11470   (unless (<= (length gnus-newsgroup-processable) 1)
11471     (error "No more than one article may be marked"))
11472   (let ((child (gnus-summary-article-number))
11473         ;; First grab the marked article, otherwise one line up.
11474         (parent (if (not (null gnus-newsgroup-processable))
11475                     (car gnus-newsgroup-processable)
11476                   (save-excursion
11477                     (if (eq (forward-line -1) 0)
11478                         (gnus-summary-article-number)
11479                       (error "Beginning of summary buffer"))))))
11480     (gnus-summary-reparent-children parent (list child))))
11481
11482 (defun gnus-summary-reparent-children (parent children)
11483   "Make PARENT the parent of CHILDREN.
11484 When called interactively, PARENT is the current article and CHILDREN
11485 are the process-marked articles."
11486   (interactive
11487    (list (gnus-summary-article-number)
11488          (gnus-summary-work-articles nil)))
11489   (dolist (child children)
11490     (save-window-excursion
11491       (let ((gnus-article-buffer " *reparent*"))
11492         (unless (not (eq parent child))
11493           (error "An article may not be self-referential"))
11494         (let ((message-id (mail-header-id
11495                            (gnus-summary-article-header parent))))
11496           (unless (and message-id (not (equal message-id "")))
11497             (error "No message-id in desired parent"))
11498           (gnus-with-article child
11499             (save-restriction
11500               (goto-char (point-min))
11501               (message-narrow-to-head)
11502               (if (re-search-forward "^References: " nil t)
11503                   (progn
11504                     (re-search-forward "^[^ \t]" nil t)
11505                     (forward-line -1)
11506                     (end-of-line)
11507                     (insert " " message-id))
11508                 (insert "References: " message-id "\n"))))
11509           (set-buffer gnus-summary-buffer)
11510           (gnus-summary-unmark-all-processable)
11511           (gnus-summary-update-article child)
11512           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11513             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11514           (gnus-summary-rethread-current)
11515           (gnus-message 3 "Article %d is now the child of article %d"
11516                         child parent))))))
11517
11518 (defun gnus-summary-toggle-threads (&optional arg)
11519   "Toggle showing conversation threads.
11520 If ARG is positive number, turn showing conversation threads on."
11521   (interactive "P")
11522   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11523     (setq gnus-show-threads
11524           (if (null arg) (not gnus-show-threads)
11525             (> (prefix-numeric-value arg) 0)))
11526     (gnus-summary-prepare)
11527     (gnus-summary-goto-subject current)
11528     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11529     (gnus-summary-position-point)))
11530
11531 (eval-and-compile
11532   (if (fboundp 'remove-overlays)
11533       (defalias 'gnus-remove-overlays 'remove-overlays)
11534     (defun gnus-remove-overlays (beg end name val)
11535       "Clear BEG and END of overlays whose property NAME has value VAL.
11536 For compatibility with XEmacs."
11537       (dolist (ov (gnus-overlays-in beg end))
11538         (when (eq (gnus-overlay-get ov name) val)
11539           (gnus-delete-overlay ov))))))
11540
11541 (defun gnus-summary-show-all-threads ()
11542   "Show all threads."
11543   (interactive)
11544   (gnus-remove-overlays (point-min) (point-max) 'invisible 'gnus-sum)
11545   (gnus-summary-position-point))
11546
11547 (defsubst gnus-summary--inv (p)
11548   (and (eq (get-char-property p 'invisible) 'gnus-sum) p))
11549
11550 (defun gnus-summary-show-thread ()
11551   "Show thread subtrees.
11552 Returns nil if no thread was there to be shown."
11553   (interactive)
11554   (let* ((orig (point))
11555          (end (point-at-eol))
11556          (end (or (gnus-summary--inv end) (gnus-summary--inv (1- end))))
11557          ;; Leave point at bol
11558          (beg (progn (beginning-of-line) (if (bobp) (point) (1- (point)))))
11559          (eoi (when end
11560                 (if (fboundp 'next-single-char-property-change)
11561                     (or (next-single-char-property-change end 'invisible)
11562                         (point-max))
11563                   (while (progn
11564                            (end-of-line 2)
11565                            (and (not (eobp))
11566                                 (eq (get-char-property (point) 'invisible)
11567                                     'gnus-sum))))
11568                   (point)))))
11569     (when eoi
11570       (gnus-remove-overlays beg eoi 'invisible 'gnus-sum)
11571       (goto-char orig)
11572       (gnus-summary-position-point)
11573       eoi)))
11574
11575 (defun gnus-summary-maybe-hide-threads ()
11576   "If requested, hide the threads that should be hidden."
11577   (when (and gnus-show-threads
11578              gnus-thread-hide-subtree)
11579     (gnus-summary-hide-all-threads
11580      (if (or (consp gnus-thread-hide-subtree)
11581              (functionp gnus-thread-hide-subtree))
11582          (gnus-make-predicate gnus-thread-hide-subtree)
11583        nil))))
11584
11585 ;;; Hiding predicates.
11586
11587 (defun gnus-article-unread-p (header)
11588   (memq (mail-header-number header) gnus-newsgroup-unreads))
11589
11590 (defun gnus-article-unseen-p (header)
11591   (memq (mail-header-number header) gnus-newsgroup-unseen))
11592
11593 (defun gnus-map-articles (predicate articles)
11594   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11595   (apply 'gnus-or (mapcar predicate
11596                           (mapcar (lambda (number)
11597                                     (gnus-summary-article-header number))
11598                                   articles))))
11599
11600 (defun gnus-summary-hide-all-threads (&optional predicate)
11601   "Hide all thread subtrees.
11602 If PREDICATE is supplied, threads that satisfy this predicate
11603 will not be hidden."
11604   (interactive)
11605   (save-excursion
11606     (goto-char (point-min))
11607     (let ((end nil)
11608           (count 0))
11609       (while (not end)
11610         (incf count)
11611         (when (zerop (mod count 1000))
11612           (message "Hiding all threads... %d" count))
11613         (when (or (not predicate)
11614                   (gnus-map-articles
11615                    predicate (gnus-summary-article-children)))
11616             (gnus-summary-hide-thread))
11617         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11618   (gnus-summary-position-point))
11619
11620 (defun gnus-summary-hide-thread ()
11621   "Hide thread subtrees.
11622 If PREDICATE is supplied, threads that satisfy this predicate
11623 will not be hidden.
11624 Returns nil if no threads were there to be hidden."
11625   (interactive)
11626   (let ((start (point))
11627         (starteol (line-end-position))
11628         (article (gnus-summary-article-number)))
11629     (goto-char start)
11630     ;; Go forward until either the buffer ends or the subthread ends.
11631     (when (and (not (eobp))
11632                (or (zerop (gnus-summary-next-thread 1 t))
11633                    (goto-char (point-max))))
11634       (if (and (> (point) start)
11635                ;; FIXME: this should actually search for a non-invisible \n.
11636                (search-backward "\n" start t))
11637           (progn
11638             (when (> (point) starteol)
11639               (gnus-remove-overlays starteol (point) 'invisible 'gnus-sum)
11640               (let ((ol (gnus-make-overlay starteol (point) nil t nil)))
11641                 (gnus-overlay-put ol 'invisible 'gnus-sum)
11642                 (gnus-overlay-put ol 'evaporate t)))
11643             (gnus-summary-goto-subject article)
11644             (when (> start (point))
11645               (message "Hiding the thread moved us backwards, aborting!")
11646               (goto-char (point-max))))
11647         (goto-char start)
11648         nil))))
11649
11650 (defun gnus-summary-go-to-next-thread (&optional previous)
11651   "Go to the same level (or less) next thread.
11652 If PREVIOUS is non-nil, go to previous thread instead.
11653 Return the article number moved to, or nil if moving was impossible."
11654   (let ((level (gnus-summary-thread-level))
11655         (way (if previous -1 1))
11656         (beg (point)))
11657     (forward-line way)
11658     (while (and (not (eobp))
11659                 (< level (gnus-summary-thread-level)))
11660       (forward-line way))
11661     (if (eobp)
11662         (progn
11663           (goto-char beg)
11664           nil)
11665       (setq beg (point))
11666       (prog1
11667           (gnus-summary-article-number)
11668         (goto-char beg)))))
11669
11670 (defun gnus-summary-next-thread (n &optional silent)
11671   "Go to the same level next N'th thread.
11672 If N is negative, search backward instead.
11673 Returns the difference between N and the number of skips actually
11674 done.
11675
11676 If SILENT, don't output messages."
11677   (interactive "p")
11678   (let ((backward (< n 0))
11679         (n (abs n)))
11680     (while (and (> n 0)
11681                 (gnus-summary-go-to-next-thread backward))
11682       (decf n))
11683     (unless silent
11684       (gnus-summary-position-point))
11685     (when (and (not silent) (/= 0 n))
11686       (gnus-message 7 "No more threads"))
11687     n))
11688
11689 (defun gnus-summary-prev-thread (n)
11690   "Go to the same level previous N'th thread.
11691 Returns the difference between N and the number of skips actually
11692 done."
11693   (interactive "p")
11694   (gnus-summary-next-thread (- n)))
11695
11696 (defun gnus-summary-go-down-thread ()
11697   "Go down one level in the current thread."
11698   (let ((children (gnus-summary-article-children)))
11699     (when children
11700       (gnus-summary-goto-subject (car children)))))
11701
11702 (defun gnus-summary-go-up-thread ()
11703   "Go up one level in the current thread."
11704   (let ((parent (gnus-summary-article-parent)))
11705     (when parent
11706       (gnus-summary-goto-subject parent))))
11707
11708 (defun gnus-summary-down-thread (n)
11709   "Go down thread N steps.
11710 If N is negative, go up instead.
11711 Returns the difference between N and how many steps down that were
11712 taken."
11713   (interactive "p")
11714   (let ((up (< n 0))
11715         (n (abs n)))
11716     (while (and (> n 0)
11717                 (if up (gnus-summary-go-up-thread)
11718                   (gnus-summary-go-down-thread)))
11719       (setq n (1- n)))
11720     (gnus-summary-position-point)
11721     (when (/= 0 n)
11722       (gnus-message 7 "Can't go further"))
11723     n))
11724
11725 (defun gnus-summary-up-thread (n)
11726   "Go up thread N steps.
11727 If N is negative, go down instead.
11728 Returns the difference between N and how many steps down that were
11729 taken."
11730   (interactive "p")
11731   (gnus-summary-down-thread (- n)))
11732
11733 (defun gnus-summary-top-thread ()
11734   "Go to the top of the thread."
11735   (interactive)
11736   (while (gnus-summary-go-up-thread))
11737   (gnus-summary-article-number))
11738
11739 (defun gnus-summary-expire-thread ()
11740   "Mark articles under current thread as expired."
11741   (interactive)
11742   (gnus-summary-kill-thread 0))
11743
11744 (defun gnus-summary-kill-thread (&optional unmark)
11745   "Mark articles under current thread as read.
11746 If the prefix argument is positive, remove any kinds of marks.
11747 If the prefix argument is zero, mark thread as expired.
11748 If the prefix argument is negative, tick articles instead."
11749   (interactive "P")
11750   (when unmark
11751     (setq unmark (prefix-numeric-value unmark)))
11752   (let ((articles (gnus-summary-articles-in-thread))
11753         (hide (or (null unmark) (= unmark 0))))
11754     (save-excursion
11755       ;; Expand the thread.
11756       (gnus-summary-show-thread)
11757       ;; Mark all the articles.
11758       (while articles
11759         (gnus-summary-goto-subject (car articles))
11760         (cond ((null unmark)
11761                (gnus-summary-mark-article-as-read gnus-killed-mark))
11762               ((> unmark 0)
11763                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11764               ((= unmark 0)
11765                (gnus-summary-mark-article nil gnus-expirable-mark))
11766               (t
11767                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11768         (setq articles (cdr articles))))
11769     ;; Hide killed subtrees when hide is true.
11770     (and hide
11771          gnus-thread-hide-killed
11772          (gnus-summary-hide-thread))
11773     ;; If hide is t, go to next unread subject.
11774     (when hide
11775       ;; Go to next unread subject.
11776       (gnus-summary-next-subject 1 t)))
11777   (gnus-set-mode-line 'summary))
11778
11779 ;; Summary sorting commands
11780
11781 (defun gnus-summary-sort-by-number (&optional reverse)
11782   "Sort the summary buffer by article number.
11783 Argument REVERSE means reverse order."
11784   (interactive "P")
11785   (gnus-summary-sort 'number reverse))
11786
11787 (defun gnus-summary-sort-by-most-recent-number (&optional reverse)
11788   "Sort the summary buffer by most recent article number.
11789 Argument REVERSE means reverse order."
11790   (interactive "P")
11791   (gnus-summary-sort 'most-recent-number reverse))
11792
11793 (defun gnus-summary-sort-by-random (&optional reverse)
11794   "Randomize the order in the summary buffer.
11795 Argument REVERSE means to randomize in reverse order."
11796   (interactive "P")
11797   (gnus-summary-sort 'random reverse))
11798
11799 (defun gnus-summary-sort-by-author (&optional reverse)
11800   "Sort the summary buffer by author name alphabetically.
11801 If `case-fold-search' is non-nil, case of letters is ignored.
11802 Argument REVERSE means reverse order."
11803   (interactive "P")
11804   (gnus-summary-sort 'author reverse))
11805
11806 (defun gnus-summary-sort-by-recipient (&optional reverse)
11807   "Sort the summary buffer by recipient name alphabetically.
11808 If `case-fold-search' is non-nil, case of letters is ignored.
11809 Argument REVERSE means reverse order."
11810   (interactive "P")
11811   (gnus-summary-sort 'recipient reverse))
11812
11813 (defun gnus-summary-sort-by-subject (&optional reverse)
11814   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11815 If `case-fold-search' is non-nil, case of letters is ignored.
11816 Argument REVERSE means reverse order."
11817   (interactive "P")
11818   (gnus-summary-sort 'subject reverse))
11819
11820 (defun gnus-summary-sort-by-date (&optional reverse)
11821   "Sort the summary buffer by date.
11822 Argument REVERSE means reverse order."
11823   (interactive "P")
11824   (gnus-summary-sort 'date reverse))
11825
11826 (defun gnus-summary-sort-by-most-recent-date (&optional reverse)
11827   "Sort the summary buffer by most recent date.
11828 Argument REVERSE means reverse order."
11829   (interactive "P")
11830   (gnus-summary-sort 'most-recent-date reverse))
11831
11832 (defun gnus-summary-sort-by-score (&optional reverse)
11833   "Sort the summary buffer by score.
11834 Argument REVERSE means reverse order."
11835   (interactive "P")
11836   (gnus-summary-sort 'score reverse))
11837
11838 (defun gnus-summary-sort-by-lines (&optional reverse)
11839   "Sort the summary buffer by the number of lines.
11840 Argument REVERSE means reverse order."
11841   (interactive "P")
11842   (gnus-summary-sort 'lines reverse))
11843
11844 (defun gnus-summary-sort-by-chars (&optional reverse)
11845   "Sort the summary buffer by article length.
11846 Argument REVERSE means reverse order."
11847   (interactive "P")
11848   (gnus-summary-sort 'chars reverse))
11849
11850 (defun gnus-summary-sort-by-original (&optional reverse)
11851   "Sort the summary buffer using the default sorting method.
11852 Argument REVERSE means reverse order."
11853   (interactive "P")
11854   (let* ((inhibit-read-only t)
11855          (gnus-summary-prepare-hook nil))
11856     ;; We do the sorting by regenerating the threads.
11857     (gnus-summary-prepare)
11858     ;; Hide subthreads if needed.
11859     (gnus-summary-maybe-hide-threads)))
11860
11861 (defun gnus-summary-sort (predicate reverse)
11862   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11863   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11864          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11865          (gnus-thread-sort-functions
11866           (if (not reverse)
11867               thread
11868             `(lambda (t1 t2)
11869                (,thread t2 t1))))
11870          (gnus-sort-gathered-threads-function
11871           gnus-thread-sort-functions)
11872          (gnus-article-sort-functions
11873           (if (not reverse)
11874               article
11875             `(lambda (t1 t2)
11876                (,article t2 t1))))
11877          (inhibit-read-only t)
11878          (gnus-summary-prepare-hook nil))
11879     ;; We do the sorting by regenerating the threads.
11880     (gnus-summary-prepare)
11881     ;; Hide subthreads if needed.
11882     (gnus-summary-maybe-hide-threads)))
11883
11884 ;; Summary saving commands.
11885
11886 (defun gnus-summary-save-article (&optional n not-saved)
11887   "Save the current article using the default saver function.
11888 If N is a positive number, save the N next articles.
11889 If N is a negative number, save the N previous articles.
11890 If N is nil and any articles have been marked with the process mark,
11891 save those articles instead.
11892 The variable `gnus-default-article-saver' specifies the saver function.
11893
11894 If the optional second argument NOT-SAVED is non-nil, articles saved
11895 will not be marked as saved."
11896   (interactive "P")
11897   (require 'gnus-art)
11898   (let* ((articles (gnus-summary-work-articles n))
11899          (save-buffer (save-excursion
11900                         (nnheader-set-temp-buffer " *Gnus Save*")))
11901          (num (length articles))
11902          ;; Whether to save decoded articles or raw articles.
11903          (decode (when gnus-article-save-coding-system
11904                    (get gnus-default-article-saver :decode)))
11905          ;; When saving many articles in a single file, use the other
11906          ;; function to save articles other than the first one.
11907          (saver2 (get gnus-default-article-saver :function))
11908          (gnus-prompt-before-saving (if saver2
11909                                         t
11910                                       gnus-prompt-before-saving))
11911          (gnus-default-article-saver gnus-default-article-saver)
11912          header file)
11913     (dolist (article articles)
11914       (setq header (gnus-summary-article-header article))
11915       (if (not (vectorp header))
11916           ;; This is a pseudo-article.
11917           (if (assq 'name header)
11918               (gnus-copy-file (cdr (assq 'name header)))
11919             (gnus-message 1 "Article %d is unsaveable" article))
11920         ;; This is a real article.
11921         (save-window-excursion
11922           (gnus-summary-select-article decode decode nil article)
11923           (gnus-summary-goto-subject article))
11924         (with-current-buffer save-buffer
11925           (erase-buffer)
11926           (insert-buffer-substring (if decode
11927                                        gnus-article-buffer
11928                                      gnus-original-article-buffer)))
11929         (setq file (gnus-article-save save-buffer file num))
11930         (gnus-summary-remove-process-mark article)
11931         (unless not-saved
11932           (gnus-summary-set-saved-mark article)))
11933       (when saver2
11934         (setq gnus-default-article-saver saver2
11935               saver2 nil)))
11936     (gnus-kill-buffer save-buffer)
11937     (gnus-summary-position-point)
11938     (gnus-set-mode-line 'summary)
11939     n))
11940
11941 (defun gnus-summary-pipe-output (&optional n sym)
11942   "Pipe the current article to a subprocess.
11943 If N is a positive number, pipe the N next articles.
11944 If N is a negative number, pipe the N previous articles.
11945 If N is nil and any articles have been marked with the process mark,
11946 pipe those articles instead.
11947 The default command to which articles are piped is specified by the
11948 variable `gnus-summary-pipe-output-default-command'; if it is nil, you
11949 will be prompted for the command.
11950
11951 The properties `:decode' and `:headers' that are put to the function
11952 symbol `gnus-summary-save-in-pipe' control whether this function
11953 decodes articles and what headers to keep (see the doc string for the
11954 `gnus-default-article-saver' variable).  If SYM (the symbolic prefix)
11955 is neither omitted nor the symbol `r', force including all headers
11956 regardless of the `:headers' property.  If it is the symbol `r',
11957 articles that are not decoded and include all headers will be piped
11958 no matter what the properties `:decode' and `:headers' are."
11959   (interactive (gnus-interactive "P\ny"))
11960   (require 'gnus-art)
11961   (let* ((articles (gnus-summary-work-articles n))
11962          (result-buffer "*Shell Command Output*")
11963          (all-headers (not (memq sym '(nil r))))
11964          (gnus-save-all-headers (or all-headers gnus-save-all-headers))
11965          (raw (eq sym 'r))
11966          (headers (get 'gnus-summary-save-in-pipe :headers))
11967          command result)
11968     (unless (numberp (car articles))
11969       (error "No article to pipe"))
11970     (setq command (gnus-read-shell-command
11971                    (concat "Shell command on "
11972                            (if (cdr articles)
11973                                (format "these %d articles" (length articles))
11974                              "this article")
11975                            ": ")
11976                    gnus-summary-pipe-output-default-command))
11977     (when (string-equal command "")
11978       (error "A command is required"))
11979     (when all-headers
11980       (put 'gnus-summary-save-in-pipe :headers nil))
11981     (unwind-protect
11982         (while articles
11983           (gnus-summary-goto-subject (pop articles))
11984           (save-window-excursion (gnus-summary-save-in-pipe command raw))
11985           (when (and (get-buffer result-buffer)
11986                      (not (zerop (buffer-size (get-buffer result-buffer)))))
11987             (setq result (concat result (with-current-buffer result-buffer
11988                                           (buffer-string))))))
11989       (put 'gnus-summary-save-in-pipe :headers headers))
11990     (unless (zerop (length result))
11991       (if (with-current-buffer (get-buffer-create result-buffer)
11992             (erase-buffer)
11993             (insert result)
11994             (prog1
11995                 (and (= (count-lines (point-min) (point)) 1)
11996                      (progn
11997                        (end-of-line 0)
11998                        (<= (current-column)
11999                            (window-width (minibuffer-window)))))
12000               (goto-char (point-min))))
12001           (message "%s" (substring result 0 -1))
12002         (message nil)
12003         (gnus-configure-windows 'pipe)))))
12004
12005 (defun gnus-summary-save-article-mail (&optional arg)
12006   "Append the current article to a Unix mail box file.
12007 If N is a positive number, save the N next articles.
12008 If N is a negative number, save the N previous articles.
12009 If N is nil and any articles have been marked with the process mark,
12010 save those articles instead."
12011   (interactive "P")
12012   (require 'gnus-art)
12013   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
12014     (gnus-summary-save-article arg)))
12015
12016 (defun gnus-summary-save-article-rmail (&optional arg)
12017   "Append the current article to an rmail file.
12018 If N is a positive number, save the N next articles.
12019 If N is a negative number, save the N previous articles.
12020 If N is nil and any articles have been marked with the process mark,
12021 save those articles instead."
12022   (interactive "P")
12023   (require 'gnus-art)
12024   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
12025     (gnus-summary-save-article arg)))
12026
12027 (defun gnus-summary-save-article-file (&optional arg)
12028   "Append the current article to a file.
12029 If N is a positive number, save the N next articles.
12030 If N is a negative number, save the N previous articles.
12031 If N is nil and any articles have been marked with the process mark,
12032 save those articles instead."
12033   (interactive "P")
12034   (require 'gnus-art)
12035   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
12036     (gnus-summary-save-article arg)))
12037
12038 (defun gnus-summary-write-article-file (&optional arg)
12039   "Write the current article to a file, deleting the previous file.
12040 If N is a positive number, save the N next articles.
12041 If N is a negative number, save the N previous articles.
12042 If N is nil and any articles have been marked with the process mark,
12043 save those articles instead."
12044   (interactive "P")
12045   (require 'gnus-art)
12046   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
12047     (gnus-summary-save-article arg)))
12048
12049 (defun gnus-summary-save-article-body-file (&optional arg)
12050   "Append the current article body to a file.
12051 If N is a positive number, save the N next articles.
12052 If N is a negative number, save the N previous articles.
12053 If N is nil and any articles have been marked with the process mark,
12054 save those articles instead."
12055   (interactive "P")
12056   (require 'gnus-art)
12057   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
12058     (gnus-summary-save-article arg)))
12059
12060 (defun gnus-summary-write-article-body-file (&optional arg)
12061   "Write the current article body to a file, deleting the previous file.
12062 If N is a positive number, save the N next articles.
12063 If N is a negative number, save the N previous articles.
12064 If N is nil and any articles have been marked with the process mark,
12065 save those articles instead."
12066   (interactive "P")
12067   (require 'gnus-art)
12068   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
12069     (gnus-summary-save-article arg)))
12070
12071 (defun gnus-summary-muttprint (&optional arg)
12072   "Print the current article using Muttprint.
12073 If N is a positive number, save the N next articles.
12074 If N is a negative number, save the N previous articles.
12075 If N is nil and any articles have been marked with the process mark,
12076 save those articles instead."
12077   (interactive "P")
12078   (require 'gnus-art)
12079   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
12080     (gnus-summary-save-article arg t)))
12081
12082 (defun gnus-summary-pipe-message (program)
12083   "Pipe the current article through PROGRAM."
12084   (interactive "sProgram: ")
12085   (gnus-summary-select-article)
12086   (let ((mail-header-separator ""))
12087     (gnus-eval-in-buffer-window gnus-article-buffer
12088       (save-restriction
12089         (widen)
12090         (let ((start (window-start))
12091               (inhibit-read-only t))
12092           (message-pipe-buffer-body program)
12093           (set-window-start (get-buffer-window (current-buffer)) start))))))
12094
12095 (defun gnus-get-split-value (methods)
12096   "Return a value based on the split METHODS."
12097   (let (split-name method result match)
12098     (when methods
12099       (with-current-buffer gnus-original-article-buffer
12100         (save-restriction
12101           (nnheader-narrow-to-headers)
12102           (while (and methods (not split-name))
12103             (goto-char (point-min))
12104             (setq method (pop methods))
12105             (setq match (car method))
12106             (when (cond
12107                    ((stringp match)
12108                     ;; Regular expression.
12109                     (ignore-errors
12110                       (re-search-forward match nil t)))
12111                    ((functionp match)
12112                     ;; Function.
12113                     (save-restriction
12114                       (widen)
12115                       (setq result (funcall match gnus-newsgroup-name))))
12116                    ((consp match)
12117                     ;; Form.
12118                     (save-restriction
12119                       (widen)
12120                       (setq result (eval match)))))
12121               (setq split-name (cdr method))
12122               (cond ((stringp result)
12123                      (push (expand-file-name
12124                             result gnus-article-save-directory)
12125                            split-name))
12126                     ((consp result)
12127                      (setq split-name (append result split-name)))))))))
12128     (nreverse split-name)))
12129
12130 (defun gnus-valid-move-group-p (group)
12131   (and (symbolp group)
12132        (boundp group)
12133        (symbol-name group)
12134        (symbol-value group)
12135        (gnus-get-function (gnus-find-method-for-group
12136                            (symbol-name group)) 'request-accept-article t)))
12137
12138 (defun gnus-read-move-group-name (prompt default articles prefix)
12139   "Read a group name."
12140   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
12141          (minibuffer-confirm-incomplete nil) ; XEmacs
12142          (prom
12143           (format "%s %s to"
12144                   prompt
12145                   (if (> (length articles) 1)
12146                       (format "these %d articles" (length articles))
12147                     "this article")))
12148          (to-newsgroup
12149           (cond
12150            ((null split-name)
12151             (gnus-group-completing-read
12152              prom
12153              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12154              nil prefix nil default))
12155            ((= 1 (length split-name))
12156             (gnus-group-completing-read
12157              prom
12158              (gnus-remove-if-not 'gnus-valid-move-group-p gnus-active-hashtb t)
12159              nil prefix 'gnus-group-history (car split-name)))
12160            (t
12161             (gnus-completing-read
12162              prom (nreverse split-name) nil nil 'gnus-group-history))))
12163          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
12164          encoded)
12165     (when to-newsgroup
12166       (if (or (string= to-newsgroup "")
12167               (string= to-newsgroup prefix))
12168           (setq to-newsgroup default))
12169       (unless to-newsgroup
12170         (error "No group name entered"))
12171       (setq encoded (mm-encode-coding-string
12172                      to-newsgroup
12173                      (gnus-group-name-charset to-method to-newsgroup)))
12174       (or (gnus-active encoded)
12175           (gnus-activate-group encoded nil nil to-method)
12176           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
12177                                      to-newsgroup))
12178               (or (and (gnus-request-create-group encoded to-method)
12179                        (gnus-activate-group encoded nil nil to-method)
12180                        (gnus-subscribe-group encoded))
12181                   (error "Couldn't create group %s" to-newsgroup)))
12182           (error "No such group: %s" to-newsgroup))
12183       encoded)))
12184
12185 (defvar gnus-summary-save-parts-counter)
12186 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
12187
12188 (defun gnus-summary-save-parts (type dir n &optional reverse)
12189   "Save parts matching TYPE to DIR.
12190 If REVERSE, save parts that do not match TYPE."
12191   (interactive
12192    (list (read-string "Save parts of type: "
12193                       (or (car gnus-summary-save-parts-type-history)
12194                           gnus-summary-save-parts-default-mime)
12195                       'gnus-summary-save-parts-type-history)
12196          (setq gnus-summary-save-parts-last-directory
12197                (read-directory-name "Save to directory: "
12198                                     gnus-summary-save-parts-last-directory
12199                                     nil t))
12200          current-prefix-arg))
12201   (gnus-summary-iterate n
12202     (let ((gnus-display-mime-function nil)
12203           gnus-article-prepare-hook
12204           gnus-article-decode-hook
12205           gnus-display-mime-function
12206           gnus-break-pages
12207           (gnus-inhibit-treatment t))
12208       (gnus-summary-select-article))
12209     (with-current-buffer gnus-article-buffer
12210       (let ((handles (or gnus-article-mime-handles
12211                          (mm-dissect-buffer nil gnus-article-loose-mime)
12212                          (and gnus-article-emulate-mime
12213                               (mm-uu-dissect))))
12214             (gnus-summary-save-parts-counter 1))
12215         (when handles
12216           (gnus-summary-save-parts-1 type dir handles reverse)
12217           (unless gnus-article-mime-handles ;; Don't destroy this case.
12218             (mm-destroy-parts handles)))))))
12219
12220 (defun gnus-summary-save-parts-1 (type dir handle reverse)
12221   (if (stringp (car handle))
12222       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
12223               (cdr handle))
12224     (when (if reverse
12225               (not (string-match type (mm-handle-media-type handle)))
12226             (string-match type (mm-handle-media-type handle)))
12227       (let ((file (expand-file-name
12228                    (gnus-map-function
12229                     mm-file-name-rewrite-functions
12230                     (file-name-nondirectory
12231                      (or
12232                       (mm-handle-filename handle)
12233                       (format "%s.%d.%d" gnus-newsgroup-name
12234                               (cdr gnus-article-current)
12235                               gnus-summary-save-parts-counter))))
12236                    dir)))
12237         (incf gnus-summary-save-parts-counter)
12238         (unless (file-exists-p file)
12239           (mm-save-part-to-file handle file))))))
12240
12241 ;; Summary extract commands
12242
12243 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
12244   (let ((inhibit-read-only t)
12245         (article (gnus-summary-article-number))
12246         after-article b e)
12247     (unless (gnus-summary-goto-subject article)
12248       (error "No such article: %d" article))
12249     (gnus-summary-position-point)
12250     ;; If all commands are to be bunched up on one line, we collect
12251     ;; them here.
12252     (unless gnus-view-pseudos-separately
12253       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
12254             files action)
12255         (while ps
12256           (setq action (cdr (assq 'action (car ps))))
12257           (setq files (list (cdr (assq 'name (car ps)))))
12258           (while (and ps (cdr ps)
12259                       (string= (or action "1")
12260                                (or (cdr (assq 'action (cadr ps))) "2")))
12261             (push (cdr (assq 'name (cadr ps))) files)
12262             (setcdr ps (cddr ps)))
12263           (when files
12264             (when (not (string-match "%s" action))
12265               (push " " files))
12266             (push " " files)
12267             (when (assq 'execute (car ps))
12268               (setcdr (assq 'execute (car ps))
12269                       (funcall (if (string-match "%s" action)
12270                                    'format 'concat)
12271                                action
12272                                (mapconcat
12273                                 (lambda (f)
12274                                   (if (equal f " ")
12275                                       f
12276                                     (shell-quote-argument f)))
12277                                 files " ")))))
12278           (setq ps (cdr ps)))))
12279     (if (and gnus-view-pseudos (not not-view))
12280         (while pslist
12281           (when (assq 'execute (car pslist))
12282             (gnus-execute-command (cdr (assq 'execute (car pslist)))
12283                                   (eq gnus-view-pseudos 'not-confirm)))
12284           (setq pslist (cdr pslist)))
12285       (save-excursion
12286         (while pslist
12287           (setq after-article (or (cdr (assq 'article (car pslist)))
12288                                   (gnus-summary-article-number)))
12289           (gnus-summary-goto-subject after-article)
12290           (forward-line 1)
12291           (setq b (point))
12292           (insert "    " (file-name-nondirectory
12293                           (cdr (assq 'name (car pslist))))
12294                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
12295           (setq e (point))
12296           (forward-line -1)             ; back to `b'
12297           (gnus-add-text-properties
12298            b (1- e) (list 'gnus-number gnus-reffed-article-number
12299                           gnus-mouse-face-prop gnus-mouse-face))
12300           (gnus-data-enter
12301            after-article gnus-reffed-article-number
12302            gnus-unread-mark b (car pslist) 0 (- e b))
12303           (setq gnus-newsgroup-unreads
12304                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
12305                                          gnus-reffed-article-number))
12306           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
12307           (setq pslist (cdr pslist)))))))
12308
12309 (defun gnus-pseudos< (p1 p2)
12310   (let ((c1 (cdr (assq 'action p1)))
12311         (c2 (cdr (assq 'action p2))))
12312     (and c1 c2 (string< c1 c2))))
12313
12314 (defun gnus-request-pseudo-article (props)
12315   (cond ((assq 'execute props)
12316          (gnus-execute-command (cdr (assq 'execute props)))))
12317   (let ((gnus-current-article (gnus-summary-article-number)))
12318     (gnus-run-hooks 'gnus-mark-article-hook)))
12319
12320 (defun gnus-execute-command (command &optional automatic)
12321   (save-excursion
12322     (gnus-article-setup-buffer)
12323     (set-buffer gnus-article-buffer)
12324     (setq buffer-read-only nil)
12325     (let ((command (if automatic command
12326                      (read-string "Command: " (cons command 0)))))
12327       (erase-buffer)
12328       (insert "$ " command "\n\n")
12329       (if gnus-view-pseudo-asynchronously
12330           (start-process "gnus-execute" (current-buffer) shell-file-name
12331                          shell-command-switch command)
12332         (call-process shell-file-name nil t nil
12333                       shell-command-switch command)))))
12334
12335 ;; Summary kill commands.
12336
12337 (defun gnus-summary-edit-global-kill (article)
12338   "Edit the \"global\" kill file."
12339   (interactive (list (gnus-summary-article-number)))
12340   (gnus-group-edit-global-kill article))
12341
12342 (defun gnus-summary-edit-local-kill ()
12343   "Edit a local kill file applied to the current newsgroup."
12344   (interactive)
12345   (setq gnus-current-headers (gnus-summary-article-header))
12346   (gnus-group-edit-local-kill
12347    (gnus-summary-article-number) gnus-newsgroup-name))
12348
12349 ;;; Header reading.
12350
12351 (defun gnus-read-header (id &optional header)
12352   "Read the headers of article ID and enter them into the Gnus system."
12353   (let ((group gnus-newsgroup-name)
12354         (gnus-override-method
12355          (or
12356           gnus-override-method
12357           (and (gnus-news-group-p gnus-newsgroup-name)
12358                (car (gnus-refer-article-methods)))))
12359         where)
12360     ;; First we check to see whether the header in question is already
12361     ;; fetched.
12362     (if (stringp id)
12363         ;; This is a Message-ID.
12364         (setq header (or header (gnus-id-to-header id)))
12365       ;; This is an article number.
12366       (setq header (or header (gnus-summary-article-header id))))
12367     (if (and header
12368              (not (gnus-summary-article-sparse-p (mail-header-number header))))
12369         ;; We have found the header.
12370         header
12371       ;; We have to really fetch the header to this article.
12372       (with-current-buffer nntp-server-buffer
12373         (when (setq where (gnus-request-head id group))
12374           (nnheader-fold-continuation-lines)
12375           (goto-char (point-max))
12376           (insert ".\n")
12377           (goto-char (point-min))
12378           (insert "211 ")
12379           (princ (cond
12380                   ((numberp id) id)
12381                   ((cdr where) (cdr where))
12382                   (header (mail-header-number header))
12383                   (t gnus-reffed-article-number))
12384                  (current-buffer))
12385           (insert " Article retrieved.\n"))
12386         (if (or (not where)
12387                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12388             ()                          ; Malformed head.
12389           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12390             (when (and (stringp id)
12391                        (or
12392                         (not (string= (gnus-group-real-name group)
12393                                       (car where)))
12394                         (not (gnus-server-equal gnus-override-method
12395                                                 (gnus-group-method group)))))
12396               ;; If we fetched by Message-ID and the article came from
12397               ;; a different group (or server), we fudge some bogus
12398               ;; article numbers for this article.
12399               (mail-header-set-number header gnus-reffed-article-number))
12400             (with-current-buffer gnus-summary-buffer
12401               (decf gnus-reffed-article-number)
12402               (gnus-remove-header (mail-header-number header))
12403               (push header gnus-newsgroup-headers)
12404               (setq gnus-current-headers header)
12405               (push (mail-header-number header) gnus-newsgroup-limit)))
12406           header)))))
12407
12408 (defun gnus-remove-header (number)
12409   "Remove header NUMBER from `gnus-newsgroup-headers'."
12410   (if (and gnus-newsgroup-headers
12411            (= number (mail-header-number (car gnus-newsgroup-headers))))
12412       (pop gnus-newsgroup-headers)
12413     (let ((headers gnus-newsgroup-headers))
12414       (while (and (cdr headers)
12415                   (not (= number (mail-header-number (cadr headers)))))
12416         (pop headers))
12417       (when (cdr headers)
12418         (setcdr headers (cddr headers))))))
12419
12420 ;;;
12421 ;;; summary highlights
12422 ;;;
12423
12424 (defun gnus-highlight-selected-summary ()
12425   "Highlight selected article in summary buffer."
12426   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12427   (when gnus-summary-selected-face
12428     (save-excursion
12429       (let* ((beg (point-at-bol))
12430              (end (point-at-eol))
12431              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12432              (from (if (get-text-property beg gnus-mouse-face-prop)
12433                        beg
12434                      (or (next-single-property-change
12435                           beg gnus-mouse-face-prop nil end)
12436                          beg)))
12437              (to
12438               (if (= from end)
12439                   (- from 2)
12440                 (or (next-single-property-change
12441                      from gnus-mouse-face-prop nil end)
12442                     end))))
12443         ;; If no mouse-face prop on line we will have to = from = end,
12444         ;; so we highlight the entire line instead.
12445         (when (= (+ to 2) from)
12446           (setq from beg)
12447           (setq to end))
12448         (if gnus-newsgroup-selected-overlay
12449             ;; Move old overlay.
12450             (gnus-move-overlay
12451              gnus-newsgroup-selected-overlay from to (current-buffer))
12452           ;; Create new overlay.
12453           (gnus-overlay-put
12454            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12455            'face gnus-summary-selected-face))))))
12456
12457 (defvar gnus-summary-highlight-line-cached nil)
12458 (defvar gnus-summary-highlight-line-trigger nil)
12459
12460 (defun gnus-summary-highlight-line-0 ()
12461   (if (and (eq gnus-summary-highlight-line-trigger
12462                gnus-summary-highlight)
12463            gnus-summary-highlight-line-cached)
12464       gnus-summary-highlight-line-cached
12465     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12466           gnus-summary-highlight-line-cached
12467           (let* ((cond (list 'cond))
12468                  (c cond)
12469                  (list gnus-summary-highlight))
12470             (while list
12471               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12472                               nil))
12473               (setq c (cdr c)
12474                     list (cdr list)))
12475             (gnus-byte-compile (list 'lambda nil cond))))))
12476
12477 (defun gnus-summary-highlight-line ()
12478   "Highlight current line according to `gnus-summary-highlight'."
12479   (let* ((beg (point-at-bol))
12480          (article (or (gnus-summary-article-number) gnus-current-article))
12481          (score (or (cdr (assq article
12482                                gnus-newsgroup-scored))
12483                     gnus-summary-default-score 0))
12484          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12485          (inhibit-read-only t)
12486          (default gnus-summary-default-score)
12487          (default-high gnus-summary-default-high-score)
12488          (default-low gnus-summary-default-low-score)
12489          (uncached (and gnus-summary-use-undownloaded-faces
12490                         (memq article gnus-newsgroup-undownloaded)
12491                         (not (memq article gnus-newsgroup-cached)))))
12492     (let ((face (funcall (gnus-summary-highlight-line-0))))
12493       (unless (eq face (get-text-property beg 'face))
12494         (gnus-put-text-property-excluding-characters-with-faces
12495          beg (point-at-eol) 'face
12496          (setq face (if (boundp face) (symbol-value face) face)))
12497         (when gnus-summary-highlight-line-function
12498           (funcall gnus-summary-highlight-line-function article face))))))
12499
12500 (defun gnus-update-read-articles (group unread &optional compute)
12501   "Update the list of read articles in GROUP.
12502 UNREAD is a sorted list."
12503   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12504         (info (gnus-get-info group))
12505         (prev 1)
12506         read)
12507     (if (or (not info) (not active))
12508         ;; There is no info on this group if it was, in fact,
12509         ;; killed.  Gnus stores no information on killed groups, so
12510         ;; there's nothing to be done.
12511         ;; One could store the information somewhere temporarily,
12512         ;; perhaps...  Hmmm...
12513         ()
12514       ;; Remove any negative articles numbers.
12515       (while (and unread (< (car unread) 0))
12516         (setq unread (cdr unread)))
12517       ;; Remove any expired article numbers
12518       (while (and unread (< (car unread) (car active)))
12519         (setq unread (cdr unread)))
12520       ;; Compute the ranges of read articles by looking at the list of
12521       ;; unread articles.
12522       (while unread
12523         (when (/= (car unread) prev)
12524           (push (if (= prev (1- (car unread))) prev
12525                   (cons prev (1- (car unread))))
12526                 read))
12527         (setq prev (1+ (car unread)))
12528         (setq unread (cdr unread)))
12529       (when (<= prev (cdr active))
12530         (push (cons prev (cdr active)) read))
12531       (setq read (if (> (length read) 1) (nreverse read) read))
12532       (if compute
12533           read
12534         (save-excursion
12535           (let (setmarkundo)
12536             ;; Propagate the read marks to the backend.
12537             (when (and (or gnus-propagate-marks
12538                            (gnus-method-option-p
12539                             (gnus-find-method-for-group group)
12540                             'server-marks))
12541                        (gnus-check-backend-function 'request-set-mark group))
12542               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12543                     (add (gnus-remove-from-range read (gnus-info-read info))))
12544                 (when (or add del)
12545                   (unless (gnus-check-group group)
12546                     (error "Can't open server for %s" group))
12547                   (gnus-request-set-mark
12548                    group (delq nil (list (if add (list add 'add '(read)))
12549                                          (if del (list del 'del '(read))))))
12550                   (setq setmarkundo
12551                         `(gnus-request-set-mark
12552                           ,group
12553                           ',(delq nil (list
12554                                        (if del (list del 'add '(read)))
12555                                        (if add (list add 'del '(read))))))))))
12556             (set-buffer gnus-group-buffer)
12557             (gnus-undo-register
12558               `(progn
12559                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12560                  (gnus-info-set-read ',info ',(gnus-info-read info))
12561                  (gnus-get-unread-articles-in-group ',info
12562                                                     (gnus-active ,group))
12563                  (gnus-group-update-group ,group t)
12564                  ,setmarkundo))))
12565         ;; Enter this list into the group info.
12566         (gnus-info-set-read info read)
12567         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12568         (gnus-get-unread-articles-in-group info (gnus-active group))
12569         t))))
12570
12571 (defun gnus-offer-save-summaries ()
12572   "Offer to save all active summary buffers."
12573   (let (buffers)
12574     ;; Go through all buffers and find all summaries.
12575     (dolist (buffer (buffer-list))
12576       (when (and (setq buffer (buffer-name buffer))
12577                  (string-match "Summary" buffer)
12578                  (with-current-buffer buffer
12579                    ;; We check that this is, indeed, a summary buffer.
12580                    (and (eq major-mode 'gnus-summary-mode)
12581                         ;; Also make sure this isn't bogus.
12582                         gnus-newsgroup-prepared
12583                         ;; Also make sure that this isn't a
12584                         ;; dead summary buffer.
12585                         (not gnus-dead-summary-mode))))
12586         (push buffer buffers)))
12587     ;; Go through all these summary buffers and offer to save them.
12588     (when buffers
12589       (save-excursion
12590         (map-y-or-n-p
12591          "Update summary buffer %s? "
12592          (lambda (buf)
12593            (switch-to-buffer buf)
12594            (gnus-summary-exit))
12595          buffers)))))
12596
12597 (defun gnus-summary-setup-default-charset ()
12598   "Setup newsgroup default charset."
12599   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12600       (setq gnus-newsgroup-charset nil)
12601     (let* ((ignored-charsets
12602             (or gnus-newsgroup-ephemeral-ignored-charsets
12603                 (append
12604                  (and gnus-newsgroup-name
12605                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12606                  gnus-newsgroup-ignored-charsets))))
12607       (setq gnus-newsgroup-charset
12608             (or gnus-newsgroup-ephemeral-charset
12609                 (and gnus-newsgroup-name
12610                      (gnus-parameter-charset gnus-newsgroup-name))
12611                 gnus-default-charset))
12612       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12613            ignored-charsets))))
12614
12615 ;;;
12616 ;;; Mime Commands
12617 ;;;
12618
12619 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12620   "Display the current article buffer fully MIME-buttonized.
12621 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12622 treated as multipart/mixed."
12623   (interactive "P")
12624   (require 'gnus-art)
12625   (let ((gnus-unbuttonized-mime-types nil)
12626         (gnus-mime-display-multipart-as-mixed show-all-parts))
12627     (gnus-summary-show-article)))
12628
12629 (defun gnus-summary-repair-multipart (article)
12630   "Add a Content-Type header to a multipart article without one."
12631   (interactive (list (gnus-summary-article-number)))
12632   (gnus-with-article article
12633     (message-narrow-to-head)
12634     (message-remove-header "Mime-Version")
12635     (goto-char (point-max))
12636     (insert "Mime-Version: 1.0\n")
12637     (widen)
12638     (when (search-forward "\n--" nil t)
12639       (let ((separator (buffer-substring (point) (point-at-eol))))
12640         (message-narrow-to-head)
12641         (message-remove-header "Content-Type")
12642         (goto-char (point-max))
12643         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12644                         separator))
12645         (widen))))
12646   (let (gnus-mark-article-hook)
12647     (gnus-summary-select-article t t nil article)))
12648
12649 (defun gnus-summary-toggle-display-buttonized ()
12650   "Toggle the buttonizing of the article buffer."
12651   (interactive)
12652   (require 'gnus-art)
12653   (if (setq gnus-inhibit-mime-unbuttonizing
12654             (not gnus-inhibit-mime-unbuttonizing))
12655       (let ((gnus-unbuttonized-mime-types nil))
12656         (gnus-summary-show-article))
12657     (gnus-summary-show-article)))
12658
12659 ;;;
12660 ;;; Generic summary marking commands
12661 ;;;
12662
12663 (defvar gnus-summary-marking-alist
12664   '((read gnus-del-mark "d")
12665     (unread gnus-unread-mark "u")
12666     (ticked gnus-ticked-mark "!")
12667     (dormant gnus-dormant-mark "?")
12668     (expirable gnus-expirable-mark "e"))
12669   "An alist of names/marks/keystrokes.")
12670
12671 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12672 (defvar gnus-summary-mark-map)
12673
12674 (defun gnus-summary-make-all-marking-commands ()
12675   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12676   (dolist (elem gnus-summary-marking-alist)
12677     (apply 'gnus-summary-make-marking-command elem)))
12678
12679 (defun gnus-summary-make-marking-command (name mark keystroke)
12680   (let ((map (make-sparse-keymap)))
12681     (define-key gnus-summary-generic-mark-map keystroke map)
12682     (dolist (lway `((next "next" next nil "n")
12683                     (next-unread "next unread" next t "N")
12684                     (prev "previous" prev nil "p")
12685                     (prev-unread "previous unread" prev t "P")
12686                     (nomove "" nil nil ,keystroke)))
12687       (let ((func (gnus-summary-make-marking-command-1
12688                    mark (car lway) lway name)))
12689         (setq func (eval func))
12690         (define-key map (nth 4 lway) func)))))
12691
12692 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12693   `(defun ,(intern
12694             (format "gnus-summary-put-mark-as-%s%s"
12695                     name (if (eq way 'nomove)
12696                              ""
12697                            (concat "-" (symbol-name way)))))
12698      (n)
12699      ,(format
12700        "Mark the current article as %s%s.
12701 If N, the prefix, then repeat N times.
12702 If N is negative, move in reverse order.
12703 The difference between N and the actual number of articles marked is
12704 returned."
12705        name (cadr lway))
12706      (interactive "p")
12707      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12708
12709 (defun gnus-summary-generic-mark (n mark move unread)
12710   "Mark N articles with MARK."
12711   (unless (eq major-mode 'gnus-summary-mode)
12712     (error "This command can only be used in the summary buffer"))
12713   (gnus-summary-show-thread)
12714   (let ((nummove
12715          (cond
12716           ((eq move 'next) 1)
12717           ((eq move 'prev) -1)
12718           (t 0))))
12719     (if (zerop nummove)
12720         (setq n 1)
12721       (when (< n 0)
12722         (setq n (abs n)
12723               nummove (* -1 nummove))))
12724     (while (and (> n 0)
12725                 (gnus-summary-mark-article nil mark)
12726                 (zerop (gnus-summary-next-subject nummove unread t)))
12727       (setq n (1- n)))
12728     (when (/= 0 n)
12729       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12730     (gnus-summary-recenter)
12731     (gnus-summary-position-point)
12732     (gnus-set-mode-line 'summary)
12733     n))
12734
12735 (defun gnus-summary-insert-articles (articles)
12736   (when (setq articles
12737               (gnus-sorted-difference articles
12738                                       (mapcar (lambda (h)
12739                                                 (mail-header-number h))
12740                                               gnus-newsgroup-headers)))
12741     (setq gnus-newsgroup-headers
12742           (gnus-merge 'list
12743                       gnus-newsgroup-headers
12744                       (gnus-fetch-headers articles)
12745                       'gnus-article-sort-by-number))
12746     ;; Suppress duplicates?
12747     (when gnus-suppress-duplicates
12748       (gnus-dup-suppress-articles))
12749
12750     (if (and gnus-fetch-old-headers
12751              (eq gnus-headers-retrieved-by 'nov))
12752         ;; We might want to build some more threads first.
12753         (if (eq gnus-fetch-old-headers 'invisible)
12754             (gnus-build-all-threads)
12755           (gnus-build-old-threads))
12756       ;; Mark the inserted articles that are unread as unread.
12757       (setq gnus-newsgroup-unreads
12758             (gnus-sorted-nunion
12759              gnus-newsgroup-unreads
12760              (gnus-sorted-nintersection
12761               (gnus-list-of-unread-articles gnus-newsgroup-name)
12762               articles)))
12763       ;; Mark the inserted articles as selected so that the information
12764       ;; of the marks having been changed by a user may be updated when
12765       ;; exiting this group.  See `gnus-summary-update-info'.
12766       (dolist (art articles)
12767         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12768     ;; Let the Gnus agent mark articles as read.
12769     (when gnus-agent
12770       (gnus-agent-get-undownloaded-list))
12771     ;; Remove list identifiers from subject
12772     (gnus-summary-remove-list-identifiers)
12773     ;; First and last article in this newsgroup.
12774     (when gnus-newsgroup-headers
12775       (setq gnus-newsgroup-begin
12776             (mail-header-number (car gnus-newsgroup-headers))
12777             gnus-newsgroup-end
12778             (mail-header-number
12779              (gnus-last-element gnus-newsgroup-headers))))
12780     (when gnus-use-scoring
12781       (gnus-possibly-score-headers))))
12782
12783 (defun gnus-summary-insert-old-articles (&optional all)
12784   "Insert all old articles in this group.
12785 If ALL is non-nil, already read articles become readable.
12786 If ALL is a number, fetch this number of articles."
12787   (interactive "P")
12788   (prog1
12789       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12790             older len)
12791         (setq older
12792               ;; Some nntp servers lie about their active range.  When
12793               ;; this happens, the active range can be in the millions.
12794               ;; Use a compressed range to avoid creating a huge list.
12795               (gnus-range-difference (list gnus-newsgroup-active) old))
12796         (setq len (gnus-range-length older))
12797         (cond
12798          ((null older) nil)
12799          ((numberp all)
12800           (if (< all len)
12801               (let ((older-range (nreverse older)))
12802                 (setq older nil)
12803
12804                 (while (> all 0)
12805                   (let* ((r (pop older-range))
12806                          (min (if (numberp r) r (car r)))
12807                          (max (if (numberp r) r (cdr r))))
12808                     (while (and (<= min max)
12809                                 (> all 0))
12810                       (push max older)
12811                       (setq all (1- all)
12812                             max (1- max))))))
12813             (setq older (gnus-uncompress-range older))))
12814          (all
12815           (setq older (gnus-uncompress-range older)))
12816          (t
12817           (when (and (numberp gnus-large-newsgroup)
12818                    (> len gnus-large-newsgroup))
12819               (let* ((cursor-in-echo-area nil)
12820                      (initial (gnus-parameter-large-newsgroup-initial
12821                                gnus-newsgroup-name))
12822                      (input
12823                       (read-string
12824                        (format
12825                         "How many articles from %s (%s %d): "
12826                         (gnus-group-decoded-name gnus-newsgroup-name)
12827                         (if initial "max" "default")
12828                         len)
12829                        (if initial
12830                            (cons (number-to-string initial)
12831                                  0)))))
12832                 (unless (string-match "^[ \t]*$" input)
12833                   (setq all (string-to-number input))
12834                   (if (< all len)
12835                       (let ((older-range (nreverse older)))
12836                         (setq older nil)
12837
12838                         (while (> all 0)
12839                           (let* ((r (pop older-range))
12840                                  (min (if (numberp r) r (car r)))
12841                                  (max (if (numberp r) r (cdr r))))
12842                             (while (and (<= min max)
12843                                         (> all 0))
12844                               (push max older)
12845                               (setq all (1- all)
12846                                     max (1- max))))))))))
12847           (setq older (gnus-uncompress-range older))))
12848         (if (not older)
12849             (message "No old news.")
12850           (gnus-summary-insert-articles older)
12851           (gnus-summary-limit (gnus-sorted-nunion old older))))
12852     (gnus-summary-position-point)))
12853
12854 (defun gnus-summary-insert-new-articles ()
12855   "Insert all new articles in this group."
12856   (interactive)
12857   (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12858         (old-high gnus-newsgroup-highest)
12859         (nnmail-fetched-sources (list t))
12860         (new-active (gnus-activate-group gnus-newsgroup-name 'scan))
12861         i new)
12862     (unless new-active
12863       (error "Couldn't fetch new data"))
12864     (setq gnus-newsgroup-active (gnus-copy-sequence new-active))
12865     (setq i (cdr gnus-newsgroup-active)
12866           gnus-newsgroup-highest i)
12867     (while (> i old-high)
12868       (push i new)
12869       (decf i))
12870     (if (not new)
12871         (message "No gnus is bad news")
12872       (gnus-summary-insert-articles new)
12873       (setq gnus-newsgroup-unreads
12874             (gnus-sorted-nunion gnus-newsgroup-unreads new))
12875       (gnus-summary-limit (gnus-sorted-nunion old new))))
12876   (gnus-summary-position-point))
12877
12878 ;;; Bookmark support for Gnus.
12879 (declare-function bookmark-make-record-default
12880                   "bookmark" (&optional no-file no-context posn))
12881 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
12882 (declare-function bookmark-default-handler "bookmark" (bmk))
12883 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
12884 (defvar bookmark-yank-point)
12885 (defvar bookmark-current-buffer)
12886
12887 (defun gnus-summary-bookmark-make-record ()
12888   "Make a bookmark entry for a Gnus summary buffer."
12889   (let (pos buf)
12890     (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
12891       (save-restriction              ; FIXME is it necessary to widen?
12892         (widen) (setq pos (point))) ; Set position in gnus-article buffer.
12893       (setq buf "art") ; We are recording bookmark from article buffer.
12894       (setq bookmark-yank-point (point))
12895       (setq bookmark-current-buffer (current-buffer))
12896       (gnus-article-show-summary))      ; Go back in summary buffer.
12897     ;; We are now recording bookmark from summary buffer.
12898     (unless buf (setq buf "sum"))
12899     (let* ((subject (elt (gnus-summary-article-header) 1))
12900            (grp     (car gnus-article-current))
12901            (art     (cdr gnus-article-current))
12902            (head    (gnus-summary-article-header art))
12903            (id      (mail-header-id head)))
12904       `(,subject
12905         ,@(condition-case nil
12906               (bookmark-make-record-default 'no-file 'no-context pos)
12907             (wrong-number-of-arguments
12908              (bookmark-make-record-default 'point-only)))
12909         (location . ,(format "Gnus-%s %s:%d:%s" buf grp art id))
12910         (group . ,grp) (article . ,art)
12911         (message-id . ,id) (handler . gnus-summary-bookmark-jump)))))
12912
12913 ;;;###autoload
12914 (defun gnus-summary-bookmark-jump (bookmark)
12915   "Handler function for record returned by `gnus-summary-bookmark-make-record'.
12916 BOOKMARK is a bookmark name or a bookmark record."
12917   (let ((group    (bookmark-prop-get bookmark 'group))
12918         (article  (bookmark-prop-get bookmark 'article))
12919         (id       (bookmark-prop-get bookmark 'message-id))
12920         (buf      (car (split-string (bookmark-prop-get bookmark 'location)))))
12921     (gnus-fetch-group group (list article))
12922     (gnus-summary-insert-cached-articles)
12923     (gnus-summary-goto-article id nil 'force)
12924     ;; FIXME we have to wait article buffer is ready (only large buffer)
12925     ;; Is there a better solution to know that?
12926     ;; If we don't wait `bookmark-default-handler' will have no chance
12927     ;; to set position. However there is no error, just wrong pos.
12928     (sit-for 1)
12929     (when (string= buf "Gnus-art")
12930       (other-window 1))
12931     (bookmark-default-handler
12932      `(""
12933        (buffer . ,(current-buffer))
12934        . ,(bookmark-get-bookmark-record bookmark)))))
12935
12936 (gnus-summary-make-all-marking-commands)
12937
12938 (gnus-ems-redefine)
12939
12940 (provide 'gnus-sum)
12941
12942 (run-hooks 'gnus-sum-load-hook)
12943
12944 ;; Local Variables:
12945 ;; coding: iso-8859-1
12946 ;; End:
12947
12948 ;;; gnus-sum.el ends here