file new.xpm was added on branch t-gnus-6_17 on 2006-04-11 22:59:16 +0000
[elisp/gnus.git-] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;;         MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;;         Katsumi Yamaoka  <yamaoka@jpl.org>
8 ;; Keywords: mail, news, MIME
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;;; Code:
30
31 (eval-when-compile
32   (require 'cl)
33   (defvar tool-bar-map))
34
35 (require 'gnus)
36 (require 'gnus-group)
37 (require 'gnus-spec)
38 (require 'gnus-range)
39 (require 'gnus-int)
40 (require 'gnus-undo)
41 (require 'gnus-util)
42 (require 'nnoo)
43
44 (eval-when-compile
45   (require 'mime-play)
46   (require 'static))
47
48 (eval-and-compile
49   (autoload 'pgg-decrypt-region "pgg" nil t)
50   (autoload 'pgg-verify-region "pgg" nil t))
51
52 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
53 (autoload 'gnus-cache-write-active "gnus-cache")
54 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
55 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
56 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
57 (autoload 'mm-uu-dissect "mm-uu")
58 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
59   "Deuglify broken Outlook (Express) articles and redisplay."
60   t)
61 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
62 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
63 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
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-fetch-old-headers nil
73   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
74 If an unread article in the group refers to an older, already read (or
75 just marked as read) article, the old article will not normally be
76 displayed in the Summary buffer.  If this variable is t, Gnus
77 will attempt to grab the headers to the old articles, and thereby
78 build complete threads.  If it has the value `some', only enough
79 headers to connect otherwise loose threads will be displayed.  This
80 variable can also be a number.  In that case, no more than that number
81 of old headers will be fetched.  If it has the value `invisible', all
82 old headers will be fetched, but none will be displayed.
83
84 The server has to support NOV for any of this to work."
85   :group 'gnus-thread
86   :type '(choice (const :tag "off" nil)
87                  (const :tag "on" t)
88                  (const some)
89                  (const invisible)
90                  number
91                  (sexp :menu-tag "other" t)))
92
93 (defcustom gnus-refer-thread-limit 200
94   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
95 If t, fetch all the available old headers."
96   :group 'gnus-thread
97   :type '(choice number
98                  (sexp :menu-tag "other" t)))
99
100 (defcustom gnus-summary-make-false-root 'adopt
101   "*nil means that Gnus won't gather loose threads.
102 If the root of a thread has expired or been read in a previous
103 session, the information necessary to build a complete thread has been
104 lost.  Instead of having many small sub-threads from this original thread
105 scattered all over the summary buffer, Gnus can gather them.
106
107 If non-nil, Gnus will try to gather all loose sub-threads from an
108 original thread into one large thread.
109
110 If this variable is non-nil, it should be one of `none', `adopt',
111 `dummy' or `empty'.
112
113 If this variable is `none', Gnus will not make a false root, but just
114 present the sub-threads after another.
115 If this variable is `dummy', Gnus will create a dummy root that will
116 have all the sub-threads as children.
117 If this variable is `adopt', Gnus will make one of the \"children\"
118 the parent and mark all the step-children as such.
119 If this variable is `empty', the \"children\" are printed with empty
120 subject fields.  (Or rather, they will be printed with a string
121 given by the `gnus-summary-same-subject' variable.)"
122   :group 'gnus-thread
123   :type '(choice (const :tag "off" nil)
124                  (const none)
125                  (const dummy)
126                  (const adopt)
127                  (const empty)))
128
129 (defcustom gnus-summary-make-false-root-always nil
130   "Always make a false dummy root."
131   :version "22.1"
132   :group 'gnus-thread
133   :type 'boolean)
134
135 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
136   "*A regexp to match subjects to be excluded from loose thread gathering.
137 As loose thread gathering is done on subjects only, that means that
138 there can be many false gatherings performed.  By rooting out certain
139 common subjects, gathering might become saner."
140   :group 'gnus-thread
141   :type 'regexp)
142
143 (defcustom gnus-summary-gather-subject-limit nil
144   "*Maximum length of subject comparisons when gathering loose threads.
145 Use nil to compare full subjects.  Setting this variable to a low
146 number will help gather threads that have been corrupted by
147 newsreaders chopping off subject lines, but it might also mean that
148 unrelated articles that have subject that happen to begin with the
149 same few characters will be incorrectly gathered.
150
151 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
152 comparing subjects."
153   :group 'gnus-thread
154   :type '(choice (const :tag "off" nil)
155                  (const fuzzy)
156                  (sexp :menu-tag "on" t)))
157
158 (defcustom gnus-simplify-subject-functions nil
159   "List of functions taking a string argument that simplify subjects.
160 The functions are applied recursively.
161
162 Useful functions to put in this list include:
163 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
164 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
165   :group 'gnus-thread
166   :type '(repeat function))
167
168 (defcustom gnus-simplify-ignored-prefixes nil
169   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
170   :group 'gnus-thread
171   :type '(choice (const :tag "off" nil)
172                  regexp))
173
174 (defcustom gnus-build-sparse-threads nil
175   "*If non-nil, fill in the gaps in threads.
176 If `some', only fill in the gaps that are needed to tie loose threads
177 together.  If `more', fill in all leaf nodes that Gnus can find.  If
178 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
179   :group 'gnus-thread
180   :type '(choice (const :tag "off" nil)
181                  (const some)
182                  (const more)
183                  (sexp :menu-tag "all" t)))
184
185 (defcustom gnus-summary-thread-gathering-function
186   'gnus-gather-threads-by-subject
187   "*Function used for gathering loose threads.
188 There are two pre-defined functions: `gnus-gather-threads-by-subject',
189 which only takes Subjects into consideration; and
190 `gnus-gather-threads-by-references', which compared the References
191 headers of the articles to find matches."
192   :group 'gnus-thread
193   :type '(radio (function-item gnus-gather-threads-by-subject)
194                 (function-item gnus-gather-threads-by-references)
195                 (function :tag "other")))
196
197 (defcustom gnus-summary-same-subject ""
198   "*String indicating that the current article has the same subject as the previous.
199 This variable will only be used if the value of
200 `gnus-summary-make-false-root' is `empty'."
201   :group 'gnus-summary-format
202   :type 'string)
203
204 (defcustom gnus-summary-goto-unread t
205   "*If t, many commands will go to the next unread article.
206 This applies to marking commands as well as other commands that
207 \"naturally\" select the next article, like, for instance, `SPC' at
208 the end of an article.
209
210 If nil, the marking commands do NOT go to the next unread article
211 \(they go to the next article instead).  If `never', commands that
212 usually go to the next unread article, will go to the next article,
213 whether it is read or not."
214   :group 'gnus-summary-marks
215   :link '(custom-manual "(gnus)Setting Marks")
216   :type '(choice (const :tag "off" nil)
217                  (const never)
218                  (sexp :menu-tag "on" t)))
219
220 (defcustom gnus-summary-default-score 0
221   "*Default article score level.
222 All scores generated by the score files will be added to this score.
223 If this variable is nil, scoring will be disabled."
224   :group 'gnus-score-default
225   :type '(choice (const :tag "disable")
226                  integer))
227
228 (defcustom gnus-summary-default-high-score 0
229   "*Default threshold for a high scored article.
230 An article will be highlighted as high scored if its score is greater
231 than this score."
232   :version "22.1"
233   :group 'gnus-score-default
234   :type 'integer)
235
236 (defcustom gnus-summary-default-low-score 0
237   "*Default threshold for a low scored article.
238 An article will be highlighted as low scored if its score is smaller
239 than this score."
240   :version "22.1"
241   :group 'gnus-score-default
242   :type 'integer)
243
244 (defcustom gnus-summary-zcore-fuzz 0
245   "*Fuzziness factor for the zcore in the summary buffer.
246 Articles with scores closer than this to `gnus-summary-default-score'
247 will not be marked."
248   :group 'gnus-summary-format
249   :type 'integer)
250
251 (defcustom gnus-simplify-subject-fuzzy-regexp nil
252   "*Strings to be removed when doing fuzzy matches.
253 This can either be a regular expression or list of regular expressions
254 that will be removed from subject strings if fuzzy subject
255 simplification is selected."
256   :group 'gnus-thread
257   :type '(repeat regexp))
258
259 (defcustom gnus-show-threads t
260   "*If non-nil, display threads in summary mode."
261   :group 'gnus-thread
262   :type 'boolean)
263
264 (defcustom gnus-thread-hide-subtree nil
265   "*If non-nil, hide all threads initially.
266 This can be a predicate specifier which says which threads to hide.
267 If threads are hidden, you have to run the command
268 `gnus-summary-show-thread' by hand or use `gnus-select-article-hook'
269 to expose hidden threads."
270   :group 'gnus-thread
271   :type '(radio (sexp :format "Non-nil\n"
272                       :match (lambda (widget value)
273                                (not (or (consp value) (functionp value))))
274                       :value t)
275                 (const nil)
276                 (sexp :tag "Predicate specifier")))
277
278 (defcustom gnus-thread-hide-killed t
279   "*If non-nil, hide killed threads automatically."
280   :group 'gnus-thread
281   :type 'boolean)
282
283 (defcustom gnus-thread-ignore-subject t
284   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
285 If nil, articles that have different subjects from their parents will
286 start separate threads."
287   :group 'gnus-thread
288   :type 'boolean)
289
290 (defcustom gnus-thread-operation-ignore-subject t
291   "*If non-nil, subjects will be ignored when doing thread commands.
292 This affects commands like `gnus-summary-kill-thread' and
293 `gnus-summary-lower-thread'.
294
295 If this variable is nil, articles in the same thread with different
296 subjects will not be included in the operation in question.  If this
297 variable is `fuzzy', only articles that have subjects that are fuzzily
298 equal will be included."
299   :group 'gnus-thread
300   :type '(choice (const :tag "off" nil)
301                  (const fuzzy)
302                  (sexp :tag "on" t)))
303
304 (defcustom gnus-thread-indent-level 4
305   "*Number that says how much each sub-thread should be indented."
306   :group 'gnus-thread
307   :type 'integer)
308
309 (defcustom gnus-auto-extend-newsgroup t
310   "*If non-nil, extend newsgroup forward and backward when requested."
311   :group 'gnus-summary-choose
312   :type 'boolean)
313
314 (defcustom gnus-auto-select-first t
315   "*If non-nil, select the article under point.
316 Which article this is is controlled by the `gnus-auto-select-subject'
317 variable.
318
319 If you want to prevent automatic selection of articles in some
320 newsgroups, set the variable to nil in `gnus-select-group-hook'."
321   :group 'gnus-group-select
322   :type '(choice (const :tag "none" nil)
323                  (sexp :menu-tag "first" t)))
324
325 (defcustom gnus-auto-select-subject 'unread
326   "*Says what subject to place under point when entering a group.
327
328 This variable can either be the symbols `first' (place point on the
329 first subject), `unread' (place point on the subject line of the first
330 unread article), `best' (place point on the subject line of the
331 higest-scored article), `unseen' (place point on the subject line of
332 the first unseen article), 'unseen-or-unread' (place point on the subject
333 line of the first unseen article or, if all article have been seen, on the
334 subject line of the first unread article), or a function to be called to
335 place point on some subject line."
336   :version "22.1"
337   :group 'gnus-group-select
338   :type '(choice (const best)
339                  (const unread)
340                  (const first)
341                  (const unseen)
342                  (const unseen-or-unread)))
343
344 (defcustom gnus-dont-select-after-jump-to-other-group nil
345   "If non-nil, don't select the first unread article after entering the
346 other group by the command `gnus-summary-jump-to-other-group'.  If nil,
347 it is depend on the value of `gnus-auto-select-first' whether to select
348 or not."
349   :group 'gnus-group-select
350   :type 'boolean)
351
352 (defcustom gnus-auto-select-next t
353   "*If non-nil, offer to go to the next group from the end of the previous.
354 If the value is t and the next newsgroup is empty, Gnus will exit
355 summary mode and go back to group mode.  If the value is neither nil
356 nor t, Gnus will select the following unread newsgroup.  In
357 particular, if the value is the symbol `quietly', the next unread
358 newsgroup will be selected without any confirmation, and if it is
359 `almost-quietly', the next group will be selected without any
360 confirmation if you are located on the last article in the group.
361 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
362 will go to the next group without confirmation."
363   :group 'gnus-summary-maneuvering
364   :type '(choice (const :tag "off" nil)
365                  (const quietly)
366                  (const almost-quietly)
367                  (const slightly-quietly)
368                  (sexp :menu-tag "on" t)))
369
370 (defcustom gnus-auto-select-same nil
371   "*If non-nil, select the next article with the same subject.
372 If there are no more articles with the same subject, go to
373 the first unread article."
374   :group 'gnus-summary-maneuvering
375   :type 'boolean)
376
377 (defcustom gnus-auto-goto-ignores 'unfetched
378   "*Says how to handle unfetched articles when maneuvering.
379
380 This variable can either be the symbols nil (maneuver to any
381 article), `undownloaded' (maneuvering while unplugged ignores articles
382 that have not been fetched), `always-undownloaded' (maneuvering always
383 ignores articles that have not been fetched), `unfetched' (maneuvering
384 ignores articles whose headers have not been fetched).
385
386 NOTE: The list of unfetched articles will always be nil when plugged
387 and, when unplugged, a subset of the undownloaded article list."
388   :version "22.1"
389   :group 'gnus-summary-maneuvering
390   :type '(choice (const :tag "None" nil)
391                  (const :tag "Undownloaded when unplugged" undownloaded)
392                  (const :tag "Undownloaded" always-undownloaded)
393                  (const :tag "Unfetched" unfetched)))
394
395 (defcustom gnus-summary-check-current nil
396   "*If non-nil, consider the current article when moving.
397 The \"unread\" movement commands will stay on the same line if the
398 current article is unread."
399   :group 'gnus-summary-maneuvering
400   :type 'boolean)
401
402 (defcustom gnus-auto-center-summary 2
403   "*If non-nil, always center the current summary buffer.
404 In particular, if `vertical' do only vertical recentering.  If non-nil
405 and non-`vertical', do both horizontal and vertical recentering."
406   :group 'gnus-summary-maneuvering
407   :type '(choice (const :tag "none" nil)
408                  (const vertical)
409                  (integer :tag "height")
410                  (sexp :menu-tag "both" t)))
411
412 (defvar gnus-auto-center-group t
413   "*If non-nil, always center the group buffer.")
414
415 (defcustom gnus-show-all-headers nil
416   "*If non-nil, don't hide any headers."
417   :group 'gnus-article-hiding
418   :group 'gnus-article-headers
419   :type 'boolean)
420
421 (defcustom gnus-summary-ignore-duplicates nil
422   "*If non-nil, ignore articles with identical Message-ID headers."
423   :group 'gnus-summary
424   :type 'boolean)
425
426 (defcustom gnus-single-article-buffer t
427   "*If non-nil, display all articles in the same buffer.
428 If nil, each group will get its own article buffer."
429   :group 'gnus-article-various
430   :type 'boolean)
431
432 (defcustom gnus-break-pages t
433   "*If non-nil, do page breaking on articles.
434 The page delimiter is specified by the `gnus-page-delimiter'
435 variable."
436   :group 'gnus-article-various
437   :type 'boolean)
438
439 (defcustom gnus-show-mime t
440   "*If non-nil, do mime processing of articles.
441 The articles will simply be fed to the function given by
442 `gnus-article-display-method-for-mime'."
443   :group 'gnus-article-mime
444   :type 'boolean)
445
446 (defcustom gnus-move-split-methods nil
447   "*Variable used to suggest where articles are to be moved to.
448 It uses the same syntax as the `gnus-split-methods' variable.
449 However, whereas `gnus-split-methods' specifies file names as targets,
450 this variable specifies group names."
451   :group 'gnus-summary-mail
452   :type '(repeat (choice (list :value (fun) function)
453                          (cons :value ("" "") regexp (repeat string))
454                          (sexp :value nil))))
455
456 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
457   "Function used to compute default prefix for article move/copy/etc prompts.
458 The function should take one argument, a group name, and return a
459 string with the suggested prefix."
460   :group 'gnus-summary-mail
461   :type 'function)
462
463 ;; FIXME: Although the custom type is `character' for the following variables,
464 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
465
466 (defcustom gnus-unread-mark ?\ ;;;Whitespace
467   "*Mark used for unread articles."
468   :group 'gnus-summary-marks
469   :type 'character)
470
471 (defcustom gnus-ticked-mark ?!
472   "*Mark used for ticked articles."
473   :group 'gnus-summary-marks
474   :type 'character)
475
476 (defcustom gnus-dormant-mark ??
477   "*Mark used for dormant articles."
478   :group 'gnus-summary-marks
479   :type 'character)
480
481 (defcustom gnus-del-mark ?r
482   "*Mark used for del'd articles."
483   :group 'gnus-summary-marks
484   :type 'character)
485
486 (defcustom gnus-read-mark ?R
487   "*Mark used for read articles."
488   :group 'gnus-summary-marks
489   :type 'character)
490
491 (defcustom gnus-expirable-mark ?E
492   "*Mark used for expirable articles."
493   :group 'gnus-summary-marks
494   :type 'character)
495
496 (defcustom gnus-killed-mark ?K
497   "*Mark used for killed articles."
498   :group 'gnus-summary-marks
499   :type 'character)
500
501 (defcustom gnus-spam-mark ?$
502   "*Mark used for spam articles."
503   :version "22.1"
504   :group 'gnus-summary-marks
505   :type 'character)
506
507 (defcustom gnus-souped-mark ?F
508   "*Mark used for souped articles."
509   :group 'gnus-summary-marks
510   :type 'character)
511
512 (defcustom gnus-kill-file-mark ?X
513   "*Mark used for articles killed by kill files."
514   :group 'gnus-summary-marks
515   :type 'character)
516
517 (defcustom gnus-low-score-mark ?Y
518   "*Mark used for articles with a low score."
519   :group 'gnus-summary-marks
520   :type 'character)
521
522 (defcustom gnus-catchup-mark ?C
523   "*Mark used for articles that are caught up."
524   :group 'gnus-summary-marks
525   :type 'character)
526
527 (defcustom gnus-replied-mark ?A
528   "*Mark used for articles that have been replied to."
529   :group 'gnus-summary-marks
530   :type 'character)
531
532 (defcustom gnus-forwarded-mark ?F
533   "*Mark used for articles that have been forwarded."
534   :version "22.1"
535   :group 'gnus-summary-marks
536   :type 'character)
537
538 (defcustom gnus-recent-mark ?N
539   "*Mark used for articles that are recent."
540   :version "22.1"
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-cached-mark ?*
545   "*Mark used for articles that are in the cache."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-saved-mark ?S
550   "*Mark used for articles that have been saved."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-unseen-mark ?.
555   "*Mark used for articles that haven't been seen."
556   :version "22.1"
557   :group 'gnus-summary-marks
558   :type 'character)
559
560 (defcustom gnus-no-mark ?\ ;;;Whitespace
561   "*Mark used for articles that have no other secondary mark."
562   :version "22.1"
563   :group 'gnus-summary-marks
564   :type 'character)
565
566 (defcustom gnus-ancient-mark ?O
567   "*Mark used for ancient articles."
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-sparse-mark ?Q
572   "*Mark used for sparsely reffed articles."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-canceled-mark ?G
577   "*Mark used for canceled articles."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-duplicate-mark ?M
582   "*Mark used for duplicate articles."
583   :group 'gnus-summary-marks
584   :type 'character)
585
586 (defcustom gnus-undownloaded-mark ?-
587   "*Mark used for articles that weren't downloaded."
588   :version "22.1"
589   :group 'gnus-summary-marks
590   :type 'character)
591
592 (defcustom gnus-downloaded-mark ?+
593   "*Mark used for articles that were downloaded."
594   :group 'gnus-summary-marks
595   :type 'character)
596
597 (defcustom gnus-downloadable-mark ?%
598   "*Mark used for articles that are to be downloaded."
599   :group 'gnus-summary-marks
600   :type 'character)
601
602 (defcustom gnus-unsendable-mark ?=
603   "*Mark used for articles that won't be sent."
604   :group 'gnus-summary-marks
605   :type 'character)
606
607 (defcustom gnus-score-over-mark ?+
608   "*Score mark used for articles with high scores."
609   :group 'gnus-summary-marks
610   :type 'character)
611
612 (defcustom gnus-score-below-mark ?-
613   "*Score mark used for articles with low scores."
614   :group 'gnus-summary-marks
615   :type 'character)
616
617 (defcustom gnus-empty-thread-mark ?\ ;;;Whitespace
618   "*There is no thread under the article."
619   :group 'gnus-summary-marks
620   :type 'character)
621
622 (defcustom gnus-not-empty-thread-mark ?=
623   "*There is a thread under the article."
624   :group 'gnus-summary-marks
625   :type 'character)
626
627 (defcustom gnus-view-pseudo-asynchronously nil
628   "*If non-nil, Gnus will view pseudo-articles asynchronously."
629   :group 'gnus-extract-view
630   :type 'boolean)
631
632 (defcustom gnus-auto-expirable-marks
633   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
634         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
635         gnus-souped-mark gnus-duplicate-mark)
636   "*The list of marks converted into expiration if a group is auto-expirable."
637   :version "21.1"
638   :group 'gnus-summary
639   :type '(repeat character))
640
641 (defcustom gnus-inhibit-user-auto-expire t
642   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
643   :version "21.1"
644   :group 'gnus-summary
645   :type 'boolean)
646
647 (defcustom gnus-view-pseudos nil
648   "*If `automatic', pseudo-articles will be viewed automatically.
649 If `not-confirm', pseudos will be viewed automatically, and the user
650 will not be asked to confirm the command."
651   :group 'gnus-extract-view
652   :type '(choice (const :tag "off" nil)
653                  (const automatic)
654                  (const not-confirm)))
655
656 (defcustom gnus-view-pseudos-separately t
657   "*If non-nil, one pseudo-article will be created for each file to be viewed.
658 If nil, all files that use the same viewing command will be given as a
659 list of parameters to that command."
660   :group 'gnus-extract-view
661   :type 'boolean)
662
663 (defcustom gnus-insert-pseudo-articles t
664   "*If non-nil, insert pseudo-articles when decoding articles."
665   :group 'gnus-extract-view
666   :type 'boolean)
667
668 (defcustom gnus-summary-dummy-line-format
669   "   %(:                             :%) %S\n"
670   "*The format specification for the dummy roots in the summary buffer.
671 It works along the same lines as a normal formatting string,
672 with some simple extensions.
673
674 %S  The subject
675
676 General format specifiers can also be used.
677 See `(gnus)Formatting Variables'."
678   :link '(custom-manual "(gnus)Formatting Variables")
679   :group 'gnus-threading
680   :type 'string)
681
682 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
683   "*The format specification for the summary mode line.
684 It works along the same lines as a normal formatting string,
685 with some simple extensions:
686
687 %G  Group name
688 %p  Unprefixed group name
689 %A  Current article number
690 %z  Current article score
691 %V  Gnus version
692 %U  Number of unread articles in the group
693 %e  Number of unselected articles in the group
694 %Z  A string with unread/unselected article counts
695 %g  Shortish group name
696 %S  Subject of the current article
697 %u  User-defined spec
698 %s  Current score file name
699 %d  Number of dormant articles
700 %r  Number of articles that have been marked as read in this session
701 %E  Number of articles expunged by the score files"
702   :group 'gnus-summary-format
703   :type 'string)
704
705 (defcustom gnus-list-identifiers nil
706   "Regexp that matches list identifiers to be removed from subject.
707 This can also be a list of regexps."
708   :version "21.1"
709   :group 'gnus-summary-format
710   :group 'gnus-article-hiding
711   :type '(choice (const :tag "none" nil)
712                  (regexp :value ".*")
713                  (repeat :value (".*") regexp)))
714
715 (defcustom gnus-summary-mark-below 0
716   "*Mark all articles with a score below this variable as read.
717 This variable is local to each summary buffer and usually set by the
718 score file."
719   :group 'gnus-score-default
720   :type 'integer)
721
722 (defun gnus-widget-reversible-match (widget value)
723   "Ignoring WIDGET, convert VALUE to internal form.
724 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
725   ;; (debug value)
726   (or (symbolp value)
727       (and (listp value)
728            (eq (length value) 2)
729            (eq (nth 0 value) 'not)
730            (symbolp (nth 1 value)))))
731
732 (defun gnus-widget-reversible-to-internal (widget value)
733   "Ignoring WIDGET, convert VALUE to internal form.
734 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
735 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
736   ;; (debug value)
737   (if (atom value)
738       (list value nil)
739     (list (nth 1 value) t)))
740
741 (defun gnus-widget-reversible-to-external (widget value)
742   "Ignoring WIDGET, convert VALUE to external form.
743 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
744 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
745   ;; (debug value)
746   (if (nth 1 value)
747       (list 'not (nth 0 value))
748     (nth 0 value)))
749
750 (define-widget 'gnus-widget-reversible 'group
751   "A `group' that convert values."
752   :match 'gnus-widget-reversible-match
753   :value-to-internal 'gnus-widget-reversible-to-internal
754   :value-to-external 'gnus-widget-reversible-to-external)
755
756 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
757   "*List of functions used for sorting articles in the summary buffer.
758
759 Each function takes two articles and returns non-nil if the first
760 article should be sorted before the other.  If you use more than one
761 function, the primary sort function should be the last.  You should
762 probably always include `gnus-article-sort-by-number' in the list of
763 sorting functions -- preferably first.  Also note that sorting by date
764 is often much slower than sorting by number, and the sorting order is
765 very similar.  (Sorting by date means sorting by the time the message
766 was sent, sorting by number means sorting by arrival time.)
767
768 Each item can also be a list `(not F)' where F is a function;
769 this reverses the sort order.
770
771 Ready-made functions include `gnus-article-sort-by-number',
772 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
773 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
774 and `gnus-article-sort-by-score'.
775
776 When threading is turned on, the variable `gnus-thread-sort-functions'
777 controls how articles are sorted."
778   :group 'gnus-summary-sort
779   :type '(repeat (gnus-widget-reversible
780                   (choice (function-item gnus-article-sort-by-number)
781                           (function-item gnus-article-sort-by-author)
782                           (function-item gnus-article-sort-by-subject)
783                           (function-item gnus-article-sort-by-date)
784                           (function-item gnus-article-sort-by-score)
785                           (function-item gnus-article-sort-by-random)
786                           (function :tag "other"))
787                   (boolean :tag "Reverse order"))))
788
789
790 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
791   "*List of functions used for sorting threads in the summary buffer.
792 By default, threads are sorted by article number.
793
794 Each function takes two threads and returns non-nil if the first
795 thread should be sorted before the other.  If you use more than one
796 function, the primary sort function should be the last.  You should
797 probably always include `gnus-thread-sort-by-number' in the list of
798 sorting functions -- preferably first.  Also note that sorting by date
799 is often much slower than sorting by number, and the sorting order is
800 very similar.  (Sorting by date means sorting by the time the message
801 was sent, sorting by number means sorting by arrival time.)
802
803 Each list item can also be a list `(not F)' where F is a
804 function; this specifies reversed sort order.
805
806 Ready-made functions include `gnus-thread-sort-by-number',
807 `gnus-thread-sort-by-author', `gnus-thread-sort-by-subject',
808 `gnus-thread-sort-by-date', `gnus-thread-sort-by-score',
809 `gnus-thread-sort-by-most-recent-number',
810 `gnus-thread-sort-by-most-recent-date',
811 `gnus-thread-sort-by-random', and
812 `gnus-thread-sort-by-total-score' (see `gnus-thread-score-function').
813
814 When threading is turned off, the variable
815 `gnus-article-sort-functions' controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat 
818           (gnus-widget-reversible
819            (choice (function-item gnus-thread-sort-by-number)
820                    (function-item gnus-thread-sort-by-author)
821                    (function-item gnus-thread-sort-by-subject)
822                    (function-item gnus-thread-sort-by-date)
823                    (function-item gnus-thread-sort-by-score)
824                    (function-item gnus-thread-sort-by-most-recent-number)
825                    (function-item gnus-thread-sort-by-most-recent-date)
826                    (function-item gnus-thread-sort-by-random)
827                    (function-item gnus-thread-sort-by-total-score)
828                    (function :tag "other"))
829            (boolean :tag "Reverse order"))))
830
831 (defcustom gnus-thread-score-function '+
832   "*Function used for calculating the total score of a thread.
833
834 The function is called with the scores of the article and each
835 subthread and should then return the score of the thread.
836
837 Some functions you can use are `+', `max', or `min'."
838   :group 'gnus-summary-sort
839   :type 'function)
840
841 (defcustom gnus-summary-expunge-below nil
842   "All articles that have a score less than this variable will be expunged.
843 This variable is local to the summary buffers."
844   :group 'gnus-score-default
845   :type '(choice (const :tag "off" nil)
846                  integer))
847
848 (defcustom gnus-thread-expunge-below nil
849   "All threads that have a total score less than this variable will be expunged.
850 See `gnus-thread-score-function' for en explanation of what a
851 \"thread score\" is.
852
853 This variable is local to the summary buffers."
854   :group 'gnus-threading
855   :group 'gnus-score-default
856   :type '(choice (const :tag "off" nil)
857                  integer))
858
859 (defcustom gnus-summary-mode-hook nil
860   "*A hook for Gnus summary mode.
861 This hook is run before any variables are set in the summary buffer."
862   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
863   :group 'gnus-summary-various
864   :type 'hook)
865
866 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
867 (when (featurep 'xemacs)
868   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
869   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
870   (add-hook 'gnus-summary-mode-hook
871             'gnus-xmas-switch-horizontal-scrollbar-off))
872
873 (defcustom gnus-summary-menu-hook nil
874   "*Hook run after the creation of the summary mode menu."
875   :group 'gnus-summary-visual
876   :type 'hook)
877
878 (defcustom gnus-summary-exit-hook nil
879   "*A hook called on exit from the summary buffer.
880 It will be called with point in the group buffer."
881   :group 'gnus-summary-exit
882   :type 'hook)
883
884 (defcustom gnus-summary-prepare-hook nil
885   "*A hook called after the summary buffer has been generated.
886 If you want to modify the summary buffer, you can use this hook."
887   :group 'gnus-summary-various
888   :type 'hook)
889
890 (defcustom gnus-summary-prepared-hook nil
891   "*A hook called as the last thing after the summary buffer has been generated."
892   :group 'gnus-summary-various
893   :type 'hook)
894
895 (defcustom gnus-summary-generate-hook nil
896   "*A hook run just before generating the summary buffer.
897 This hook is commonly used to customize threading variables and the
898 like."
899   :group 'gnus-summary-various
900   :type 'hook)
901
902 (defcustom gnus-select-group-hook nil
903   "*A hook called when a newsgroup is selected.
904
905 If you'd like to simplify subjects like the
906 `gnus-summary-next-same-subject' command does, you can use the
907 following hook:
908
909  (add-hook gnus-select-group-hook
910            (lambda ()
911              (mapcar (lambda (header)
912                        (mail-header-set-subject
913                         header
914                         (gnus-simplify-subject
915                          (mail-header-subject header) 're-only)))
916                      gnus-newsgroup-headers)))"
917   :group 'gnus-group-select
918   :type 'hook)
919
920 (defcustom gnus-select-article-hook nil
921   "*A hook called when an article is selected."
922   :group 'gnus-summary-choose
923   :options '(gnus-agent-fetch-selected-article)
924   :type 'hook)
925
926 (defcustom gnus-visual-mark-article-hook
927   (list 'gnus-highlight-selected-summary)
928   "*Hook run after selecting an article in the summary buffer.
929 It is meant to be used for highlighting the article in some way.  It
930 is not run if `gnus-visual' is nil."
931   :group 'gnus-summary-visual
932   :type 'hook)
933
934 (defcustom gnus-parse-headers-hook '(gnus-summary-inherit-default-charset)
935   "*A hook called before parsing the headers."
936   :group 'gnus-various
937   :type 'hook)
938
939 (defcustom gnus-exit-group-hook nil
940   "*A hook called when exiting summary mode.
941 This hook is not called from the non-updating exit commands like `Q'."
942   :group 'gnus-various
943   :type 'hook)
944
945 (defcustom gnus-summary-update-hook
946   (list 'gnus-summary-highlight-line)
947   "*A hook called when a summary line is changed.
948 The hook will not be called if `gnus-visual' is nil.
949
950 The default function `gnus-summary-highlight-line' will
951 highlight the line according to the `gnus-summary-highlight'
952 variable."
953   :group 'gnus-summary-visual
954   :type 'hook)
955
956 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
957   "*A hook called when an article is selected for the first time.
958 The hook is intended to mark an article as read (or unread)
959 automatically when it is selected."
960   :group 'gnus-summary-choose
961   :type 'hook)
962
963 (defcustom gnus-group-no-more-groups-hook nil
964   "*A hook run when returning to group mode having no more (unread) groups."
965   :group 'gnus-group-select
966   :type 'hook)
967
968 (defcustom gnus-ps-print-hook nil
969   "*A hook run before ps-printing something from Gnus."
970   :group 'gnus-summary
971   :type 'hook)
972
973 (defcustom gnus-summary-article-move-hook nil
974   "*A hook called after an article is moved, copied, respooled, or crossposted."
975   :version "22.1"
976   :group 'gnus-summary
977   :type 'hook)
978
979 (defcustom gnus-summary-article-delete-hook nil
980   "*A hook called after an article is deleted."
981   :version "22.1"
982   :group 'gnus-summary
983   :type 'hook)
984
985 (defcustom gnus-summary-article-expire-hook nil
986   "*A hook called after an article is expired."
987   :version "22.1"
988   :group 'gnus-summary
989   :type 'hook)
990
991 (defcustom gnus-summary-display-arrow
992   (and (fboundp 'display-graphic-p)
993        (display-graphic-p))
994   "*If non-nil, display an arrow highlighting the current article."
995   :version "22.1"
996   :group 'gnus-summary
997   :type 'boolean)
998
999 (defcustom gnus-summary-selected-face 'gnus-summary-selected-face
1000   "Face used for highlighting the current article in the summary buffer."
1001   :group 'gnus-summary-visual
1002   :type 'face)
1003
1004 (defvar gnus-tmp-downloaded nil)
1005
1006 (defcustom gnus-summary-highlight
1007   '(((eq mark gnus-canceled-mark)
1008      . gnus-summary-cancelled-face)
1009     ((and uncached (> score default-high))
1010      . gnus-summary-high-undownloaded-face)
1011     ((and uncached (< score default-low))
1012      . gnus-summary-low-undownloaded-face)
1013     (uncached
1014      . gnus-summary-normal-undownloaded-face)
1015     ((and (> score default-high)
1016           (or (eq mark gnus-dormant-mark)
1017               (eq mark gnus-ticked-mark)))
1018      . gnus-summary-high-ticked-face)
1019     ((and (< score default-low)
1020           (or (eq mark gnus-dormant-mark)
1021               (eq mark gnus-ticked-mark)))
1022      . gnus-summary-low-ticked-face)
1023     ((or (eq mark gnus-dormant-mark)
1024          (eq mark gnus-ticked-mark))
1025      . gnus-summary-normal-ticked-face)
1026     ((and (> score default-high) (eq mark gnus-ancient-mark))
1027      . gnus-summary-high-ancient-face)
1028     ((and (< score default-low) (eq mark gnus-ancient-mark))
1029      . gnus-summary-low-ancient-face)
1030     ((eq mark gnus-ancient-mark)
1031      . gnus-summary-normal-ancient-face)
1032     ((and (> score default-high) (eq mark gnus-unread-mark))
1033      . gnus-summary-high-unread-face)
1034     ((and (< score default-low) (eq mark gnus-unread-mark))
1035      . gnus-summary-low-unread-face)
1036     ((eq mark gnus-unread-mark)
1037      . gnus-summary-normal-unread-face)
1038     ((> score default-high)
1039      . gnus-summary-high-read-face)
1040     ((< score default-low)
1041      . gnus-summary-low-read-face)
1042     (t
1043      . gnus-summary-normal-read-face))
1044   "*Controls the highlighting of summary buffer lines.
1045
1046 A list of (FORM . FACE) pairs.  When deciding how a a particular
1047 summary line should be displayed, each form is evaluated.  The content
1048 of the face field after the first true form is used.  You can change
1049 how those summary lines are displayed, by editing the face field.
1050
1051 You can use the following variables in the FORM field.
1052
1053 score:        The article's score
1054 default:      The default article score.
1055 default-high: The default score for high scored articles.
1056 default-low:  The default score for low scored articles.
1057 below:        The score below which articles are automatically marked as read.
1058 mark:         The article's mark.
1059 uncached:     Non-nil if the article is uncached."
1060   :group 'gnus-summary-visual
1061   :type '(repeat (cons (sexp :tag "Form" nil)
1062                        face)))
1063
1064 (defcustom gnus-alter-header-function nil
1065   "Function called to allow alteration of article header structures.
1066 The function is called with one parameter, the article header vector,
1067 which it may alter in any way."
1068   :type '(choice (const :tag "None" nil)
1069                  function)
1070   :group 'gnus-summary)
1071
1072 (defvar gnus-decode-encoded-word-function
1073   (mime-find-field-decoder 'From 'nov)
1074   "Variable that says which function should be used to decode a string with encoded words.")
1075
1076 (defcustom gnus-extra-headers '(To Newsgroups)
1077   "*Extra headers to parse."
1078   :version "21.1"
1079   :group 'gnus-summary
1080   :type '(repeat symbol))
1081
1082 (defcustom gnus-ignored-from-addresses
1083   (and user-mail-address (regexp-quote user-mail-address))
1084   "*Regexp of From headers that may be suppressed in favor of To headers."
1085   :version "21.1"
1086   :group 'gnus-summary
1087   :type 'regexp)
1088
1089 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1090   "List of charsets that should be ignored.
1091 When these charsets are used in the \"charset\" parameter, the
1092 default charset will be used instead."
1093   :version "21.1"
1094   :type '(repeat symbol)
1095   :group 'gnus-charset)
1096
1097 (gnus-define-group-parameter
1098  ignored-charsets
1099  :type list
1100  :function-document
1101  "Return the ignored charsets of GROUP."
1102  :variable gnus-group-ignored-charsets-alist
1103  :variable-default
1104  '(("alt\\.chinese\\.text" iso-8859-1))
1105  :variable-document
1106  "Alist of regexps (to match group names) and charsets that should be ignored.
1107 When these charsets are used in the \"charset\" parameter, the
1108 default charset will be used instead."
1109  :variable-group gnus-charset
1110  :variable-type '(repeat (cons (regexp :tag "Group")
1111                                (repeat symbol)))
1112  :parameter-type '(choice :tag "Ignored charsets"
1113                           :value nil
1114                           (repeat (symbol)))
1115  :parameter-document       "\
1116 List of charsets that should be ignored.
1117
1118 When these charsets are used in the \"charset\" parameter, the
1119 default charset will be used instead.")
1120
1121 (defcustom gnus-group-highlight-words-alist nil
1122   "Alist of group regexps and highlight regexps.
1123 This variable uses the same syntax as `gnus-emphasis-alist'."
1124   :version "21.1"
1125   :type '(repeat (cons (regexp :tag "Group")
1126                        (repeat (list (regexp :tag "Highlight regexp")
1127                                      (number :tag "Group for entire word" 0)
1128                                      (number :tag "Group for displayed part" 0)
1129                                      (symbol :tag "Face"
1130                                              gnus-emphasis-highlight-words)))))
1131   :group 'gnus-summary-visual)
1132
1133 (defcustom gnus-use-wheel nil
1134   "Use Intelli-mouse on summary movement"
1135   :type 'boolean
1136   :group 'gnus-summary-maneuvering)
1137
1138 (defcustom gnus-wheel-scroll-amount '(5 . 1)
1139   "Amount to scroll messages by spinning the mouse wheel.
1140 This is actually a cons cell, where the first item is the amount to scroll
1141 on a normal wheel event, and the second is the amount to scroll when the
1142 wheel is moved with the shift key depressed."
1143   :type '(cons (integer :tag "Shift") integer)
1144   :group 'gnus-summary-maneuvering)
1145
1146 (defcustom gnus-wheel-edge-resistance 2
1147   "How hard it should be to change the current article
1148 by moving the mouse over the edge of the article window."
1149   :type 'integer
1150   :group 'gnus-summary-maneuvering)
1151
1152 (defcustom gnus-summary-show-article-charset-alist
1153   nil
1154   "Alist of number and charset.
1155 The article will be shown with the charset corresponding to the
1156 numbered argument.
1157 For example: ((1 . cn-gb-2312) (2 . big5))."
1158   :version "21.1"
1159   :type '(repeat (cons (number :tag "Argument" 1)
1160                        (symbol :tag "Charset")))
1161   :group 'gnus-charset)
1162
1163 (defcustom gnus-preserve-marks t
1164   "Whether marks are preserved when moving, copying and respooling messages."
1165   :version "21.1"
1166   :type 'boolean
1167   :group 'gnus-summary-marks)
1168
1169 (defcustom gnus-alter-articles-to-read-function nil
1170   "Function to be called to alter the list of articles to be selected."
1171   :type '(choice (const nil) function)
1172   :group 'gnus-summary)
1173
1174 (defcustom gnus-orphan-score nil
1175   "*All orphans get this score added.  Set in the score file."
1176   :group 'gnus-score-default
1177   :type '(choice (const nil)
1178                  integer))
1179
1180 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1181   "*A regexp to match MIME parts when saving multiple parts of a
1182 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1183 This regexp will be used by default when prompting the user for which
1184 type of files to save."
1185   :group 'gnus-summary
1186   :type 'regexp)
1187
1188 (defcustom gnus-read-all-available-headers nil
1189   "Whether Gnus should parse all headers made available to it.
1190 This is mostly relevant for slow back ends where the user may
1191 wish to widen the summary buffer to include all headers
1192 that were fetched.  Say, for nnultimate groups."
1193   :version "22.1"
1194   :group 'gnus-summary
1195   :type '(choice boolean regexp))
1196
1197 (defcustom gnus-summary-muttprint-program "muttprint"
1198   "Command (and optional arguments) used to run Muttprint."
1199   :version "22.1"
1200   :group 'gnus-summary
1201   :type 'string)
1202
1203 (defcustom gnus-article-loose-mime t
1204   "If non-nil, don't require MIME-Version header.
1205 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1206 supply the MIME-Version header or deliberately strip it from the mail.
1207 If non-nil (the default), Gnus will treat some articles as MIME
1208 even if the MIME-Version header is missing."
1209   :version "22.1"
1210   :type 'boolean
1211   :group 'gnus-article-mime)
1212
1213 (defcustom gnus-article-emulate-mime t
1214   "If non-nil, use MIME emulation for uuencode and the like.
1215 This means that Gnus will search message bodies for text that look
1216 like uuencoded bits, yEncoded bits, and so on, and present that using
1217 the normal Gnus MIME machinery."
1218   :version "22.1"
1219   :type 'boolean
1220   :group 'gnus-article-mime)
1221
1222 ;;; Internal variables
1223
1224 (defvar gnus-summary-display-cache nil)
1225 (defvar gnus-article-mime-handles nil)
1226 (defvar gnus-article-decoded-p nil)
1227 (defvar gnus-article-charset nil)
1228 (defvar gnus-article-ignored-charsets nil)
1229 (defvar gnus-scores-exclude-files nil)
1230 (defvar gnus-page-broken nil)
1231
1232 (defvar gnus-original-article nil)
1233 (defvar gnus-article-internal-prepare-hook nil)
1234 (defvar gnus-newsgroup-process-stack nil)
1235
1236 (defvar gnus-thread-indent-array nil)
1237 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1238 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1239   "Function called to sort the articles within a thread after it has been gathered together.")
1240
1241 (defvar gnus-summary-save-parts-type-history nil)
1242 (defvar gnus-summary-save-parts-last-directory nil)
1243
1244 ;; Avoid highlighting in kill files.
1245 (defvar gnus-summary-inhibit-highlight nil)
1246 (defvar gnus-newsgroup-selected-overlay nil)
1247 (defvar gnus-inhibit-limiting nil)
1248 (defvar gnus-newsgroup-adaptive-score-file nil)
1249 (defvar gnus-current-score-file nil)
1250 (defvar gnus-current-move-group nil)
1251 (defvar gnus-current-copy-group nil)
1252 (defvar gnus-current-crosspost-group nil)
1253 (defvar gnus-newsgroup-display nil)
1254
1255 (defvar gnus-newsgroup-dependencies nil)
1256 (defvar gnus-newsgroup-adaptive nil)
1257 (defvar gnus-summary-display-article-function nil)
1258 (defvar gnus-summary-highlight-line-function nil
1259   "Function called after highlighting a summary line.")
1260
1261 (defvar gnus-summary-line-format-alist
1262   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1263     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1264     (?s gnus-tmp-subject-or-nil ?s)
1265     (?n gnus-tmp-name ?s)
1266     (?A (std11-address-string
1267          (car (mime-entity-read-field gnus-tmp-header 'From))) ?s)
1268     (?a (or (std11-full-name-string
1269              (car (mime-entity-read-field gnus-tmp-header 'From)))
1270             gnus-tmp-from) ?s)
1271     (?F gnus-tmp-from ?s)
1272     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1273     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1274     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1275     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1276     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1277     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1278     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1279     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1280     (?L gnus-tmp-lines ?s)
1281     (?O gnus-tmp-downloaded ?c)
1282     (?I gnus-tmp-indentation ?s)
1283     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1284     (?R gnus-tmp-replied ?c)
1285     (?\[ gnus-tmp-opening-bracket ?c)
1286     (?\] gnus-tmp-closing-bracket ?c)
1287     (?\> (make-string gnus-tmp-level ? ) ?s)
1288     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1289     (?i gnus-tmp-score ?d)
1290     (?z gnus-tmp-score-char ?c)
1291     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1292     (?U gnus-tmp-unread ?c)
1293     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1294         ?s)
1295     (?t (gnus-summary-number-of-articles-in-thread
1296          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1297         ?d)
1298     (?e (gnus-summary-number-of-articles-in-thread
1299          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1300         ?c)
1301     (?u gnus-tmp-user-defined ?s)
1302     (?P (gnus-pick-line-number) ?d)
1303     (?B gnus-tmp-thread-tree-header-string ?s)
1304     (user-date (gnus-user-date
1305                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1306   "An alist of format specifications that can appear in summary lines.
1307 These are paired with what variables they correspond with, along with
1308 the type of the variable (string, integer, character, etc).")
1309
1310 (defvar gnus-summary-dummy-line-format-alist
1311   `((?S gnus-tmp-subject ?s)
1312     (?N gnus-tmp-number ?d)
1313     (?u gnus-tmp-user-defined ?s)))
1314
1315 (defvar gnus-summary-mode-line-format-alist
1316   `((?G gnus-tmp-group-name ?s)
1317     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1318     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1319     (?A gnus-tmp-article-number ?d)
1320     (?Z gnus-tmp-unread-and-unselected ?s)
1321     (?V gnus-version ?s)
1322     (?U gnus-tmp-unread-and-unticked ?d)
1323     (?S gnus-tmp-subject ?s)
1324     (?e gnus-tmp-unselected ?d)
1325     (?u gnus-tmp-user-defined ?s)
1326     (?d (length gnus-newsgroup-dormant) ?d)
1327     (?t (length gnus-newsgroup-marked) ?d)
1328     (?h (length gnus-newsgroup-spam-marked) ?d)
1329     (?r (length gnus-newsgroup-reads) ?d)
1330     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1331     (?E gnus-newsgroup-expunged-tally ?d)
1332     (?s (gnus-current-score-file-nondirectory) ?s)))
1333
1334 (defvar gnus-last-search-regexp nil
1335   "Default regexp for article search command.")
1336
1337 (defvar gnus-summary-search-article-matched-data nil
1338   "Last matched data of article search command.  It is the local variable
1339 in `gnus-article-buffer' which consists of the list of start position,
1340 end position and text.")
1341
1342 (defvar gnus-last-shell-command nil
1343   "Default shell command on article.")
1344
1345 (defvar gnus-newsgroup-agentized nil
1346   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1347 (defvar gnus-newsgroup-begin nil)
1348 (defvar gnus-newsgroup-end nil)
1349 (defvar gnus-newsgroup-last-rmail nil)
1350 (defvar gnus-newsgroup-last-mail nil)
1351 (defvar gnus-newsgroup-last-folder nil)
1352 (defvar gnus-newsgroup-last-file nil)
1353 (defvar gnus-newsgroup-auto-expire nil)
1354 (defvar gnus-newsgroup-active nil)
1355
1356 (defvar gnus-newsgroup-data nil)
1357 (defvar gnus-newsgroup-data-reverse nil)
1358 (defvar gnus-newsgroup-limit nil)
1359 (defvar gnus-newsgroup-limits nil)
1360 (defvar gnus-summary-use-undownloaded-faces nil)
1361
1362 (defvar gnus-newsgroup-unreads nil
1363   "Sorted list of unread articles in the current newsgroup.")
1364
1365 (defvar gnus-newsgroup-unselected nil
1366   "Sorted list of unselected unread articles in the current newsgroup.")
1367
1368 (defvar gnus-newsgroup-reads nil
1369   "Alist of read articles and article marks in the current newsgroup.")
1370
1371 (defvar gnus-newsgroup-expunged-tally nil)
1372
1373 (defvar gnus-newsgroup-marked nil
1374   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1375
1376 (defvar gnus-newsgroup-spam-marked nil
1377   "List of ranges of articles that have been marked as spam.")
1378
1379 (defvar gnus-newsgroup-killed nil
1380   "List of ranges of articles that have been through the scoring process.")
1381
1382 (defvar gnus-newsgroup-cached nil
1383   "Sorted list of articles that come from the article cache.")
1384
1385 (defvar gnus-newsgroup-saved nil
1386   "List of articles that have been saved.")
1387
1388 (defvar gnus-newsgroup-kill-headers nil)
1389
1390 (defvar gnus-newsgroup-replied nil
1391   "List of articles that have been replied to in the current newsgroup.")
1392
1393 (defvar gnus-newsgroup-forwarded nil
1394   "List of articles that have been forwarded in the current newsgroup.")
1395
1396 (defvar gnus-newsgroup-recent nil
1397   "List of articles that have are recent in the current newsgroup.")
1398
1399 (defvar gnus-newsgroup-expirable nil
1400   "Sorted list of articles in the current newsgroup that can be expired.")
1401
1402 (defvar gnus-newsgroup-processable nil
1403   "List of articles in the current newsgroup that can be processed.")
1404
1405 (defvar gnus-newsgroup-downloadable nil
1406   "Sorted list of articles in the current newsgroup that can be processed.")
1407
1408 (defvar gnus-newsgroup-unfetched nil
1409   "Sorted list of articles in the current newsgroup whose headers have
1410 not been fetched into the agent.
1411
1412 This list will always be a subset of gnus-newsgroup-undownloaded.")
1413
1414 (defvar gnus-newsgroup-undownloaded nil
1415   "List of articles in the current newsgroup that haven't been downloaded.")
1416
1417 (defvar gnus-newsgroup-unsendable nil
1418   "List of articles in the current newsgroup that won't be sent.")
1419
1420 (defvar gnus-newsgroup-bookmarks nil
1421   "List of articles in the current newsgroup that have bookmarks.")
1422
1423 (defvar gnus-newsgroup-dormant nil
1424   "Sorted list of dormant articles in the current newsgroup.")
1425
1426 (defvar gnus-newsgroup-unseen nil
1427   "List of unseen articles in the current newsgroup.")
1428
1429 (defvar gnus-newsgroup-seen nil
1430   "Range of seen articles in the current newsgroup.")
1431
1432 (defvar gnus-newsgroup-articles nil
1433   "List of articles in the current newsgroup.")
1434
1435 (defvar gnus-newsgroup-scored nil
1436   "List of scored articles in the current newsgroup.")
1437
1438 (defvar gnus-newsgroup-incorporated nil
1439   "List of incorporated articles in the current newsgroup.")
1440
1441 (defvar gnus-newsgroup-headers nil
1442   "List of article headers in the current newsgroup.")
1443
1444 (defvar gnus-newsgroup-threads nil)
1445
1446 (defvar gnus-newsgroup-prepared nil
1447   "Whether the current group has been prepared properly.")
1448
1449 (defvar gnus-newsgroup-ancient nil
1450   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1451
1452 (defvar gnus-newsgroup-sparse nil)
1453
1454 (defvar gnus-current-article nil)
1455 (defvar gnus-article-current nil)
1456 (defvar gnus-current-headers nil)
1457 (defvar gnus-have-all-headers nil)
1458 (defvar gnus-last-article nil)
1459 (defvar gnus-newsgroup-history nil)
1460 (defvar gnus-newsgroup-charset nil)
1461 (defvar gnus-newsgroup-ephemeral-charset nil)
1462 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1463
1464 (defvar gnus-article-before-search nil)
1465
1466 (defvar gnus-summary-local-variables
1467   '(gnus-newsgroup-name
1468     gnus-newsgroup-begin gnus-newsgroup-end
1469     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1470     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1471     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1472     gnus-newsgroup-unselected gnus-newsgroup-marked
1473     gnus-newsgroup-spam-marked
1474     gnus-newsgroup-reads gnus-newsgroup-saved
1475     gnus-newsgroup-replied gnus-newsgroup-forwarded
1476     gnus-newsgroup-recent
1477     gnus-newsgroup-expirable
1478     gnus-newsgroup-processable gnus-newsgroup-killed
1479     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1480     gnus-newsgroup-unfetched
1481     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1482     gnus-newsgroup-seen gnus-newsgroup-articles
1483     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1484     gnus-newsgroup-headers gnus-newsgroup-threads
1485     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1486     gnus-current-article gnus-current-headers gnus-have-all-headers
1487     gnus-last-article gnus-article-internal-prepare-hook
1488     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1489     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1490     gnus-thread-expunge-below
1491     gnus-score-alist gnus-current-score-file
1492     (gnus-summary-expunge-below . global)
1493     (gnus-summary-mark-below . global)
1494     (gnus-orphan-score . global)
1495     gnus-newsgroup-active gnus-scores-exclude-files
1496     gnus-newsgroup-history gnus-newsgroup-ancient
1497     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1498     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1499     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1500     (gnus-newsgroup-expunged-tally . 0)
1501     gnus-cache-removable-articles gnus-newsgroup-cached
1502     gnus-newsgroup-data gnus-newsgroup-data-reverse
1503     gnus-newsgroup-limit gnus-newsgroup-limits
1504     gnus-newsgroup-charset gnus-newsgroup-display
1505     gnus-summary-use-undownloaded-faces
1506     gnus-newsgroup-incorporated)
1507   "Variables that are buffer-local to the summary buffers.")
1508
1509 (defvar gnus-newsgroup-variables nil
1510   "A list of variables that have separate values in different newsgroups.
1511 A list of newsgroup (summary buffer) local variables, or cons of
1512 variables and their default expressions to be evalled (when the default
1513 values are not nil), that should be made global while the summary buffer
1514 is active.
1515
1516 Note: The default expressions will be evaluated (using function `eval')
1517 before assignment to the local variable rather than just assigned to it.
1518 If the default expression is the symbol `global', that symbol will not
1519 be evaluated but the global value of the local variable will be used
1520 instead.
1521
1522 These variables can be used to set variables in the group parameters
1523 while still allowing them to affect operations done in other buffers.
1524 For example:
1525
1526 \(setq gnus-newsgroup-variables
1527      '(message-use-followup-to
1528        (gnus-visible-headers .
1529          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1530 ")
1531
1532 ;; Byte-compiler warning.
1533 (eval-when-compile
1534   ;; Bind features so that require will believe that gnus-sum has
1535   ;; already been loaded (avoids infinite recursion)
1536   (let ((features (cons 'gnus-sum features)))
1537     ;; Several of the declarations in gnus-sum are needed to load the
1538     ;; following files. Right now, these definitions have been
1539     ;; compiled but not defined (evaluated).  We could either do a
1540     ;; eval-and-compile about all of the declarations or evaluate the
1541     ;; source file.
1542     (if (boundp 'gnus-newsgroup-variables)
1543         nil
1544       (load "gnus-sum.el" t t t))
1545     (require 'gnus)
1546     (require 'gnus-art)))
1547
1548 ;; Subject simplification.
1549
1550 (defun gnus-simplify-whitespace (str)
1551   "Remove excessive whitespace from STR."
1552   ;; Multiple spaces.
1553   (while (string-match "[ \t][ \t]+" str)
1554     (setq str (concat (substring str 0 (match-beginning 0))
1555                         " "
1556                         (substring str (match-end 0)))))
1557   ;; Leading spaces.
1558   (when (string-match "^[ \t]+" str)
1559     (setq str (substring str (match-end 0))))
1560   ;; Trailing spaces.
1561   (when (string-match "[ \t]+$" str)
1562     (setq str (substring str 0 (match-beginning 0))))
1563   str)
1564
1565 (defun gnus-simplify-all-whitespace (str)
1566   "Remove all whitespace from STR."
1567   (while (string-match "[ \t\n]+" str)
1568     (setq str (replace-match "" nil nil str)))
1569   str)
1570
1571 (defsubst gnus-simplify-subject-re (subject)
1572   "Remove \"Re:\" from subject lines."
1573   (if (string-match message-subject-re-regexp subject)
1574       (substring subject (match-end 0))
1575     subject))
1576
1577 (defun gnus-simplify-subject (subject &optional re-only)
1578   "Remove `Re:' and words in parentheses.
1579 If RE-ONLY is non-nil, strip leading `Re:'s only."
1580   (let ((case-fold-search t))           ;Ignore case.
1581     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1582     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1583       (setq subject (substring subject (match-end 0))))
1584     ;; Remove uninteresting prefixes.
1585     (when (and (not re-only)
1586                gnus-simplify-ignored-prefixes
1587                (string-match gnus-simplify-ignored-prefixes subject))
1588       (setq subject (substring subject (match-end 0))))
1589     ;; Remove words in parentheses from end.
1590     (unless re-only
1591       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1592         (setq subject (substring subject 0 (match-beginning 0)))))
1593     ;; Return subject string.
1594     subject))
1595
1596 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1597 ;; all whitespace.
1598 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1599   (goto-char (point-min))
1600   (while (re-search-forward regexp nil t)
1601     (replace-match (or newtext ""))))
1602
1603 (defun gnus-simplify-buffer-fuzzy ()
1604   "Simplify string in the buffer fuzzily.
1605 The string in the accessible portion of the current buffer is simplified.
1606 It is assumed to be a single-line subject.
1607 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1608 matter is removed.  Additional things can be deleted by setting
1609 `gnus-simplify-subject-fuzzy-regexp'."
1610   (let ((case-fold-search t)
1611         (modified-tick))
1612     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1613
1614     (while (not (eq modified-tick (buffer-modified-tick)))
1615       (setq modified-tick (buffer-modified-tick))
1616       (cond
1617        ((listp gnus-simplify-subject-fuzzy-regexp)
1618         (mapcar 'gnus-simplify-buffer-fuzzy-step
1619                 gnus-simplify-subject-fuzzy-regexp))
1620        (gnus-simplify-subject-fuzzy-regexp
1621         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1622       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1623       (gnus-simplify-buffer-fuzzy-step
1624        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1625       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1626
1627     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1628     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1629     (gnus-simplify-buffer-fuzzy-step " $")
1630     (gnus-simplify-buffer-fuzzy-step "^ +")))
1631
1632 (defun gnus-simplify-subject-fuzzy (subject)
1633   "Simplify a subject string fuzzily.
1634 See `gnus-simplify-buffer-fuzzy' for details."
1635   (save-excursion
1636     (gnus-set-work-buffer)
1637     (let ((case-fold-search t))
1638       ;; Remove uninteresting prefixes.
1639       (when (and gnus-simplify-ignored-prefixes
1640                  (string-match gnus-simplify-ignored-prefixes subject))
1641         (setq subject (substring subject (match-end 0))))
1642       (insert subject)
1643       (inline (gnus-simplify-buffer-fuzzy))
1644       (buffer-string))))
1645
1646 (defsubst gnus-simplify-subject-fully (subject)
1647   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1648   (cond
1649    (gnus-simplify-subject-functions
1650     (gnus-map-function gnus-simplify-subject-functions subject))
1651    ((null gnus-summary-gather-subject-limit)
1652     (gnus-simplify-subject-re subject))
1653    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1654     (gnus-simplify-subject-fuzzy subject))
1655    ((numberp gnus-summary-gather-subject-limit)
1656     (gnus-limit-string (gnus-simplify-subject-re subject)
1657                        gnus-summary-gather-subject-limit))
1658    (t
1659     subject)))
1660
1661 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1662   "Check whether two subjects are equal.
1663 If optional argument SIMPLE-FIRST is t, first argument is already
1664 simplified."
1665   (cond
1666    ((null simple-first)
1667     (equal (gnus-simplify-subject-fully s1)
1668            (gnus-simplify-subject-fully s2)))
1669    (t
1670     (equal s1
1671            (gnus-simplify-subject-fully s2)))))
1672
1673 (defun gnus-summary-bubble-group ()
1674   "Increase the score of the current group.
1675 This is a handy function to add to `gnus-summary-exit-hook' to
1676 increase the score of each group you read."
1677   (gnus-group-add-score gnus-newsgroup-name))
1678
1679 \f
1680 ;;;
1681 ;;; Gnus summary mode
1682 ;;;
1683
1684 (put 'gnus-summary-mode 'mode-class 'special)
1685
1686 (defvar gnus-article-commands-menu)
1687
1688 ;; Non-orthogonal keys
1689
1690 (gnus-define-keys gnus-summary-mode-map
1691   " " gnus-summary-next-page
1692   "\177" gnus-summary-prev-page
1693   [delete] gnus-summary-prev-page
1694   [backspace] gnus-summary-prev-page
1695   "\r" gnus-summary-scroll-up
1696   "\M-\r" gnus-summary-scroll-down
1697   "n" gnus-summary-next-unread-article
1698   "p" gnus-summary-prev-unread-article
1699   "N" gnus-summary-next-article
1700   "P" gnus-summary-prev-article
1701   "\M-\C-n" gnus-summary-next-same-subject
1702   "\M-\C-p" gnus-summary-prev-same-subject
1703   "\M-n" gnus-summary-next-unread-subject
1704   "\M-p" gnus-summary-prev-unread-subject
1705   "." gnus-summary-first-unread-article
1706   "," gnus-summary-best-unread-article
1707   "\M-s" gnus-summary-search-article-forward
1708   "\M-r" gnus-summary-search-article-backward
1709   "<" gnus-summary-beginning-of-article
1710   ">" gnus-summary-end-of-article
1711   "j" gnus-summary-goto-article
1712   "^" gnus-summary-refer-parent-article
1713   "\M-^" gnus-summary-refer-article
1714   "u" gnus-summary-tick-article-forward
1715   "!" gnus-summary-tick-article-forward
1716   "U" gnus-summary-tick-article-backward
1717   "d" gnus-summary-mark-as-read-forward
1718   "D" gnus-summary-mark-as-read-backward
1719   "E" gnus-summary-mark-as-expirable
1720   "\M-u" gnus-summary-clear-mark-forward
1721   "\M-U" gnus-summary-clear-mark-backward
1722   "k" gnus-summary-kill-same-subject-and-select
1723   "\C-k" gnus-summary-kill-same-subject
1724   "\M-\C-k" gnus-summary-kill-thread
1725   "\M-\C-l" gnus-summary-lower-thread
1726   "e" gnus-summary-edit-article
1727   "#" gnus-summary-mark-as-processable
1728   "\M-#" gnus-summary-unmark-as-processable
1729   "\M-\C-t" gnus-summary-toggle-threads
1730   "\M-\C-s" gnus-summary-show-thread
1731   "\M-\C-h" gnus-summary-hide-thread
1732   "\M-\C-f" gnus-summary-next-thread
1733   "\M-\C-b" gnus-summary-prev-thread
1734   [(meta down)] gnus-summary-next-thread
1735   [(meta up)] gnus-summary-prev-thread
1736   "\M-\C-u" gnus-summary-up-thread
1737   "\M-\C-d" gnus-summary-down-thread
1738   "&" gnus-summary-execute-command
1739   "c" gnus-summary-catchup-and-exit
1740   "\C-w" gnus-summary-mark-region-as-read
1741   "\C-t" gnus-summary-toggle-truncation
1742   "?" gnus-summary-mark-as-dormant
1743   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1744   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1745   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1746   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1747   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1748   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1749   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1750   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1751   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1752   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1753   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1754   "=" gnus-summary-expand-window
1755   "\C-x\C-s" gnus-summary-reselect-current-group
1756   "\M-g" gnus-summary-rescan-group
1757   "w" gnus-summary-stop-page-breaking
1758   "\C-c\C-r" gnus-summary-caesar-message
1759   "\M-t" gnus-summary-toggle-mime
1760   "f" gnus-summary-followup
1761   "F" gnus-summary-followup-with-original
1762   "C" gnus-summary-cancel-article
1763   "r" gnus-summary-reply
1764   "R" gnus-summary-reply-with-original
1765   "\C-c\C-f" gnus-summary-mail-forward
1766   "o" gnus-summary-save-article
1767   "\C-o" gnus-summary-save-article-mail
1768   "|" gnus-summary-pipe-output
1769   "\M-k" gnus-summary-edit-local-kill
1770   "\M-K" gnus-summary-edit-global-kill
1771   ;; "V" gnus-version
1772   "\C-c\C-d" gnus-summary-describe-group
1773   "q" gnus-summary-exit
1774   "Q" gnus-summary-exit-no-update
1775   "\C-c\C-i" gnus-info-find-node
1776   gnus-mouse-2 gnus-mouse-pick-article
1777   [follow-link] mouse-face
1778   "m" gnus-summary-mail-other-window
1779   "a" gnus-summary-post-news
1780   "i" gnus-summary-news-other-window
1781   "x" gnus-summary-limit-to-unread
1782   "s" gnus-summary-isearch-article
1783   "t" gnus-summary-toggle-header
1784   "g" gnus-summary-show-article
1785   "l" gnus-summary-goto-last-article
1786   "v" gnus-summary-preview-mime-message
1787   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1788   "\C-d" gnus-summary-enter-digest-group
1789   "\M-\C-d" gnus-summary-read-document
1790   "\M-\C-e" gnus-summary-edit-parameters
1791   "\M-\C-a" gnus-summary-customize-parameters
1792   "\C-c\C-b" gnus-bug
1793   "\C-c\C-n" gnus-namazu-search
1794   "*" gnus-cache-enter-article
1795   "\M-*" gnus-cache-remove-article
1796   "\M-&" gnus-summary-universal-argument
1797   "\C-l" gnus-recenter
1798   "I" gnus-summary-increase-score
1799   "L" gnus-summary-lower-score
1800   "\M-i" gnus-symbolic-argument
1801   "h" gnus-summary-select-article-buffer
1802
1803   "V" gnus-summary-score-map
1804   "X" gnus-uu-extract-map
1805   "S" gnus-summary-send-map)
1806
1807   ;; Sort of orthogonal keymap
1808 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1809   "t" gnus-summary-tick-article-forward
1810   "!" gnus-summary-tick-article-forward
1811   "d" gnus-summary-mark-as-read-forward
1812   "r" gnus-summary-mark-as-read-forward
1813   "c" gnus-summary-clear-mark-forward
1814   " " gnus-summary-clear-mark-forward
1815   "e" gnus-summary-mark-as-expirable
1816   "x" gnus-summary-mark-as-expirable
1817   "?" gnus-summary-mark-as-dormant
1818   "b" gnus-summary-set-bookmark
1819   "B" gnus-summary-remove-bookmark
1820   "#" gnus-summary-mark-as-processable
1821   "\M-#" gnus-summary-unmark-as-processable
1822   "S" gnus-summary-limit-include-expunged
1823   "C" gnus-summary-catchup
1824   "H" gnus-summary-catchup-to-here
1825   "h" gnus-summary-catchup-from-here
1826   "\C-c" gnus-summary-catchup-all
1827   "k" gnus-summary-kill-same-subject-and-select
1828   "K" gnus-summary-kill-same-subject
1829   "P" gnus-uu-mark-map)
1830
1831 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1832   "c" gnus-summary-clear-above
1833   "u" gnus-summary-tick-above
1834   "m" gnus-summary-mark-above
1835   "k" gnus-summary-kill-below)
1836
1837 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1838   "/" gnus-summary-limit-to-subject
1839   "n" gnus-summary-limit-to-articles
1840   "w" gnus-summary-pop-limit
1841   "s" gnus-summary-limit-to-subject
1842   "a" gnus-summary-limit-to-author
1843   "u" gnus-summary-limit-to-unread
1844   "m" gnus-summary-limit-to-marks
1845   "M" gnus-summary-limit-exclude-marks
1846   "v" gnus-summary-limit-to-score
1847   "*" gnus-summary-limit-include-cached
1848   "D" gnus-summary-limit-include-dormant
1849   "T" gnus-summary-limit-include-thread
1850   "d" gnus-summary-limit-exclude-dormant
1851   "t" gnus-summary-limit-to-age
1852   "." gnus-summary-limit-to-unseen
1853   "x" gnus-summary-limit-to-extra
1854   "p" gnus-summary-limit-to-display-predicate
1855   "E" gnus-summary-limit-include-expunged
1856   "c" gnus-summary-limit-exclude-childless-dormant
1857   "C" gnus-summary-limit-mark-excluded-as-read
1858   "o" gnus-summary-insert-old-articles
1859   "N" gnus-summary-insert-new-articles
1860   "r" gnus-summary-limit-to-replied
1861   "R" gnus-summary-limit-to-recipient)
1862
1863 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1864   "n" gnus-summary-next-unread-article
1865   "p" gnus-summary-prev-unread-article
1866   "N" gnus-summary-next-article
1867   "P" gnus-summary-prev-article
1868   "\C-n" gnus-summary-next-same-subject
1869   "\C-p" gnus-summary-prev-same-subject
1870   "\M-n" gnus-summary-next-unread-subject
1871   "\M-p" gnus-summary-prev-unread-subject
1872   "f" gnus-summary-first-unread-article
1873   "b" gnus-summary-best-unread-article
1874   "j" gnus-summary-goto-article
1875   "g" gnus-summary-goto-subject
1876   "l" gnus-summary-goto-last-article
1877   "o" gnus-summary-pop-article)
1878
1879 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1880   "k" gnus-summary-kill-thread
1881   "l" gnus-summary-lower-thread
1882   "i" gnus-summary-raise-thread
1883   "T" gnus-summary-toggle-threads
1884   "t" gnus-summary-rethread-current
1885   "^" gnus-summary-reparent-thread
1886   "s" gnus-summary-show-thread
1887   "S" gnus-summary-show-all-threads
1888   "h" gnus-summary-hide-thread
1889   "H" gnus-summary-hide-all-threads
1890   "n" gnus-summary-next-thread
1891   "p" gnus-summary-prev-thread
1892   "u" gnus-summary-up-thread
1893   "o" gnus-summary-top-thread
1894   "d" gnus-summary-down-thread
1895   "#" gnus-uu-mark-thread
1896   "\M-#" gnus-uu-unmark-thread)
1897
1898 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
1899   "g" gnus-summary-prepare
1900   "c" gnus-summary-insert-cached-articles
1901   "d" gnus-summary-insert-dormant-articles)
1902
1903 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
1904   "c" gnus-summary-catchup-and-exit
1905   "C" gnus-summary-catchup-all-and-exit
1906   "E" gnus-summary-exit-no-update
1907   "J" gnus-summary-jump-to-other-group
1908   "Q" gnus-summary-exit
1909   "Z" gnus-summary-exit
1910   "n" gnus-summary-catchup-and-goto-next-group
1911   "R" gnus-summary-reselect-current-group
1912   "G" gnus-summary-rescan-group
1913   "N" gnus-summary-next-group
1914   "s" gnus-summary-save-newsrc
1915   "P" gnus-summary-prev-group)
1916
1917 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
1918   " " gnus-summary-next-page
1919   "n" gnus-summary-next-page
1920   "\177" gnus-summary-prev-page
1921   [delete] gnus-summary-prev-page
1922   "p" gnus-summary-prev-page
1923   "\r" gnus-summary-scroll-up
1924   "\M-\r" gnus-summary-scroll-down
1925   "<" gnus-summary-beginning-of-article
1926   ">" gnus-summary-end-of-article
1927   "b" gnus-summary-beginning-of-article
1928   "e" gnus-summary-end-of-article
1929   "^" gnus-summary-refer-parent-article
1930   "r" gnus-summary-refer-parent-article
1931   "D" gnus-summary-enter-digest-group
1932   "R" gnus-summary-refer-references
1933   "T" gnus-summary-refer-thread
1934   "g" gnus-summary-show-article
1935   "s" gnus-summary-isearch-article
1936   "P" gnus-summary-print-article
1937   "M" gnus-mailing-list-insinuate
1938   "t" gnus-article-babel)
1939
1940 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
1941   "b" gnus-article-add-buttons
1942   "B" gnus-article-add-buttons-to-head
1943   "o" gnus-article-treat-overstrike
1944   "e" gnus-article-emphasize
1945   "w" gnus-article-fill-cited-article
1946   "Q" gnus-article-fill-long-lines
1947   "C" gnus-article-capitalize-sentences
1948   "c" gnus-article-remove-cr
1949   "Z" gnus-article-decode-HZ
1950   "A" gnus-article-treat-ansi-sequences
1951   "h" gnus-article-wash-html
1952   "u" gnus-article-unsplit-urls
1953   "f" gnus-article-display-x-face
1954   "l" gnus-summary-stop-page-breaking
1955   "r" gnus-summary-caesar-message
1956   "m" gnus-summary-morse-message
1957   "t" gnus-summary-toggle-header
1958   "g" gnus-treat-smiley
1959   "v" gnus-summary-verbose-headers
1960   "m" gnus-summary-toggle-mime
1961   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
1962   "p" gnus-article-verify-x-pgp-sig
1963   "d" gnus-article-treat-dumbquotes
1964   "i" gnus-summary-idna-message)
1965
1966 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
1967   ;; mnemonic: deuglif*Y*
1968   "u" gnus-article-outlook-unwrap-lines
1969   "a" gnus-article-outlook-repair-attribution
1970   "c" gnus-article-outlook-rearrange-citation
1971   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
1972
1973 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
1974   "a" gnus-article-hide
1975   "h" gnus-article-hide-headers
1976   "b" gnus-article-hide-boring-headers
1977   "s" gnus-article-hide-signature
1978   "c" gnus-article-hide-citation
1979   "C" gnus-article-hide-citation-in-followups
1980   "l" gnus-article-hide-list-identifiers
1981   "B" gnus-article-strip-banner
1982   "P" gnus-article-hide-pem
1983   "\C-c" gnus-article-hide-citation-maybe)
1984
1985 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
1986   "a" gnus-article-highlight
1987   "h" gnus-article-highlight-headers
1988   "c" gnus-article-highlight-citation
1989   "s" gnus-article-highlight-signature)
1990
1991 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
1992   "f" gnus-article-treat-fold-headers
1993   "u" gnus-article-treat-unfold-headers
1994   "n" gnus-article-treat-fold-newsgroups)
1995
1996 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
1997   "x" gnus-article-display-x-face
1998   "d" gnus-article-display-face
1999   "s" gnus-treat-smiley
2000   "D" gnus-article-remove-images
2001   "f" gnus-treat-from-picon
2002   "m" gnus-treat-mail-picon
2003   "n" gnus-treat-newsgroups-picon)
2004
2005 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2006   "z" gnus-article-date-ut
2007   "u" gnus-article-date-ut
2008   "l" gnus-article-date-local
2009   "p" gnus-article-date-english
2010   "e" gnus-article-date-lapsed
2011   "o" gnus-article-date-original
2012   "i" gnus-article-date-iso8601
2013   "s" gnus-article-date-user)
2014
2015 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2016   "t" gnus-article-remove-trailing-blank-lines
2017   "l" gnus-article-strip-leading-blank-lines
2018   "m" gnus-article-strip-multiple-blank-lines
2019   "a" gnus-article-strip-blank-lines
2020   "A" gnus-article-strip-all-blank-lines
2021   "s" gnus-article-strip-leading-space
2022   "e" gnus-article-strip-trailing-space
2023   "w" gnus-article-remove-leading-whitespace)
2024
2025 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2026   "v" gnus-version
2027   "f" gnus-summary-fetch-faq
2028   "d" gnus-summary-describe-group
2029   "h" gnus-summary-describe-briefly
2030   "i" gnus-info-find-node
2031   "c" gnus-group-fetch-charter
2032   "C" gnus-group-fetch-control)
2033
2034 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2035   "e" gnus-summary-expire-articles
2036   "\M-\C-e" gnus-summary-expire-articles-now
2037   "\177" gnus-summary-delete-article
2038   [delete] gnus-summary-delete-article
2039   [backspace] gnus-summary-delete-article
2040   "m" gnus-summary-move-article
2041   "r" gnus-summary-respool-article
2042   "w" gnus-summary-edit-article
2043   "c" gnus-summary-copy-article
2044   "B" gnus-summary-crosspost-article
2045   "q" gnus-summary-respool-query
2046   "t" gnus-summary-respool-trace
2047   "i" gnus-summary-import-article
2048   "I" gnus-summary-create-article
2049   "p" gnus-summary-article-posted-p)
2050
2051 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2052   "o" gnus-summary-save-article
2053   "m" gnus-summary-save-article-mail
2054   "F" gnus-summary-write-article-file
2055   "r" gnus-summary-save-article-rmail
2056   "f" gnus-summary-save-article-file
2057   "b" gnus-summary-save-article-body-file
2058   "h" gnus-summary-save-article-folder
2059   "v" gnus-summary-save-article-vm
2060   "p" gnus-summary-pipe-output
2061   "P" gnus-summary-muttprint
2062   "s" gnus-soup-add-article)
2063
2064 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2065   "b" gnus-summary-display-buttonized
2066   "m" gnus-summary-repair-multipart
2067   "v" gnus-article-view-part
2068   "o" gnus-article-save-part
2069   "c" gnus-article-copy-part
2070   "C" gnus-article-view-part-as-charset
2071   "e" gnus-article-view-part-externally
2072   "E" gnus-article-encrypt-body
2073   "i" gnus-article-inline-part
2074   "|" gnus-article-pipe-part)
2075
2076 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2077   "p" gnus-summary-mark-as-processable
2078   "u" gnus-summary-unmark-as-processable
2079   "U" gnus-summary-unmark-all-processable
2080   "v" gnus-uu-mark-over
2081   "s" gnus-uu-mark-series
2082   "r" gnus-uu-mark-region
2083   "g" gnus-uu-unmark-region
2084   "R" gnus-uu-mark-by-regexp
2085   "G" gnus-uu-unmark-by-regexp
2086   "t" gnus-uu-mark-thread
2087   "T" gnus-uu-unmark-thread
2088   "a" gnus-uu-mark-all
2089   "b" gnus-uu-mark-buffer
2090   "S" gnus-uu-mark-sparse
2091   "k" gnus-summary-kill-process-mark
2092   "y" gnus-summary-yank-process-mark
2093   "w" gnus-summary-save-process-mark
2094   "i" gnus-uu-invert-processable)
2095
2096 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2097   ;;"x" gnus-uu-extract-any
2098   "m" gnus-summary-save-parts
2099   "u" gnus-uu-decode-uu
2100   "U" gnus-uu-decode-uu-and-save
2101   "s" gnus-uu-decode-unshar
2102   "S" gnus-uu-decode-unshar-and-save
2103   "o" gnus-uu-decode-save
2104   "O" gnus-uu-decode-save
2105   "b" gnus-uu-decode-binhex
2106   "B" gnus-uu-decode-binhex
2107   "p" gnus-uu-decode-postscript
2108   "P" gnus-uu-decode-postscript-and-save)
2109
2110 (gnus-define-keys
2111     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2112   "u" gnus-uu-decode-uu-view
2113   "U" gnus-uu-decode-uu-and-save-view
2114   "s" gnus-uu-decode-unshar-view
2115   "S" gnus-uu-decode-unshar-and-save-view
2116   "o" gnus-uu-decode-save-view
2117   "O" gnus-uu-decode-save-view
2118   "b" gnus-uu-decode-binhex-view
2119   "B" gnus-uu-decode-binhex-view
2120   "p" gnus-uu-decode-postscript-view
2121   "P" gnus-uu-decode-postscript-and-save-view)
2122
2123 (defvar gnus-article-post-menu nil)
2124
2125 (defconst gnus-summary-menu-maxlen 20)
2126
2127 (defun gnus-summary-menu-split (menu)
2128   ;; If we have lots of elements, divide them into groups of 20
2129   ;; and make a pane (or submenu) for each one.
2130   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2131       (let ((menu menu) sublists next
2132             (i 1))
2133         (while menu
2134           ;; Pull off the next gnus-summary-menu-maxlen elements
2135           ;; and make them the next element of sublist.
2136           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2137           (if next
2138               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2139                       nil))
2140           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2141                                              (aref (car (last menu)) 0)) menu)
2142                                sublists))
2143           (setq i (1+ i))
2144           (setq menu next))
2145         (nreverse sublists))
2146     ;; Few elements--put them all in one pane.
2147     menu))
2148
2149 (defun gnus-summary-make-menu-bar ()
2150   (gnus-turn-off-edit-menu 'summary)
2151
2152   (unless (boundp 'gnus-summary-misc-menu)
2153
2154     (easy-menu-define
2155       gnus-summary-kill-menu gnus-summary-mode-map ""
2156       (cons
2157        "Score"
2158        (nconc
2159         (list
2160          ["Customize" gnus-score-customize t])
2161         (gnus-make-score-map 'increase)
2162         (gnus-make-score-map 'lower)
2163         '(("Mark"
2164            ["Kill below" gnus-summary-kill-below t]
2165            ["Mark above" gnus-summary-mark-above t]
2166            ["Tick above" gnus-summary-tick-above t]
2167            ["Clear above" gnus-summary-clear-above t])
2168           ["Current score" gnus-summary-current-score t]
2169           ["Set score" gnus-summary-set-score t]
2170           ["Switch current score file..." gnus-score-change-score-file t]
2171           ["Set mark below..." gnus-score-set-mark-below t]
2172           ["Set expunge below..." gnus-score-set-expunge-below t]
2173           ["Edit current score file" gnus-score-edit-current-scores t]
2174           ["Edit score file" gnus-score-edit-file t]
2175           ["Trace score" gnus-score-find-trace t]
2176           ["Find words" gnus-score-find-favourite-words t]
2177           ["Rescore buffer" gnus-summary-rescore t]
2178           ["Increase score..." gnus-summary-increase-score t]
2179           ["Lower score..." gnus-summary-lower-score t]))))
2180
2181     ;; Define both the Article menu in the summary buffer and the
2182     ;; equivalent Commands menu in the article buffer here for
2183     ;; consistency.
2184     (let ((innards
2185            `(("Hide"
2186               ["All" gnus-article-hide t]
2187               ["Headers" gnus-article-hide-headers t]
2188               ["Signature" gnus-article-hide-signature t]
2189               ["Citation" gnus-article-hide-citation t]
2190               ["List identifiers" gnus-article-hide-list-identifiers t]
2191               ["Banner" gnus-article-strip-banner t]
2192               ["Boring headers" gnus-article-hide-boring-headers t])
2193              ("Highlight"
2194               ["All" gnus-article-highlight t]
2195               ["Headers" gnus-article-highlight-headers t]
2196               ["Signature" gnus-article-highlight-signature t]
2197               ["Citation" gnus-article-highlight-citation t])
2198              ("Date"
2199               ["Local" gnus-article-date-local t]
2200               ["ISO8601" gnus-article-date-iso8601 t]
2201               ["UT" gnus-article-date-ut t]
2202               ["Original" gnus-article-date-original t]
2203               ["Lapsed" gnus-article-date-lapsed t]
2204               ["User-defined" gnus-article-date-user t])
2205              ("Display"
2206               ["Remove images" gnus-article-remove-images t]
2207               ["Toggle smiley" gnus-treat-smiley t]
2208               ["Show X-Face" gnus-article-display-x-face t]
2209               ["Show picons in From" gnus-treat-from-picon t]
2210               ["Show picons in mail headers" gnus-treat-mail-picon t]
2211               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2212               ("View as different encoding"
2213                ,@(gnus-summary-menu-split
2214                   (mapcar
2215                    (lambda (cs)
2216                      ;; Since easymenu under Emacs doesn't allow
2217                      ;; lambda forms for menu commands, we should
2218                      ;; provide intern'ed function symbols.
2219                      (let ((command (intern (format "\
2220 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2221                        (fset command
2222                              `(lambda ()
2223                                 (interactive)
2224                                 (let ((gnus-summary-show-article-charset-alist
2225                                        '((1 . ,cs))))
2226                                   (gnus-summary-show-article 1))))
2227                        `[,(symbol-name cs) ,command t]))
2228                    (sort (if (fboundp 'coding-system-list)
2229                              (coding-system-list)
2230                            ;;(mapcar 'car mm-mime-mule-charset-alist)
2231                            )
2232                          'string<)))))
2233              ("Washing"
2234               ("Remove Blanks"
2235                ["Leading" gnus-article-strip-leading-blank-lines t]
2236                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2237                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2238                ["All of the above" gnus-article-strip-blank-lines t]
2239                ["All" gnus-article-strip-all-blank-lines t]
2240                ["Leading space" gnus-article-strip-leading-space t]
2241                ["Trailing space" gnus-article-strip-trailing-space t]
2242                ["Leading space in headers"
2243                 gnus-article-remove-leading-whitespace t])
2244               ["Overstrike" gnus-article-treat-overstrike t]
2245               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2246               ["Emphasis" gnus-article-emphasize t]
2247               ["Word wrap" gnus-article-fill-cited-article t]
2248               ["Fill long lines" gnus-article-fill-long-lines t]
2249               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2250               ["Remove CR" gnus-article-remove-cr t]
2251               ["Rot 13" gnus-summary-caesar-message
2252                ,@(if (featurep 'xemacs) '(t)
2253                    '(:help "\"Caesar rotate\" article by 13"))]
2254               ["De-IDNA" gnus-summary-idna-message t]
2255               ["Morse decode" gnus-summary-morse-message t]
2256               ["Unix pipe..." gnus-summary-pipe-message t]
2257               ["Add buttons" gnus-article-add-buttons t]
2258               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2259               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2260               ["Toggle MIME" gnus-summary-toggle-mime t]
2261               ["Verbose header" gnus-summary-verbose-headers t]
2262               ["Toggle header" gnus-summary-toggle-header t]
2263               ["Unfold headers" gnus-article-treat-unfold-headers t]
2264               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2265               ["Html" gnus-article-wash-html t]
2266               ["Unsplit URLs" gnus-article-unsplit-urls t]
2267               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2268               ["Decode HZ" gnus-article-decode-HZ t]
2269               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2270               ("(Outlook) Deuglify"
2271                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2272                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2273                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2274                ["Full (Outlook) deuglify"
2275                 gnus-article-outlook-deuglify-article t])
2276               )
2277              ("Output"
2278               ["Save in default format..." gnus-summary-save-article
2279                ,@(if (featurep 'xemacs) '(t)
2280                    '(:help "Save article using default method"))]
2281               ["Save in file..." gnus-summary-save-article-file
2282                ,@(if (featurep 'xemacs) '(t)
2283                    '(:help "Save article in file"))]
2284               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2285               ["Save in MH folder..." gnus-summary-save-article-folder t]
2286               ["Save in VM folder..." gnus-summary-save-article-vm t]
2287               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2288               ["Save body in file..." gnus-summary-save-article-body-file t]
2289               ["Pipe through a filter..." gnus-summary-pipe-output t]
2290               ["Add to SOUP packet" gnus-soup-add-article t]
2291               ["Print with Muttprint..." gnus-summary-muttprint t]
2292               ["Print" gnus-summary-print-article
2293                ,@(if (featurep 'xemacs) '(t)
2294                    '(:help "Generate and print a PostScript image"))])
2295              ("Copy, move,... (Backend)"
2296               ,@(if (featurep 'xemacs) nil
2297                   '(:help "Copying, moving, expiring articles..."))
2298               ["Respool article..." gnus-summary-respool-article t]
2299               ["Move article..." gnus-summary-move-article
2300                (gnus-check-backend-function
2301                 'request-move-article gnus-newsgroup-name)]
2302               ["Copy article..." gnus-summary-copy-article t]
2303               ["Crosspost article..." gnus-summary-crosspost-article
2304                (gnus-check-backend-function
2305                 'request-replace-article gnus-newsgroup-name)]
2306               ["Import file..." gnus-summary-import-article
2307                (gnus-check-backend-function
2308                 'request-accept-article gnus-newsgroup-name)]
2309               ["Create article..." gnus-summary-create-article
2310                (gnus-check-backend-function
2311                 'request-accept-article gnus-newsgroup-name)]
2312               ["Check if posted" gnus-summary-article-posted-p t]
2313               ["Edit article" gnus-summary-edit-article
2314                (not (gnus-group-read-only-p))]
2315               ["Delete article" gnus-summary-delete-article
2316                (gnus-check-backend-function
2317                 'request-expire-articles gnus-newsgroup-name)]
2318               ["Query respool" gnus-summary-respool-query t]
2319               ["Trace respool" gnus-summary-respool-trace t]
2320               ["Delete expirable articles" gnus-summary-expire-articles-now
2321                (gnus-check-backend-function
2322                 'request-expire-articles gnus-newsgroup-name)])
2323              ("Extract"
2324               ["Uudecode" gnus-uu-decode-uu
2325                ,@(if (featurep 'xemacs) '(t)
2326                    '(:help "Decode uuencoded article(s)"))]
2327               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2328               ["Unshar" gnus-uu-decode-unshar t]
2329               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2330               ["Save" gnus-uu-decode-save t]
2331               ["Binhex" gnus-uu-decode-binhex t]
2332               ["Postscript" gnus-uu-decode-postscript t])
2333              ("Cache"
2334               ["Enter article" gnus-cache-enter-article t]
2335               ["Remove article" gnus-cache-remove-article t])
2336              ["Translate" gnus-article-babel t]
2337              ["Select article buffer" gnus-summary-select-article-buffer t]
2338              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2339              ["Isearch article..." gnus-summary-isearch-article t]
2340              ["Beginning of the article" gnus-summary-beginning-of-article t]
2341              ["End of the article" gnus-summary-end-of-article t]
2342              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2343              ["Fetch referenced articles" gnus-summary-refer-references t]
2344              ["Fetch current thread" gnus-summary-refer-thread t]
2345              ["Fetch article with id..." gnus-summary-refer-article t]
2346              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2347              ["Redisplay" gnus-summary-show-article t]
2348              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2349       (easy-menu-define
2350         gnus-summary-article-menu gnus-summary-mode-map ""
2351         (cons "Article" innards))
2352
2353       (if (not (keymapp gnus-summary-article-menu))
2354           (easy-menu-define
2355             gnus-article-commands-menu gnus-article-mode-map ""
2356             (cons "Commands" innards))
2357         ;; in Emacs, don't share menu.
2358         (setq gnus-article-commands-menu
2359               (copy-keymap gnus-summary-article-menu))
2360         (define-key gnus-article-mode-map [menu-bar commands]
2361           (cons "Commands" gnus-article-commands-menu))))
2362
2363     (easy-menu-define
2364       gnus-summary-thread-menu gnus-summary-mode-map ""
2365       '("Threads"
2366         ["Find all messages in thread" gnus-summary-refer-thread t]
2367         ["Toggle threading" gnus-summary-toggle-threads t]
2368         ["Hide threads" gnus-summary-hide-all-threads t]
2369         ["Show threads" gnus-summary-show-all-threads t]
2370         ["Hide thread" gnus-summary-hide-thread t]
2371         ["Show thread" gnus-summary-show-thread t]
2372         ["Go to next thread" gnus-summary-next-thread t]
2373         ["Go to previous thread" gnus-summary-prev-thread t]
2374         ["Go down thread" gnus-summary-down-thread t]
2375         ["Go up thread" gnus-summary-up-thread t]
2376         ["Top of thread" gnus-summary-top-thread t]
2377         ["Mark thread as read" gnus-summary-kill-thread t]
2378         ["Lower thread score" gnus-summary-lower-thread t]
2379         ["Raise thread score" gnus-summary-raise-thread t]
2380         ["Rethread current" gnus-summary-rethread-current t]))
2381
2382     (easy-menu-define
2383       gnus-summary-post-menu gnus-summary-mode-map ""
2384       `("Post"
2385         ["Send a message (mail or news)" gnus-summary-post-news
2386          ,@(if (featurep 'xemacs) '(t)
2387              '(:help "Compose a new message (mail or news)"))]
2388         ["Followup" gnus-summary-followup
2389          ,@(if (featurep 'xemacs) '(t)
2390              '(:help "Post followup to this article"))]
2391         ["Followup and yank" gnus-summary-followup-with-original
2392          ,@(if (featurep 'xemacs) '(t)
2393              '(:help "Post followup to this article, quoting its contents"))]
2394         ["Supersede article" gnus-summary-supersede-article t]
2395         ["Cancel article" gnus-summary-cancel-article
2396          ,@(if (featurep 'xemacs) '(t)
2397              '(:help "Cancel an article you posted"))]
2398         ["Reply" gnus-summary-reply t]
2399         ["Reply and yank" gnus-summary-reply-with-original t]
2400         ["Wide reply" gnus-summary-wide-reply t]
2401         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2402          ,@(if (featurep 'xemacs) '(t)
2403              '(:help "Mail a reply, quoting this article"))]
2404         ["Very wide reply" gnus-summary-very-wide-reply t]
2405         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2406          ,@(if (featurep 'xemacs) '(t)
2407              '(:help "Mail a very wide reply, quoting this article"))]
2408         ["Mail forward" gnus-summary-mail-forward t]
2409         ["Post forward" gnus-summary-post-forward t]
2410         ["Digest and mail" gnus-summary-digest-mail-forward t]
2411         ["Digest and post" gnus-summary-digest-post-forward t]
2412         ["Resend message" gnus-summary-resend-message t]
2413         ["Resend message edit" gnus-summary-resend-message-edit t]
2414         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2415         ["Send a mail" gnus-summary-mail-other-window t]
2416         ["Create a local message" gnus-summary-news-other-window t]
2417         ["Uuencode and post" gnus-uu-post-news
2418          ,@(if (featurep 'xemacs) '(t)
2419              '(:help "Post a uuencoded article"))]
2420         ["Followup via news" gnus-summary-followup-to-mail t]
2421         ["Followup via news and yank"
2422          gnus-summary-followup-to-mail-with-original t]
2423         ;;("Draft"
2424         ;;["Send" gnus-summary-send-draft t]
2425         ;;["Send bounced" gnus-resend-bounced-mail t])
2426         ))
2427
2428     (cond
2429      ((not (keymapp gnus-summary-post-menu))
2430       (setq gnus-article-post-menu gnus-summary-post-menu))
2431      ((not gnus-article-post-menu)
2432       ;; Don't share post menu.
2433       (setq gnus-article-post-menu
2434             (copy-keymap gnus-summary-post-menu))))
2435     (define-key gnus-article-mode-map [menu-bar post]
2436       (cons "Post" gnus-article-post-menu))
2437
2438     (easy-menu-define
2439       gnus-summary-misc-menu gnus-summary-mode-map ""
2440       `("Gnus"
2441         ("Mark Read"
2442          ["Mark as read" gnus-summary-mark-as-read-forward t]
2443          ["Mark same subject and select"
2444           gnus-summary-kill-same-subject-and-select t]
2445          ["Mark same subject" gnus-summary-kill-same-subject t]
2446          ["Catchup" gnus-summary-catchup
2447           ,@(if (featurep 'xemacs) '(t)
2448               '(:help "Mark unread articles in this group as read"))]
2449          ["Catchup all" gnus-summary-catchup-all t]
2450          ["Catchup to here" gnus-summary-catchup-to-here t]
2451          ["Catchup from here" gnus-summary-catchup-from-here t]
2452          ["Catchup region" gnus-summary-mark-region-as-read
2453           (gnus-mark-active-p)]
2454          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2455         ("Mark Various"
2456          ["Tick" gnus-summary-tick-article-forward t]
2457          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2458          ["Remove marks" gnus-summary-clear-mark-forward t]
2459          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2460          ["Set bookmark" gnus-summary-set-bookmark t]
2461          ["Remove bookmark" gnus-summary-remove-bookmark t])
2462         ("Limit to"
2463          ["Marks..." gnus-summary-limit-to-marks t]
2464          ["Subject..." gnus-summary-limit-to-subject t]
2465          ["Author..." gnus-summary-limit-to-author t]
2466          ["Recipient..." gnus-summary-limit-to-recipient t]
2467          ["Age..." gnus-summary-limit-to-age t]
2468          ["Extra..." gnus-summary-limit-to-extra t]
2469          ["Score..." gnus-summary-limit-to-score t]
2470          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2471          ["Unread" gnus-summary-limit-to-unread t]
2472          ["Unseen" gnus-summary-limit-to-unseen t]
2473          ["Replied" gnus-summary-limit-to-replied t]
2474          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2475          ["Next articles" gnus-summary-limit-to-articles t]
2476          ["Pop limit" gnus-summary-pop-limit t]
2477          ["Show dormant" gnus-summary-limit-include-dormant t]
2478          ["Hide childless dormant"
2479           gnus-summary-limit-exclude-childless-dormant t]
2480          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2481          ["Hide marked" gnus-summary-limit-exclude-marks t]
2482          ["Show expunged" gnus-summary-limit-include-expunged t])
2483         ("Process Mark"
2484          ["Set mark" gnus-summary-mark-as-processable t]
2485          ["Remove mark" gnus-summary-unmark-as-processable t]
2486          ["Remove all marks" gnus-summary-unmark-all-processable t]
2487          ["Invert marks" gnus-uu-invert-processable t]
2488          ["Mark above" gnus-uu-mark-over t]
2489          ["Mark series" gnus-uu-mark-series t]
2490          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2491          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2492          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2493          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2494          ["Mark all" gnus-uu-mark-all t]
2495          ["Mark buffer" gnus-uu-mark-buffer t]
2496          ["Mark sparse" gnus-uu-mark-sparse t]
2497          ["Mark thread" gnus-uu-mark-thread t]
2498          ["Unmark thread" gnus-uu-unmark-thread t]
2499          ("Process Mark Sets"
2500           ["Kill" gnus-summary-kill-process-mark t]
2501           ["Yank" gnus-summary-yank-process-mark
2502            gnus-newsgroup-process-stack]
2503           ["Save" gnus-summary-save-process-mark t]
2504           ["Run command on marked..." gnus-summary-universal-argument t]))
2505         ("Scroll article"
2506          ["Page forward" gnus-summary-next-page
2507           ,@(if (featurep 'xemacs) '(t)
2508               '(:help "Show next page of article"))]
2509          ["Page backward" gnus-summary-prev-page
2510           ,@(if (featurep 'xemacs) '(t)
2511               '(:help "Show previous page of article"))]
2512          ["Line forward" gnus-summary-scroll-up t])
2513         ("Move"
2514          ["Next unread article" gnus-summary-next-unread-article t]
2515          ["Previous unread article" gnus-summary-prev-unread-article t]
2516          ["Next article" gnus-summary-next-article t]
2517          ["Previous article" gnus-summary-prev-article t]
2518          ["Next unread subject" gnus-summary-next-unread-subject t]
2519          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2520          ["Next article same subject" gnus-summary-next-same-subject t]
2521          ["Previous article same subject" gnus-summary-prev-same-subject t]
2522          ["First unread article" gnus-summary-first-unread-article t]
2523          ["Best unread article" gnus-summary-best-unread-article t]
2524          ["Go to subject number..." gnus-summary-goto-subject t]
2525          ["Go to article number..." gnus-summary-goto-article t]
2526          ["Go to the last article" gnus-summary-goto-last-article t]
2527          ["Pop article off history" gnus-summary-pop-article t])
2528         ("Sort"
2529          ["Sort by number" gnus-summary-sort-by-number t]
2530          ["Sort by author" gnus-summary-sort-by-author t]
2531          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2532          ["Sort by subject" gnus-summary-sort-by-subject t]
2533          ["Sort by date" gnus-summary-sort-by-date t]
2534          ["Sort by score" gnus-summary-sort-by-score t]
2535          ["Sort by lines" gnus-summary-sort-by-lines t]
2536          ["Sort by characters" gnus-summary-sort-by-chars t]
2537          ["Randomize" gnus-summary-sort-by-random t]
2538          ["Original sort" gnus-summary-sort-by-original t])
2539         ("Help"
2540          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2541          ["Describe group" gnus-summary-describe-group t]
2542          ["Fetch charter" gnus-group-fetch-charter
2543           ,@(if (featurep 'xemacs) nil
2544               '(:help "Display the charter of the current group"))]
2545          ["Fetch control message" gnus-group-fetch-control
2546           ,@(if (featurep 'xemacs) nil
2547               '(:help "Display the archived control message for the current group"))]
2548          ["Read manual" gnus-info-find-node t])
2549         ("Modes"
2550          ["Pick and read" gnus-pick-mode t]
2551          ["Binary" gnus-binary-mode t])
2552         ("Regeneration"
2553          ["Regenerate" gnus-summary-prepare t]
2554          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2555          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2556          ["Toggle threading" gnus-summary-toggle-threads t])
2557         ["See old articles" gnus-summary-insert-old-articles t]
2558         ["See new articles" gnus-summary-insert-new-articles t]
2559         ["Filter articles..." gnus-summary-execute-command t]
2560         ["Run command on articles..." gnus-summary-universal-argument t]
2561         ["Search articles forward..." gnus-summary-search-article-forward t]
2562         ["Search articles backward..." gnus-summary-search-article-backward t]
2563         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2564         ["Expand window" gnus-summary-expand-window t]
2565         ["Expire expirable articles" gnus-summary-expire-articles
2566          (gnus-check-backend-function
2567           'request-expire-articles gnus-newsgroup-name)]
2568         ["Edit local kill file" gnus-summary-edit-local-kill t]
2569         ["Edit main kill file" gnus-summary-edit-global-kill t]
2570         ["Edit group parameters" gnus-summary-edit-parameters t]
2571         ["Customize group parameters" gnus-summary-customize-parameters t]
2572         ["Send a bug report" gnus-bug t]
2573         ("Exit"
2574          ["Catchup and exit" gnus-summary-catchup-and-exit
2575           ,@(if (featurep 'xemacs) '(t)
2576               '(:help "Mark unread articles in this group as read, then exit"))]
2577          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2578          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2579          ["Exit group" gnus-summary-exit
2580           ,@(if (featurep 'xemacs) '(t)
2581               '(:help "Exit current group, return to group selection mode"))]
2582          ["Exit group without updating" gnus-summary-exit-no-update t]
2583          ["Exit and goto next group" gnus-summary-next-group t]
2584          ["Exit and goto prev group" gnus-summary-prev-group t]
2585          ["Reselect group" gnus-summary-reselect-current-group t]
2586          ["Rescan group" gnus-summary-rescan-group t]
2587          ["Update dribble" gnus-summary-save-newsrc t])))
2588
2589     (gnus-run-hooks 'gnus-summary-menu-hook)))
2590
2591 (defvar gnus-summary-tool-bar-map nil)
2592
2593 ;; Emacs 21 tool bar.  Should be no-op otherwise.
2594 (defun gnus-summary-make-tool-bar ()
2595   (if (and (fboundp 'tool-bar-add-item-from-menu)
2596            (default-value 'tool-bar-mode)
2597            (not gnus-summary-tool-bar-map))
2598       (setq gnus-summary-tool-bar-map
2599             (let ((tool-bar-map (make-sparse-keymap))
2600                   (load-path (mm-image-load-path)))
2601               (tool-bar-add-item-from-menu
2602                'gnus-summary-prev-unread "prev-ur" gnus-summary-mode-map)
2603               (tool-bar-add-item-from-menu
2604                'gnus-summary-next-unread "next-ur" gnus-summary-mode-map)
2605               (tool-bar-add-item-from-menu
2606                'gnus-summary-post-news "post" gnus-summary-mode-map)
2607               (tool-bar-add-item-from-menu
2608                'gnus-summary-followup-with-original "fuwo" gnus-summary-mode-map)
2609               (tool-bar-add-item-from-menu
2610                'gnus-summary-followup "followup" gnus-summary-mode-map)
2611               (tool-bar-add-item-from-menu
2612                'gnus-summary-reply-with-original "reply-wo" gnus-summary-mode-map)
2613               (tool-bar-add-item-from-menu
2614                'gnus-summary-reply "reply" gnus-summary-mode-map)
2615               (tool-bar-add-item-from-menu
2616                'gnus-summary-caesar-message "rot13" gnus-summary-mode-map)
2617               (tool-bar-add-item-from-menu
2618                'gnus-uu-decode-uu "uu-decode" gnus-summary-mode-map)
2619               (tool-bar-add-item-from-menu
2620                'gnus-summary-save-article-file "save-aif" gnus-summary-mode-map)
2621               (tool-bar-add-item-from-menu
2622                'gnus-summary-save-article "save-art" gnus-summary-mode-map)
2623               (tool-bar-add-item-from-menu
2624                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2625               (tool-bar-add-item-from-menu
2626                'gnus-uu-post-news "uu-post" gnus-summary-mode-map)
2627               (tool-bar-add-item-from-menu
2628                'gnus-summary-catchup "catchup" gnus-summary-mode-map)
2629               (tool-bar-add-item-from-menu
2630                'gnus-summary-catchup-and-exit "cu-exit" gnus-summary-mode-map)
2631               (tool-bar-add-item-from-menu
2632                'gnus-summary-exit "exit-summ" gnus-summary-mode-map)
2633               tool-bar-map)))
2634   (if gnus-summary-tool-bar-map
2635       (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map)))
2636
2637 (defun gnus-score-set-default (var value)
2638   "A version of set that updates the GNU Emacs menu-bar."
2639   (set var value)
2640   ;; It is the message that forces the active status to be updated.
2641   (message ""))
2642
2643 (defun gnus-make-score-map (type)
2644   "Make a summary score map of type TYPE."
2645   (if t
2646       nil
2647     (let ((headers '(("author" "from" string)
2648                      ("subject" "subject" string)
2649                      ("article body" "body" string)
2650                      ("article head" "head" string)
2651                      ("xref" "xref" string)
2652                      ("extra header" "extra" string)
2653                      ("lines" "lines" number)
2654                      ("followups to author" "followup" string)))
2655           (types '((number ("less than" <)
2656                            ("greater than" >)
2657                            ("equal" =))
2658                    (string ("substring" s)
2659                            ("exact string" e)
2660                            ("fuzzy string" f)
2661                            ("regexp" r))))
2662           (perms '(("temporary" (current-time-string))
2663                    ("permanent" nil)
2664                    ("immediate" now)))
2665           header)
2666       (list
2667        (apply
2668         'nconc
2669         (list
2670          (if (eq type 'lower)
2671              "Lower score"
2672            "Increase score"))
2673         (let (outh)
2674           (while headers
2675             (setq header (car headers))
2676             (setq outh
2677                   (cons
2678                    (apply
2679                     'nconc
2680                     (list (car header))
2681                     (let ((ts (cdr (assoc (nth 2 header) types)))
2682                           outt)
2683                       (while ts
2684                         (setq outt
2685                               (cons
2686                                (apply
2687                                 'nconc
2688                                 (list (caar ts))
2689                                 (let ((ps perms)
2690                                       outp)
2691                                   (while ps
2692                                     (setq outp
2693                                           (cons
2694                                            (vector
2695                                             (caar ps)
2696                                             (list
2697                                              'gnus-summary-score-entry
2698                                              (nth 1 header)
2699                                              (if (or (string= (nth 1 header)
2700                                                               "head")
2701                                                      (string= (nth 1 header)
2702                                                               "body"))
2703                                                  ""
2704                                                (list 'gnus-summary-header
2705                                                      (nth 1 header)))
2706                                              (list 'quote (nth 1 (car ts)))
2707                                              (list 'gnus-score-delta-default
2708                                                    nil)
2709                                              (nth 1 (car ps))
2710                                              t)
2711                                             t)
2712                                            outp))
2713                                     (setq ps (cdr ps)))
2714                                   (list (nreverse outp))))
2715                                outt))
2716                         (setq ts (cdr ts)))
2717                       (list (nreverse outt))))
2718                    outh))
2719             (setq headers (cdr headers)))
2720           (list (nreverse outh))))))))
2721
2722 \f
2723
2724 (defun gnus-summary-mode (&optional group)
2725   "Major mode for reading articles.
2726
2727 All normal editing commands are switched off.
2728 \\<gnus-summary-mode-map>
2729 Each line in this buffer represents one article.  To read an
2730 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
2731 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
2732 respectively.
2733
2734 You can also post articles and send mail from this buffer.  To
2735 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
2736 of an article, type `\\[gnus-summary-reply]'.
2737
2738 There are approx. one gazillion commands you can execute in this
2739 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
2740
2741 The following commands are available:
2742
2743 \\{gnus-summary-mode-map}"
2744   (interactive)
2745   (kill-all-local-variables)
2746   (when (gnus-visual-p 'summary-menu 'menu)
2747     (gnus-summary-make-menu-bar)
2748     (gnus-summary-make-tool-bar))
2749   (gnus-summary-make-local-variables)
2750   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
2751     (gnus-summary-make-local-variables))
2752   (gnus-make-thread-indent-array)
2753   (gnus-simplify-mode-line)
2754   (setq major-mode 'gnus-summary-mode)
2755   (setq mode-name "Summary")
2756   (make-local-variable 'minor-mode-alist)
2757   (use-local-map gnus-summary-mode-map)
2758   (buffer-disable-undo)
2759   (setq buffer-read-only t              ;Disable modification
2760         show-trailing-whitespace nil)
2761   (setq truncate-lines t)
2762   (setq selective-display t)
2763   (setq selective-display-ellipses t)   ;Display `...'
2764   (gnus-summary-set-display-table)
2765   (gnus-set-default-directory)
2766   (setq gnus-newsgroup-name group)
2767   (unless (gnus-news-group-p group)
2768     (setq gnus-newsgroup-incorporated
2769           (nnmail-new-mail-numbers (gnus-group-real-name group))))
2770   (make-local-variable 'gnus-summary-line-format)
2771   (make-local-variable 'gnus-summary-line-format-spec)
2772   (make-local-variable 'gnus-summary-dummy-line-format)
2773   (make-local-variable 'gnus-summary-dummy-line-format-spec)
2774   (make-local-variable 'gnus-summary-mark-positions)
2775   (gnus-make-local-hook 'pre-command-hook)
2776   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
2777   (gnus-run-hooks 'gnus-summary-mode-hook)
2778   (turn-on-gnus-mailing-list-mode)
2779   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
2780   (gnus-update-summary-mark-positions))
2781
2782 (defun gnus-summary-make-local-variables ()
2783   "Make all the local summary buffer variables."
2784   (let (global)
2785     (dolist (local gnus-summary-local-variables)
2786       (if (consp local)
2787           (progn
2788             (if (eq (cdr local) 'global)
2789                 ;; Copy the global value of the variable.
2790                 (setq global (symbol-value (car local)))
2791               ;; Use the value from the list.
2792               (setq global (eval (cdr local))))
2793             (set (make-local-variable (car local)) global))
2794         ;; Simple nil-valued local variable.
2795         (set (make-local-variable local) nil)))))
2796
2797 (defun gnus-summary-clear-local-variables ()
2798   (let ((locals gnus-summary-local-variables))
2799     (while locals
2800       (if (consp (car locals))
2801           (and (symbolp (caar locals))
2802                (set (caar locals) nil))
2803         (and (symbolp (car locals))
2804              (set (car locals) nil)))
2805       (setq locals (cdr locals)))))
2806
2807 ;; Summary data functions.
2808
2809 (defmacro gnus-data-number (data)
2810   `(car ,data))
2811
2812 (defmacro gnus-data-set-number (data number)
2813   `(setcar ,data ,number))
2814
2815 (defmacro gnus-data-mark (data)
2816   `(nth 1 ,data))
2817
2818 (defmacro gnus-data-set-mark (data mark)
2819   `(setcar (nthcdr 1 ,data) ,mark))
2820
2821 (defmacro gnus-data-pos (data)
2822   `(nth 2 ,data))
2823
2824 (defmacro gnus-data-set-pos (data pos)
2825   `(setcar (nthcdr 2 ,data) ,pos))
2826
2827 (defmacro gnus-data-header (data)
2828   `(nth 3 ,data))
2829
2830 (defmacro gnus-data-set-header (data header)
2831   `(setcar (nthcdr 3 ,data) ,header))
2832
2833 (defmacro gnus-data-level (data)
2834   `(nth 4 ,data))
2835
2836 (defmacro gnus-data-unread-p (data)
2837   `(= (nth 1 ,data) gnus-unread-mark))
2838
2839 (defmacro gnus-data-read-p (data)
2840   `(/= (nth 1 ,data) gnus-unread-mark))
2841
2842 (defmacro gnus-data-pseudo-p (data)
2843   `(consp (nth 3 ,data)))
2844
2845 (defmacro gnus-data-find (number)
2846   `(assq ,number gnus-newsgroup-data))
2847
2848 (defmacro gnus-data-find-list (number &optional data)
2849   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
2850      (memq (assq ,number bdata)
2851            bdata)))
2852
2853 (defmacro gnus-data-make (number mark pos header level)
2854   `(list ,number ,mark ,pos ,header ,level))
2855
2856 (defun gnus-data-enter (after-article number mark pos header level offset)
2857   (let ((data (gnus-data-find-list after-article)))
2858     (unless data
2859       (error "No such article: %d" after-article))
2860     (setcdr data (cons (gnus-data-make number mark pos header level)
2861                        (cdr data)))
2862     (setq gnus-newsgroup-data-reverse nil)
2863     (gnus-data-update-list (cddr data) offset)))
2864
2865 (defun gnus-data-enter-list (after-article list &optional offset)
2866   (when list
2867     (let ((data (and after-article (gnus-data-find-list after-article)))
2868           (ilist list))
2869       (if (not (or data
2870                    after-article))
2871           (let ((odata gnus-newsgroup-data))
2872             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
2873             (when offset
2874               (gnus-data-update-list odata offset)))
2875         ;; Find the last element in the list to be spliced into the main
2876         ;; list.
2877         (setq list (last list))
2878         (if (not data)
2879             (progn
2880               (setcdr list gnus-newsgroup-data)
2881               (setq gnus-newsgroup-data ilist)
2882               (when offset
2883                 (gnus-data-update-list (cdr list) offset)))
2884           (setcdr list (cdr data))
2885           (setcdr data ilist)
2886           (when offset
2887             (gnus-data-update-list (cdr list) offset))))
2888       (setq gnus-newsgroup-data-reverse nil))))
2889
2890 (defun gnus-data-remove (article &optional offset)
2891   (let ((data gnus-newsgroup-data))
2892     (if (= (gnus-data-number (car data)) article)
2893         (progn
2894           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
2895                 gnus-newsgroup-data-reverse nil)
2896           (when offset
2897             (gnus-data-update-list gnus-newsgroup-data offset)))
2898       (while (cdr data)
2899         (when (= (gnus-data-number (cadr data)) article)
2900           (setcdr data (cddr data))
2901           (when offset
2902             (gnus-data-update-list (cdr data) offset))
2903           (setq data nil
2904                 gnus-newsgroup-data-reverse nil))
2905         (setq data (cdr data))))))
2906
2907 (defmacro gnus-data-list (backward)
2908   `(if ,backward
2909        (or gnus-newsgroup-data-reverse
2910            (setq gnus-newsgroup-data-reverse
2911                  (reverse gnus-newsgroup-data)))
2912      gnus-newsgroup-data))
2913
2914 (defun gnus-data-update-list (data offset)
2915   "Add OFFSET to the POS of all data entries in DATA."
2916   (setq gnus-newsgroup-data-reverse nil)
2917   (while data
2918     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
2919     (setq data (cdr data))))
2920
2921 (defun gnus-summary-article-pseudo-p (article)
2922   "Say whether this article is a pseudo article or not."
2923   (not (vectorp (gnus-data-header (gnus-data-find article)))))
2924
2925 (defmacro gnus-summary-article-sparse-p (article)
2926   "Say whether this article is a sparse article or not."
2927   `(memq ,article gnus-newsgroup-sparse))
2928
2929 (defmacro gnus-summary-article-ancient-p (article)
2930   "Say whether this article is a sparse article or not."
2931   `(memq ,article gnus-newsgroup-ancient))
2932
2933 (defun gnus-article-parent-p (number)
2934   "Say whether this article is a parent or not."
2935   (let ((data (gnus-data-find-list number)))
2936     (and (cdr data)                     ; There has to be an article after...
2937          (< (gnus-data-level (car data)) ; And it has to have a higher level.
2938             (gnus-data-level (nth 1 data))))))
2939
2940 (defun gnus-article-children (number)
2941   "Return a list of all children to NUMBER."
2942   (let* ((data (gnus-data-find-list number))
2943          (level (gnus-data-level (car data)))
2944          children)
2945     (setq data (cdr data))
2946     (while (and data
2947                 (= (gnus-data-level (car data)) (1+ level)))
2948       (push (gnus-data-number (car data)) children)
2949       (setq data (cdr data)))
2950     children))
2951
2952 (defmacro gnus-summary-skip-intangible ()
2953   "If the current article is intangible, then jump to a different article."
2954   '(let ((to (get-text-property (point) 'gnus-intangible)))
2955      (and to (gnus-summary-goto-subject to))))
2956
2957 (defmacro gnus-summary-article-intangible-p ()
2958   "Say whether this article is intangible or not."
2959   '(get-text-property (point) 'gnus-intangible))
2960
2961 (defun gnus-article-read-p (article)
2962   "Say whether ARTICLE is read or not."
2963   (not (or (memq article gnus-newsgroup-marked)
2964            (memq article gnus-newsgroup-spam-marked)
2965            (memq article gnus-newsgroup-unreads)
2966            (memq article gnus-newsgroup-unselected)
2967            (memq article gnus-newsgroup-dormant))))
2968
2969 ;; Some summary mode macros.
2970
2971 (defmacro gnus-summary-article-number ()
2972   "The article number of the article on the current line.
2973 If there isn't an article number here, then we return the current
2974 article number."
2975   '(progn
2976      (gnus-summary-skip-intangible)
2977      (or (get-text-property (point) 'gnus-number)
2978          (gnus-summary-last-subject))))
2979
2980 (defmacro gnus-summary-article-header (&optional number)
2981   "Return the header of article NUMBER."
2982   `(gnus-data-header (gnus-data-find
2983                       ,(or number '(gnus-summary-article-number)))))
2984
2985 (defmacro gnus-summary-thread-level (&optional number)
2986   "Return the level of thread that starts with article NUMBER."
2987   `(if (and (eq gnus-summary-make-false-root 'dummy)
2988             (get-text-property (point) 'gnus-intangible))
2989        0
2990      (gnus-data-level (gnus-data-find
2991                        ,(or number '(gnus-summary-article-number))))))
2992
2993 (defmacro gnus-summary-article-mark (&optional number)
2994   "Return the mark of article NUMBER."
2995   `(gnus-data-mark (gnus-data-find
2996                     ,(or number '(gnus-summary-article-number)))))
2997
2998 (defmacro gnus-summary-article-pos (&optional number)
2999   "Return the position of the line of article NUMBER."
3000   `(gnus-data-pos (gnus-data-find
3001                    ,(or number '(gnus-summary-article-number)))))
3002
3003 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3004 (defmacro gnus-summary-article-subject (&optional number)
3005   "Return current subject string or nil if nothing."
3006   `(let ((headers
3007           ,(if number
3008                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3009              '(gnus-data-header (assq (gnus-summary-article-number)
3010                                       gnus-newsgroup-data)))))
3011      (and headers
3012           (vectorp headers)
3013           (mail-header-subject headers))))
3014
3015 (defmacro gnus-summary-article-score (&optional number)
3016   "Return current article score."
3017   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3018                   gnus-newsgroup-scored))
3019        gnus-summary-default-score 0))
3020
3021 (defun gnus-summary-article-children (&optional number)
3022   "Return a list of article numbers that are children of article NUMBER."
3023   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3024          (level (gnus-data-level (car data)))
3025          l children)
3026     (while (and (setq data (cdr data))
3027                 (> (setq l (gnus-data-level (car data))) level))
3028       (and (= (1+ level) l)
3029            (push (gnus-data-number (car data))
3030                  children)))
3031     (nreverse children)))
3032
3033 (defun gnus-summary-article-parent (&optional number)
3034   "Return the article number of the parent of article NUMBER."
3035   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3036                                     (gnus-data-list t)))
3037          (level (gnus-data-level (car data))))
3038     (if (zerop level)
3039         ()                              ; This is a root.
3040       ;; We search until we find an article with a level less than
3041       ;; this one.  That function has to be the parent.
3042       (while (and (setq data (cdr data))
3043                   (not (< (gnus-data-level (car data)) level))))
3044       (and data (gnus-data-number (car data))))))
3045
3046 (defun gnus-unread-mark-p (mark)
3047   "Say whether MARK is the unread mark."
3048   (= mark gnus-unread-mark))
3049
3050 (defun gnus-read-mark-p (mark)
3051   "Say whether MARK is one of the marks that mark as read.
3052 This is all marks except unread, ticked, dormant, and expirable."
3053   (not (or (= mark gnus-unread-mark)
3054            (= mark gnus-ticked-mark)
3055            (= mark gnus-spam-mark)
3056            (= mark gnus-dormant-mark)
3057            (= mark gnus-expirable-mark))))
3058
3059 (defmacro gnus-article-mark (number)
3060   "Return the MARK of article NUMBER.
3061 This macro should only be used when computing the mark the \"first\"
3062 time; i.e., when generating the summary lines.  After that,
3063 `gnus-summary-article-mark' should be used to examine the
3064 marks of articles."
3065   `(cond
3066     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3067     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3068     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3069     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3070     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3071     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3072     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3073     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3074            gnus-ancient-mark))))
3075
3076 ;; Saving hidden threads.
3077
3078 (defmacro gnus-save-hidden-threads (&rest forms)
3079   "Save hidden threads, eval FORMS, and restore the hidden threads."
3080   (let ((config (make-symbol "config")))
3081     `(let ((,config (gnus-hidden-threads-configuration)))
3082        (unwind-protect
3083            (save-excursion
3084              ,@forms)
3085          (gnus-restore-hidden-threads-configuration ,config)))))
3086 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3087 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3088
3089 (defun gnus-data-compute-positions ()
3090   "Compute the positions of all articles."
3091   (setq gnus-newsgroup-data-reverse nil)
3092   (let ((data gnus-newsgroup-data))
3093     (save-excursion
3094       (gnus-save-hidden-threads
3095         (gnus-summary-show-all-threads)
3096         (goto-char (point-min))
3097         (while data
3098           (while (get-text-property (point) 'gnus-intangible)
3099             (forward-line 1))
3100           (gnus-data-set-pos (car data) (+ (point) 3))
3101           (setq data (cdr data))
3102           (forward-line 1))))))
3103
3104 (defun gnus-hidden-threads-configuration ()
3105   "Return the current hidden threads configuration."
3106   (save-excursion
3107     (let (config)
3108       (goto-char (point-min))
3109       (while (search-forward "\r" nil t)
3110         (push (1- (point)) config))
3111       config)))
3112
3113 (defun gnus-restore-hidden-threads-configuration (config)
3114   "Restore hidden threads configuration from CONFIG."
3115   (save-excursion
3116     (let (point buffer-read-only)
3117       (while (setq point (pop config))
3118         (when (and (< point (point-max))
3119                    (goto-char point)
3120                    (eq (char-after) ?\n))
3121           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3122
3123 ;; Various summary mode internalish functions.
3124
3125 (defun gnus-mouse-pick-article (e)
3126   (interactive "e")
3127   (mouse-set-point e)
3128   (gnus-summary-next-page nil t))
3129
3130 (defun gnus-summary-set-display-table ()
3131   "Change the display table.
3132 Odd characters have a tendency to mess
3133 up nicely formatted displays - we make all possible glyphs
3134 display only a single character."
3135
3136   ;; We start from the standard display table, if any.
3137   (let ((table (or (copy-sequence standard-display-table)
3138                    (make-display-table)))
3139         (i 32))
3140     ;; Nix out all the control chars...
3141     (while (>= (setq i (1- i)) 0)
3142       (aset table i [??]))
3143     ;; ... but not newline and cr, of course.  (cr is necessary for the
3144     ;; selective display).
3145     (aset table ?\n nil)
3146     (aset table ?\r nil)
3147     ;; We keep TAB as well.
3148     (aset table ?\t nil)
3149     ;; We nix out any glyphs over 126 that are not set already.
3150     (let ((i 256))
3151       (while (>= (setq i (1- i)) 127)
3152         ;; Only modify if the entry is nil.
3153         (unless (aref table i)
3154           (aset table i [??]))))
3155     (setq buffer-display-table table)))
3156
3157 (defun gnus-summary-set-article-display-arrow (pos)
3158   "Update the overlay arrow to point to line at position POS."
3159   (when (and gnus-summary-display-arrow
3160              (boundp 'overlay-arrow-position)
3161              (boundp 'overlay-arrow-string))
3162     (save-excursion
3163       (goto-char pos)
3164       (beginning-of-line)
3165       (unless overlay-arrow-position
3166         (setq overlay-arrow-position (make-marker)))
3167       (setq overlay-arrow-string "=>"
3168             overlay-arrow-position (set-marker overlay-arrow-position
3169                                                (point)
3170                                                (current-buffer))))))
3171
3172 (defun gnus-summary-setup-buffer (group)
3173   "Initialize summary buffer."
3174   (let ((buffer (gnus-summary-buffer-name group))
3175         (dead-name (concat "*Dead Summary "
3176                            (gnus-group-decoded-name group) "*")))
3177     ;; If a dead summary buffer exists, we kill it.
3178     (when (gnus-buffer-live-p dead-name)
3179       (gnus-kill-buffer dead-name))
3180     (if (get-buffer buffer)
3181         (progn
3182           (set-buffer buffer)
3183           (setq gnus-summary-buffer (current-buffer))
3184           (not gnus-newsgroup-prepared))
3185       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3186       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3187       (gnus-summary-mode group)
3188       (when gnus-carpal
3189         (gnus-carpal-setup-buffer 'summary))
3190       (unless gnus-single-article-buffer
3191         (make-local-variable 'gnus-article-buffer)
3192         (make-local-variable 'gnus-article-current)
3193         (make-local-variable 'gnus-original-article-buffer))
3194       (setq gnus-newsgroup-name group)
3195       ;; Set any local variables in the group parameters.
3196       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3197       t)))
3198
3199 (defun gnus-set-global-variables ()
3200   "Set the global equivalents of the buffer-local variables.
3201 They are set to the latest values they had.  These reflect the summary
3202 buffer that was in action when the last article was fetched."
3203   (when (eq major-mode 'gnus-summary-mode)
3204     (setq gnus-summary-buffer (current-buffer))
3205     (let ((name gnus-newsgroup-name)
3206           (marked gnus-newsgroup-marked)
3207           (spam gnus-newsgroup-spam-marked)
3208           (unread gnus-newsgroup-unreads)
3209           (headers gnus-current-headers)
3210           (data gnus-newsgroup-data)
3211           (summary gnus-summary-buffer)
3212           (article-buffer gnus-article-buffer)
3213           (original gnus-original-article-buffer)
3214           (gac gnus-article-current)
3215           (reffed gnus-reffed-article-number)
3216           (score-file gnus-current-score-file)
3217           (default-charset gnus-newsgroup-charset)
3218           vlist)
3219       (let ((locals gnus-newsgroup-variables))
3220         (while locals
3221           (if (consp (car locals))
3222               (push (eval (caar locals)) vlist)
3223             (push (eval (car locals)) vlist))
3224           (setq locals (cdr locals)))
3225         (setq vlist (nreverse vlist)))
3226       (with-current-buffer gnus-group-buffer
3227         (setq gnus-newsgroup-name name
3228               gnus-newsgroup-marked marked
3229               gnus-newsgroup-spam-marked spam
3230               gnus-newsgroup-unreads unread
3231               gnus-current-headers headers
3232               gnus-newsgroup-data data
3233               gnus-article-current gac
3234               gnus-summary-buffer summary
3235               gnus-article-buffer article-buffer
3236               gnus-original-article-buffer original
3237               gnus-reffed-article-number reffed
3238               gnus-current-score-file score-file
3239               gnus-newsgroup-charset default-charset)
3240         (let ((locals gnus-newsgroup-variables))
3241           (while locals
3242             (if (consp (car locals))
3243                 (set (caar locals) (pop vlist))
3244               (set (car locals) (pop vlist)))
3245             (setq locals (cdr locals))))
3246         ;; The article buffer also has local variables.
3247         (when (gnus-buffer-live-p gnus-article-buffer)
3248           (set-buffer gnus-article-buffer)
3249           (setq gnus-summary-buffer summary))))))
3250
3251 (defun gnus-summary-article-unread-p (article)
3252   "Say whether ARTICLE is unread or not."
3253   (memq article gnus-newsgroup-unreads))
3254
3255 (defun gnus-summary-first-article-p (&optional article)
3256   "Return whether ARTICLE is the first article in the buffer."
3257   (if (not (setq article (or article (gnus-summary-article-number))))
3258       nil
3259     (eq article (caar gnus-newsgroup-data))))
3260
3261 (defun gnus-summary-last-article-p (&optional article)
3262   "Return whether ARTICLE is the last article in the buffer."
3263   (if (not (setq article (or article (gnus-summary-article-number))))
3264       ;; All non-existent numbers are the last article.  :-)
3265       t
3266     (not (cdr (gnus-data-find-list article)))))
3267
3268 (defun gnus-make-thread-indent-array ()
3269   (let ((n 200))
3270     (unless (and gnus-thread-indent-array
3271                  (= gnus-thread-indent-level gnus-thread-indent-array-level))
3272       (setq gnus-thread-indent-array (make-vector 201 "")
3273             gnus-thread-indent-array-level gnus-thread-indent-level)
3274       (while (>= n 0)
3275         (aset gnus-thread-indent-array n
3276               (make-string (* n gnus-thread-indent-level) ? ))
3277         (setq n (1- n))))))
3278
3279 (defun gnus-update-summary-mark-positions ()
3280   "Compute where the summary marks are to go."
3281   (save-excursion
3282     (when (gnus-buffer-exists-p gnus-summary-buffer)
3283       (set-buffer gnus-summary-buffer))
3284     (let ((spec gnus-summary-line-format-spec)
3285           pos)
3286       (save-excursion
3287         (gnus-set-work-buffer)
3288         (let ((gnus-tmp-unread ?Z)
3289               (gnus-replied-mark ?Z)
3290               (gnus-score-below-mark ?Z)
3291               (gnus-score-over-mark ?Z)
3292               (gnus-undownloaded-mark ?Z)
3293               (gnus-summary-line-format-spec spec)
3294               (gnus-newsgroup-downloadable '(0))
3295               (header
3296                (make-full-mail-header
3297                 0 "" "nobody" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil))
3298               case-fold-search ignores)
3299           ;; Here, all marks are bound to Z.
3300           (gnus-summary-insert-line header
3301                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3302           (goto-char (point-min))
3303           ;; Memorize the positions of the same characters as dummy marks.
3304           (while (re-search-forward "[A-D]" nil t)
3305             (push (point) ignores))
3306           (erase-buffer)
3307           ;; We use A-D as dummy marks in order to know column positions
3308           ;; where marks should be inserted.
3309           (setq gnus-tmp-unread ?A
3310                 gnus-replied-mark ?B
3311                 gnus-score-below-mark ?C
3312                 gnus-score-over-mark ?C
3313                 gnus-undownloaded-mark ?D)
3314           (gnus-summary-insert-line header
3315                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3316           ;; Ignore characters which aren't dummy marks.
3317           (dolist (p ignores)
3318             (delete-region (goto-char (1- p)) p)
3319             (insert ?Z))
3320           (goto-char (point-min))
3321           (setq pos (list (cons 'unread
3322                                 (and (search-forward "A" nil t)
3323                                      (- (point) (point-min) 1)))))
3324           (goto-char (point-min))
3325           (push (cons 'replied (and (search-forward "B" nil t)
3326                                     (- (point) (point-min) 1)))
3327                 pos)
3328           (goto-char (point-min))
3329           (push (cons 'score (and (search-forward "C" nil t)
3330                                   (- (point) (point-min) 1)))
3331                 pos)
3332           (goto-char (point-min))
3333           (push (cons 'download (and (search-forward "D" nil t)
3334                                      (- (point) (point-min) 1)))
3335                 pos)))
3336       (setq gnus-summary-mark-positions pos))))
3337
3338 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3339   "Insert a dummy root in the summary buffer."
3340   (beginning-of-line)
3341   (gnus-add-text-properties
3342    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3343    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3344
3345 (defun gnus-summary-extract-address-component (from)
3346   (or (car (funcall gnus-extract-address-components from))
3347       from))
3348
3349 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3350   (let ((default-mime-charset (with-current-buffer gnus-summary-buffer
3351                                 default-mime-charset)))
3352     ;; Is it really necessary to do this next part for each summary line?
3353     ;; Luckily, doesn't seem to slow things down much.
3354     (or
3355      (and gnus-ignored-from-addresses
3356           (string-match gnus-ignored-from-addresses gnus-tmp-from)
3357           (let ((extra-headers (mail-header-extra header))
3358                 to
3359                 newsgroups)
3360             (cond
3361              ((setq to (cdr (assq 'To extra-headers)))
3362               (concat "-> "
3363                       (inline
3364                         (gnus-summary-extract-address-component
3365                          (funcall gnus-decode-encoded-word-function to)))))
3366              ((setq newsgroups (cdr (assq 'Newsgroups extra-headers)))
3367               (concat "=> " newsgroups)))))
3368      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3369
3370 (defun gnus-summary-insert-line (gnus-tmp-header
3371                                  gnus-tmp-level gnus-tmp-current
3372                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3373                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3374                                  &optional gnus-tmp-dummy gnus-tmp-score
3375                                  gnus-tmp-process)
3376   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3377          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3378          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3379          (gnus-tmp-score-char
3380           (if (or (null gnus-summary-default-score)
3381                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3382                       gnus-summary-zcore-fuzz))
3383               ?\ ;;;Whitespace
3384             (if (< gnus-tmp-score gnus-summary-default-score)
3385                 gnus-score-below-mark gnus-score-over-mark)))
3386          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3387          (gnus-tmp-replied
3388           (cond (gnus-tmp-process gnus-process-mark)
3389                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3390                  gnus-cached-mark)
3391                 (gnus-tmp-replied gnus-replied-mark)
3392                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3393                  gnus-forwarded-mark)
3394                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3395                  gnus-saved-mark)
3396                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3397                  gnus-recent-mark)
3398                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3399                  gnus-unseen-mark)
3400                 (t gnus-no-mark)))
3401          (gnus-tmp-downloaded
3402           (cond (undownloaded
3403                  gnus-undownloaded-mark)
3404                 (gnus-newsgroup-agentized
3405                  gnus-downloaded-mark)
3406                 (t
3407                  gnus-no-mark)))
3408          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3409          (gnus-tmp-name
3410           (cond
3411            ((string-match "<[^>]+> *$" gnus-tmp-from)
3412             (let ((beg (match-beginning 0)))
3413               (or (and (string-match "^\".+\"" gnus-tmp-from)
3414                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3415                   (substring gnus-tmp-from 0 beg))))
3416            ((string-match "(.+)" gnus-tmp-from)
3417             (substring gnus-tmp-from
3418                        (1+ (match-beginning 0)) (1- (match-end 0))))
3419            (t gnus-tmp-from)))
3420          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3421          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3422          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3423          (buffer-read-only nil))
3424     (when (string= gnus-tmp-name "")
3425       (setq gnus-tmp-name gnus-tmp-from))
3426     (unless (numberp gnus-tmp-lines)
3427       (setq gnus-tmp-lines -1))
3428     (if (= gnus-tmp-lines -1)
3429         (setq gnus-tmp-lines "?")
3430       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3431     (gnus-put-text-property-excluding-characters-with-faces
3432      (point)
3433      (progn (eval gnus-summary-line-format-spec) (point))
3434      'gnus-number gnus-tmp-number)
3435     (when (gnus-visual-p 'summary-highlight 'highlight)
3436       (forward-line -1)
3437       (gnus-run-hooks 'gnus-summary-update-hook)
3438       (forward-line 1))))
3439
3440 (defun gnus-summary-update-line (&optional dont-update)
3441   "Update summary line after change."
3442   (when (and gnus-summary-default-score
3443              (not gnus-summary-inhibit-highlight))
3444     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3445            (article (gnus-summary-article-number))
3446            (score (gnus-summary-article-score article)))
3447       (unless dont-update
3448         (if (and gnus-summary-mark-below
3449                  (< (gnus-summary-article-score)
3450                     gnus-summary-mark-below))
3451             ;; This article has a low score, so we mark it as read.
3452             (when (memq article gnus-newsgroup-unreads)
3453               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3454           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3455             ;; This article was previously marked as read on account
3456             ;; of a low score, but now it has risen, so we mark it as
3457             ;; unread.
3458             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3459         (gnus-summary-update-mark
3460          (if (or (null gnus-summary-default-score)
3461                  (<= (abs (- score gnus-summary-default-score))
3462                      gnus-summary-zcore-fuzz))
3463              ?\ ;;;Whitespace
3464            (if (< score gnus-summary-default-score)
3465                gnus-score-below-mark gnus-score-over-mark))
3466          'score))
3467       ;; Do visual highlighting.
3468       (when (gnus-visual-p 'summary-highlight 'highlight)
3469         (gnus-run-hooks 'gnus-summary-update-hook)))))
3470
3471 (defvar gnus-tmp-new-adopts nil)
3472
3473 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3474   "Return the number of articles in THREAD.
3475 This may be 0 in some cases -- if none of the articles in
3476 the thread are to be displayed."
3477   (let* ((number
3478           ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3479           (cond
3480            ((not (listp thread))
3481             1)
3482            ((and (consp thread) (cdr thread))
3483             (apply
3484              '+ 1 (mapcar
3485                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3486            ((null thread)
3487             1)
3488            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3489             1)
3490            (t 0))))
3491     (when (and level (zerop level) gnus-tmp-new-adopts)
3492       (incf number
3493             (apply '+ (mapcar
3494                        'gnus-summary-number-of-articles-in-thread
3495                        gnus-tmp-new-adopts))))
3496     (if char
3497         (if (> number 1) gnus-not-empty-thread-mark
3498           gnus-empty-thread-mark)
3499       number)))
3500
3501 (defsubst gnus-summary-line-message-size (head)
3502   "Return pretty-printed version of message size.
3503 This function is intended to be used in
3504 `gnus-summary-line-format-alist'."
3505   (let ((c (or (mail-header-chars head) -1)))
3506     (cond ((< c 0) "n/a")               ; chars not available
3507           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3508           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3509           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3510           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3511
3512
3513 (defun gnus-summary-set-local-parameters (group)
3514   "Go through the local params of GROUP and set all variable specs in that list."
3515   (let ((vars '(quit-config)))          ; Ignore quit-config.
3516     (dolist (elem (gnus-group-find-parameter group))
3517       (and (consp elem)                 ; Has to be a cons.
3518            (consp (cdr elem))           ; The cdr has to be a list.
3519            (symbolp (car elem))         ; Has to be a symbol in there.
3520            (not (memq (car elem) vars))
3521            (ignore-errors               ; So we set it.
3522              (push (car elem) vars)
3523              (make-local-variable (car elem))
3524              (set (car elem) (eval (nth 1 elem))))))))
3525
3526 (defun gnus-summary-read-group (group &optional show-all no-article
3527                                       kill-buffer no-display backward
3528                                       select-articles)
3529   "Start reading news in newsgroup GROUP.
3530 If SHOW-ALL is non-nil, already read articles are also listed.
3531 If NO-ARTICLE is non-nil, no article is selected initially.
3532 If NO-DISPLAY, don't generate a summary buffer."
3533   (let (result)
3534     (while (and group
3535                 (null (setq result
3536                             (let ((gnus-auto-select-next nil))
3537                               (or (gnus-summary-read-group-1
3538                                    group show-all no-article
3539                                    kill-buffer no-display
3540                                    select-articles)
3541                                   (setq show-all nil
3542                                         select-articles nil)))))
3543                 (eq gnus-auto-select-next 'quietly))
3544       (set-buffer gnus-group-buffer)
3545       ;; The entry function called above goes to the next
3546       ;; group automatically, so we go two groups back
3547       ;; if we are searching for the previous group.
3548       (when backward
3549         (gnus-group-prev-unread-group 2))
3550       (if (not (equal group (gnus-group-group-name)))
3551           (setq group (gnus-group-group-name))
3552         (setq group nil)))
3553     result))
3554
3555 (defun gnus-summary-jump-to-other-group (group &optional show-all)
3556   "Directly jump to the other GROUP from summary buffer.
3557 If SHOW-ALL is non-nil, already read articles are also listed."
3558   (interactive
3559    (if (eq gnus-summary-buffer (current-buffer))
3560        (list (completing-read
3561               "Group: " gnus-active-hashtb nil t
3562               (when (and gnus-newsgroup-name
3563                          (string-match "[.:][^.:]+$" gnus-newsgroup-name))
3564                 (substring gnus-newsgroup-name 0 (1+ (match-beginning 0))))
3565               'gnus-group-history)
3566              current-prefix-arg)
3567      (error "%s must be invoked from a gnus summary buffer." this-command)))
3568   (unless (or (zerop (length group))
3569               (and gnus-newsgroup-name
3570                    (string-equal gnus-newsgroup-name group)))
3571     (gnus-summary-exit)
3572     (gnus-summary-read-group group show-all
3573                              gnus-dont-select-after-jump-to-other-group)))
3574
3575 (defun gnus-summary-read-group-1 (group show-all no-article
3576                                         kill-buffer no-display
3577                                         &optional select-articles)
3578   ;; Killed foreign groups can't be entered.
3579   ;;  (when (and (not (gnus-group-native-p group))
3580   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3581   ;;    (error "Dead non-native groups can't be entered"))
3582   (gnus-message 5 "Retrieving newsgroup: %s..."
3583                 (gnus-group-decoded-name group))
3584   (let* ((new-group (gnus-summary-setup-buffer group))
3585          (quit-config (gnus-group-quit-config group))
3586          (did-select (and new-group (gnus-select-newsgroup
3587                                      group show-all select-articles))))
3588     (cond
3589      ;; This summary buffer exists already, so we just select it.
3590      ((not new-group)
3591       (gnus-set-global-variables)
3592       (when kill-buffer
3593         (gnus-kill-or-deaden-summary kill-buffer))
3594       (gnus-configure-windows 'summary 'force)
3595       (gnus-set-mode-line 'summary)
3596       (gnus-summary-position-point)
3597       (message "")
3598       t)
3599      ;; We couldn't select this group.
3600      ((null did-select)
3601       (when (and (eq major-mode 'gnus-summary-mode)
3602                  (not (equal (current-buffer) kill-buffer)))
3603         (kill-buffer (current-buffer))
3604         (if (not quit-config)
3605             (progn
3606               ;; Update the info -- marks might need to be removed,
3607               ;; for instance.
3608               (gnus-summary-update-info)
3609               (set-buffer gnus-group-buffer)
3610               (gnus-group-jump-to-group group)
3611               (gnus-group-next-unread-group 1))
3612           (gnus-handle-ephemeral-exit quit-config)))
3613       (let ((grpinfo (gnus-get-info group)))
3614         (if (null (gnus-info-read grpinfo))
3615             (gnus-message 3 "Group %s contains no messages"
3616                           (gnus-group-decoded-name group))
3617           (gnus-message 3 "Can't select group")))
3618       nil)
3619      ;; The user did a `C-g' while prompting for number of articles,
3620      ;; so we exit this group.
3621      ((eq did-select 'quit)
3622       (and (eq major-mode 'gnus-summary-mode)
3623            (not (equal (current-buffer) kill-buffer))
3624            (kill-buffer (current-buffer)))
3625       (when kill-buffer
3626         (gnus-kill-or-deaden-summary kill-buffer))
3627       (if (not quit-config)
3628           (progn
3629             (set-buffer gnus-group-buffer)
3630             (gnus-group-jump-to-group group)
3631             (gnus-group-next-unread-group 1)
3632             (gnus-configure-windows 'group 'force))
3633         (gnus-handle-ephemeral-exit quit-config))
3634       ;; Finally signal the quit.
3635       (signal 'quit nil))
3636      ;; The group was successfully selected.
3637      (t
3638       (gnus-set-global-variables)
3639       ;; Save the active value in effect when the group was entered.
3640       (setq gnus-newsgroup-active
3641             (gnus-copy-sequence
3642              (gnus-active gnus-newsgroup-name)))
3643       ;; You can change the summary buffer in some way with this hook.
3644       (gnus-run-hooks 'gnus-select-group-hook)
3645       (when (memq 'summary (gnus-update-format-specifications
3646                             nil 'summary 'summary-mode 'summary-dummy))
3647         ;; The format specification for the summary line was updated,
3648         ;; so we need to update the mark positions as well.
3649         (gnus-update-summary-mark-positions))
3650       ;; Do score processing.
3651       (when gnus-use-scoring
3652         (gnus-possibly-score-headers))
3653       ;; Check whether to fill in the gaps in the threads.
3654       (when gnus-build-sparse-threads
3655         (gnus-build-sparse-threads))
3656       ;; Find the initial limit.
3657       (if show-all
3658           (let ((gnus-newsgroup-dormant nil))
3659             (gnus-summary-initial-limit show-all))
3660         (gnus-summary-initial-limit show-all))
3661       ;; Generate the summary buffer.
3662       (unless no-display
3663         (gnus-summary-prepare))
3664       (when gnus-use-trees
3665         (gnus-tree-open group)
3666         (setq gnus-summary-highlight-line-function
3667               'gnus-tree-highlight-article))
3668       ;; If the summary buffer is empty, but there are some low-scored
3669       ;; articles or some excluded dormants, we include these in the
3670       ;; buffer.
3671       (when (and (zerop (buffer-size))
3672                  (not no-display))
3673         (cond (gnus-newsgroup-dormant
3674                (gnus-summary-limit-include-dormant))
3675               ((and gnus-newsgroup-scored show-all)
3676                (gnus-summary-limit-include-expunged t))))
3677       ;; Function `gnus-apply-kill-file' must be called in this hook.
3678       (gnus-run-hooks 'gnus-apply-kill-hook)
3679       (if (and (zerop (buffer-size))
3680                (not no-display))
3681           (progn
3682             ;; This newsgroup is empty.
3683             (gnus-summary-catchup-and-exit nil t)
3684             (gnus-message 6 "No unread news")
3685             (when kill-buffer
3686               (gnus-kill-or-deaden-summary kill-buffer))
3687             ;; Return nil from this function.
3688             nil)
3689         ;; Hide conversation thread subtrees.  We cannot do this in
3690         ;; gnus-summary-prepare-hook since kill processing may not
3691         ;; work with hidden articles.
3692         (gnus-summary-maybe-hide-threads)
3693         (when kill-buffer
3694           (gnus-kill-or-deaden-summary kill-buffer))
3695         (gnus-summary-auto-select-subject)
3696         ;; Show first unread article if requested.
3697         (if (and (not no-article)
3698                  (not no-display)
3699                  gnus-newsgroup-unreads
3700                  gnus-auto-select-first)
3701             (progn
3702               (gnus-configure-windows 'summary)
3703               (let ((art (gnus-summary-article-number)))
3704                 (unless (and (not gnus-plugged)
3705                              (or (memq art gnus-newsgroup-undownloaded)
3706                                  (memq art gnus-newsgroup-downloadable)))
3707                   (gnus-summary-goto-article art))))
3708           ;; Don't select any articles.
3709           (gnus-summary-position-point)
3710           (gnus-configure-windows 'summary 'force)
3711           (gnus-set-mode-line 'summary))
3712         (when (and gnus-auto-center-group
3713                    (get-buffer-window gnus-group-buffer t))
3714           ;; Gotta use windows, because recenter does weird stuff if
3715           ;; the current buffer ain't the displayed window.
3716           (let ((owin (selected-window)))
3717             (select-window (get-buffer-window gnus-group-buffer t))
3718             (when (gnus-group-goto-group group)
3719               (recenter))
3720             (select-window owin)))
3721         ;; Mark this buffer as "prepared".
3722         (setq gnus-newsgroup-prepared t)
3723         (gnus-run-hooks 'gnus-summary-prepared-hook)
3724         (unless (gnus-ephemeral-group-p group)
3725           (gnus-group-update-group group))
3726         t)))))
3727
3728 (defun gnus-summary-auto-select-subject ()
3729   "Select the subject line on initial group entry."
3730   (goto-char (point-min))
3731   (cond
3732    ((eq gnus-auto-select-subject 'best)
3733     (gnus-summary-best-unread-subject))
3734    ((eq gnus-auto-select-subject 'unread)
3735     (gnus-summary-first-unread-subject))
3736    ((eq gnus-auto-select-subject 'unseen)
3737     (gnus-summary-first-unseen-subject))
3738    ((eq gnus-auto-select-subject 'unseen-or-unread)
3739     (gnus-summary-first-unseen-or-unread-subject))
3740    ((eq gnus-auto-select-subject 'first)
3741     ;; Do nothing.
3742     )
3743    ((functionp gnus-auto-select-subject)
3744     (funcall gnus-auto-select-subject))))
3745
3746 (defun gnus-summary-prepare ()
3747   "Generate the summary buffer."
3748   (interactive)
3749   (let ((buffer-read-only nil))
3750     (erase-buffer)
3751     (setq gnus-newsgroup-data nil
3752           gnus-newsgroup-data-reverse nil)
3753     (gnus-run-hooks 'gnus-summary-generate-hook)
3754     ;; Generate the buffer, either with threads or without.
3755     (when gnus-newsgroup-headers
3756       (gnus-summary-prepare-threads
3757        (if gnus-show-threads
3758            (gnus-sort-gathered-threads
3759             (funcall gnus-summary-thread-gathering-function
3760                      (gnus-sort-threads
3761                       (gnus-cut-threads (gnus-make-threads)))))
3762          ;; Unthreaded display.
3763          (gnus-sort-articles gnus-newsgroup-headers))))
3764     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
3765     ;; Call hooks for modifying summary buffer.
3766     (goto-char (point-min))
3767     (gnus-run-hooks 'gnus-summary-prepare-hook)))
3768
3769 (defsubst gnus-general-simplify-subject (subject)
3770   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
3771   (setq subject
3772         (cond
3773          ;; Truncate the subject.
3774          (gnus-simplify-subject-functions
3775           (gnus-map-function gnus-simplify-subject-functions subject))
3776          ((numberp gnus-summary-gather-subject-limit)
3777           (setq subject (gnus-simplify-subject-re subject))
3778           (if (> (length subject) gnus-summary-gather-subject-limit)
3779               (substring subject 0 gnus-summary-gather-subject-limit)
3780             subject))
3781          ;; Fuzzily simplify it.
3782          ((eq 'fuzzy gnus-summary-gather-subject-limit)
3783           (gnus-simplify-subject-fuzzy subject))
3784          ;; Just remove the leading "Re:".
3785          (t
3786           (gnus-simplify-subject-re subject))))
3787
3788   (if (and gnus-summary-gather-exclude-subject
3789            (string-match gnus-summary-gather-exclude-subject subject))
3790       nil                               ; This article shouldn't be gathered
3791     subject))
3792
3793 (defun gnus-summary-simplify-subject-query ()
3794   "Query where the respool algorithm would put this article."
3795   (interactive)
3796   (gnus-summary-select-article)
3797   (message "%s"
3798            (gnus-general-simplify-subject (gnus-summary-article-subject))))
3799
3800 (defun gnus-gather-threads-by-subject (threads)
3801   "Gather threads by looking at Subject headers."
3802   (if (not gnus-summary-make-false-root)
3803       threads
3804     (let ((hashtb (gnus-make-hashtable 1024))
3805           (prev threads)
3806           (result threads)
3807           subject hthread whole-subject)
3808       (while threads
3809         (setq subject (gnus-general-simplify-subject
3810                        (setq whole-subject (mail-header-subject
3811                                             (caar threads)))))
3812         (when subject
3813           (if (setq hthread (gnus-gethash subject hashtb))
3814               (progn
3815                 ;; We enter a dummy root into the thread, if we
3816                 ;; haven't done that already.
3817                 (unless (stringp (caar hthread))
3818                   (setcar hthread (list whole-subject (car hthread))))
3819                 ;; We add this new gathered thread to this gathered
3820                 ;; thread.
3821                 (setcdr (car hthread)
3822                         (nconc (cdar hthread) (list (car threads))))
3823                 ;; Remove it from the list of threads.
3824                 (setcdr prev (cdr threads))
3825                 (setq threads prev))
3826             ;; Enter this thread into the hash table.
3827             (gnus-sethash subject
3828                           (if gnus-summary-make-false-root-always
3829                               (progn
3830                                 ;; If you want a dummy root above all
3831                                 ;; threads...
3832                                 (setcar threads (list whole-subject
3833                                                       (car threads)))
3834                                 threads)
3835                             threads)
3836                           hashtb)))
3837         (setq prev threads)
3838         (setq threads (cdr threads)))
3839       result)))
3840
3841 (defun gnus-gather-threads-by-references (threads)
3842   "Gather threads by looking at References headers."
3843   (let ((idhashtb (gnus-make-hashtable 1024))
3844         (thhashtb (gnus-make-hashtable 1024))
3845         (prev threads)
3846         (result threads)
3847         ids references id gthread gid entered ref)
3848     (while threads
3849       (when (setq references (mail-header-references (caar threads)))
3850         (setq id (mail-header-id (caar threads))
3851               ids (inline (gnus-split-references references))
3852               entered nil)
3853         (while (setq ref (pop ids))
3854           (setq ids (delete ref ids))
3855           (if (not (setq gid (gnus-gethash ref idhashtb)))
3856               (progn
3857                 (gnus-sethash ref id idhashtb)
3858                 (gnus-sethash id threads thhashtb))
3859             (setq gthread (gnus-gethash gid thhashtb))
3860             (unless entered
3861               ;; We enter a dummy root into the thread, if we
3862               ;; haven't done that already.
3863               (unless (stringp (caar gthread))
3864                 (setcar gthread (list (mail-header-subject (caar gthread))
3865                                       (car gthread))))
3866               ;; We add this new gathered thread to this gathered
3867               ;; thread.
3868               (setcdr (car gthread)
3869                       (nconc (cdar gthread) (list (car threads)))))
3870             ;; Add it into the thread hash table.
3871             (gnus-sethash id gthread thhashtb)
3872             (setq entered t)
3873             ;; Remove it from the list of threads.
3874             (setcdr prev (cdr threads))
3875             (setq threads prev))))
3876       (setq prev threads)
3877       (setq threads (cdr threads)))
3878     result))
3879
3880 (defun gnus-sort-gathered-threads (threads)
3881   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
3882   (let ((result threads))
3883     (while threads
3884       (when (stringp (caar threads))
3885         (setcdr (car threads)
3886                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
3887       (setq threads (cdr threads)))
3888     result))
3889
3890 (defun gnus-thread-loop-p (root thread)
3891   "Say whether ROOT is in THREAD."
3892   (let ((stack (list thread))
3893         (infloop 0)
3894         th)
3895     (while (setq thread (pop stack))
3896       (setq th (cdr thread))
3897       (while (and th
3898                   (not (eq (caar th) root)))
3899         (pop th))
3900       (if th
3901           ;; We have found a loop.
3902           (let (ref-dep)
3903             (setcdr thread (delq (car th) (cdr thread)))
3904             (if (boundp (setq ref-dep (intern "none"
3905                                               gnus-newsgroup-dependencies)))
3906                 (setcdr (symbol-value ref-dep)
3907                         (nconc (cdr (symbol-value ref-dep))
3908                                (list (car th))))
3909               (set ref-dep (list nil (car th))))
3910             (setq infloop 1
3911                   stack nil))
3912         ;; Push all the subthreads onto the stack.
3913         (push (cdr thread) stack)))
3914     infloop))
3915
3916 (defun gnus-make-threads ()
3917   "Go through the dependency hashtb and find the roots.  Return all threads."
3918   (let (threads)
3919     (while (catch 'infloop
3920              (mapatoms
3921               (lambda (refs)
3922                 ;; Deal with self-referencing References loops.
3923                 (when (and (car (symbol-value refs))
3924                            (not (zerop
3925                                  (apply
3926                                   '+
3927                                   (mapcar
3928                                    (lambda (thread)
3929                                      (gnus-thread-loop-p
3930                                       (car (symbol-value refs)) thread))
3931                                    (cdr (symbol-value refs)))))))
3932                   (setq threads nil)
3933                   (throw 'infloop t))
3934                 (unless (car (symbol-value refs))
3935                   ;; These threads do not refer back to any other articles,
3936                   ;; so they're roots.
3937                   (setq threads (append (cdr (symbol-value refs)) threads))))
3938               gnus-newsgroup-dependencies)))
3939     threads))
3940
3941 ;; Build the thread tree.
3942 (defsubst gnus-dependencies-add-header (header dependencies force-new)
3943   "Enter HEADER into the DEPENDENCIES table if it is not already there.
3944
3945 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
3946 if it was already present.
3947
3948 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
3949 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
3950 Message-IDs will be renamed to a unique Message-ID before being
3951 entered.
3952
3953 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
3954   (let* ((id (mail-header-id header))
3955          (id-dep (and id (intern id dependencies)))
3956          parent-id ref ref-dep ref-header replaced)
3957     ;; Enter this `header' in the `dependencies' table.
3958     (cond
3959      ((not id-dep)
3960       (setq header nil))
3961      ;; The first two cases do the normal part: enter a new `header'
3962      ;; in the `dependencies' table.
3963      ((not (boundp id-dep))
3964       (set id-dep (list header)))
3965      ((null (car (symbol-value id-dep)))
3966       (setcar (symbol-value id-dep) header))
3967
3968      ;; From here the `header' was already present in the
3969      ;; `dependencies' table.
3970      (force-new
3971       ;; Overrides an existing entry;
3972       ;; just set the header part of the entry.
3973       (setcar (symbol-value id-dep) header)
3974       (setq replaced t))
3975
3976      ;; Renames the existing `header' to a unique Message-ID.
3977      ((not gnus-summary-ignore-duplicates)
3978       ;; An article with this Message-ID has already been seen.
3979       ;; We rename the Message-ID.
3980       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
3981            (list header))
3982       (mail-header-set-id header id))
3983
3984      ;; The last case ignores an existing entry, except it adds any
3985      ;; additional Xrefs (in case the two articles came from different
3986      ;; servers.
3987      ;; Also sets `header' to `nil' meaning that the `dependencies'
3988      ;; table was *not* modified.
3989      (t
3990       (mail-header-set-xref
3991        (car (symbol-value id-dep))
3992        (concat (or (mail-header-xref (car (symbol-value id-dep)))
3993                    "")
3994                (or (mail-header-xref header) "")))
3995       (setq header nil)))
3996
3997     (when (and header (not replaced))
3998       ;; First check that we are not creating a References loop.
3999       (setq parent-id (gnus-parent-id (mail-header-references header)))
4000       (setq ref parent-id)
4001       (while (and ref
4002                   (setq ref-dep (intern-soft ref dependencies))
4003                   (boundp ref-dep)
4004                   (setq ref-header (car (symbol-value ref-dep))))
4005         (if (string= id ref)
4006             ;; Yuk!  This is a reference loop.  Make the article be a
4007             ;; root article.
4008             (progn
4009               (mail-header-set-references (car (symbol-value id-dep)) "none")
4010               (setq ref nil)
4011               (setq parent-id nil))
4012           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4013       (setq ref-dep (intern (or parent-id "none") dependencies))
4014       (if (boundp ref-dep)
4015           (setcdr (symbol-value ref-dep)
4016                   (nconc (cdr (symbol-value ref-dep))
4017                          (list (symbol-value id-dep))))
4018         (set ref-dep (list nil (symbol-value id-dep)))))
4019     header))
4020
4021 (defun gnus-extract-message-id-from-in-reply-to (string)
4022   (if (string-match "<[^>]+>" string)
4023       (substring string (match-beginning 0) (match-end 0))
4024     nil))
4025
4026 (defun gnus-build-sparse-threads ()
4027   (let ((headers gnus-newsgroup-headers)
4028         (mail-parse-charset gnus-newsgroup-charset)
4029         (gnus-summary-ignore-duplicates t)
4030         header references generation relations
4031         subject child end new-child date)
4032     ;; First we create an alist of generations/relations, where
4033     ;; generations is how much we trust the relation, and the relation
4034     ;; is parent/child.
4035     (gnus-message 7 "Making sparse threads...")
4036     (save-excursion
4037       (nnheader-set-temp-buffer " *gnus sparse threads*")
4038       (while (setq header (pop headers))
4039         (when (and (setq references (mail-header-references header))
4040                    (not (string= references "")))
4041           (insert references)
4042           (setq child (mail-header-id header)
4043                 subject (mail-header-subject header)
4044                 date (mail-header-date header)
4045                 generation 0)
4046           (while (search-backward ">" nil t)
4047             (setq end (1+ (point)))
4048             (when (search-backward "<" nil t)
4049               (setq new-child (buffer-substring (point) end))
4050               (push (list (incf generation)
4051                           child (setq child new-child)
4052                           subject date)
4053                     relations)))
4054           (when child
4055             (push (list (1+ generation) child nil subject) relations))
4056           (erase-buffer)))
4057       (kill-buffer (current-buffer)))
4058     ;; Sort over trustworthiness.
4059     (mapcar
4060      (lambda (relation)
4061        (when (gnus-dependencies-add-header
4062               (make-full-mail-header-from-decoded-header
4063                gnus-reffed-article-number
4064                (nth 3 relation) "" (or (nth 4 relation) "")
4065                (nth 1 relation)
4066                (or (nth 2 relation) "") 0 0 "")
4067               gnus-newsgroup-dependencies nil)
4068          (push gnus-reffed-article-number gnus-newsgroup-limit)
4069          (push gnus-reffed-article-number gnus-newsgroup-sparse)
4070          (push (cons gnus-reffed-article-number gnus-sparse-mark)
4071                gnus-newsgroup-reads)
4072          (decf gnus-reffed-article-number)))
4073      (sort relations 'car-less-than-car))
4074     (gnus-message 7 "Making sparse threads...done")))
4075
4076 (defun gnus-build-old-threads ()
4077   ;; Look at all the articles that refer back to old articles, and
4078   ;; fetch the headers for the articles that aren't there.  This will
4079   ;; build complete threads - if the roots haven't been expired by the
4080   ;; server, that is.
4081   (let ((mail-parse-charset gnus-newsgroup-charset)
4082         id heads)
4083     (mapatoms
4084      (lambda (refs)
4085        (when (not (car (symbol-value refs)))
4086          (setq heads (cdr (symbol-value refs)))
4087          (while heads
4088            (if (memq (mail-header-number (caar heads))
4089                      gnus-newsgroup-dormant)
4090                (setq heads (cdr heads))
4091              (setq id (symbol-name refs))
4092              (while (and (setq id (gnus-build-get-header id))
4093                          (not (car (gnus-id-to-thread id)))))
4094              (setq heads nil)))))
4095      gnus-newsgroup-dependencies)))
4096
4097 (defsubst gnus-remove-odd-characters (string)
4098   "Translate STRING into something that doesn't contain weird characters."
4099   (mm-subst-char-in-string
4100    ?\r ?\-
4101    (mm-subst-char-in-string ?\n ?\- string t) t))
4102
4103 ;; This function has to be called with point after the article number
4104 ;; on the beginning of the line.
4105 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4106   (let ((eol (point-at-eol))
4107         (buffer (current-buffer))
4108         header references in-reply-to)
4109
4110     ;; overview: [num subject from date id refs chars lines misc]
4111     (unwind-protect
4112         (progn
4113           (narrow-to-region (point) eol)
4114           (unless (eobp)
4115             (forward-char))
4116
4117           (setq header
4118                 (make-full-mail-header
4119                  number                         ; number
4120                  (nnheader-nov-field)           ; subject
4121                  (nnheader-nov-field)           ; from
4122                  (nnheader-nov-field)           ; date
4123                  (nnheader-nov-read-message-id number)  ; id
4124                  (setq references (nnheader-nov-field)) ; refs
4125                  (nnheader-nov-read-integer)    ; chars
4126                  (nnheader-nov-read-integer)    ; lines
4127                  (unless (eobp)
4128                    (if (looking-at "Xref: ")
4129                        (goto-char (match-end 0)))
4130                    (nnheader-nov-field))        ; Xref
4131                  (nnheader-nov-parse-extra))))  ; extra
4132
4133       (widen))
4134
4135     (when (and (string= references "")
4136                (setq in-reply-to (mail-header-extra header))
4137                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4138       (mail-header-set-references
4139        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4140
4141     (when gnus-alter-header-function
4142       (funcall gnus-alter-header-function header))
4143     (gnus-dependencies-add-header header dependencies force-new)))
4144
4145 (defun gnus-build-get-header (id)
4146   "Look through the buffer of NOV lines and find the header to ID.
4147 Enter this line into the dependencies hash table, and return
4148 the id of the parent article (if any)."
4149   (let ((deps gnus-newsgroup-dependencies)
4150         found header)
4151     (prog1
4152         (save-excursion
4153           (set-buffer nntp-server-buffer)
4154           (let ((case-fold-search nil))
4155             (goto-char (point-min))
4156             (while (and (not found)
4157                         (search-forward id nil t))
4158               (beginning-of-line)
4159               (setq found (looking-at
4160                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4161                                    (regexp-quote id))))
4162               (or found (beginning-of-line 2)))
4163             (when found
4164               (beginning-of-line)
4165               (and
4166                (setq header (gnus-nov-parse-line
4167                              (read (current-buffer)) deps))
4168                (gnus-parent-id (mail-header-references header))))))
4169       (when header
4170         (let ((number (mail-header-number header)))
4171           (push number gnus-newsgroup-limit)
4172           (push header gnus-newsgroup-headers)
4173           (if (memq number gnus-newsgroup-unselected)
4174               (progn
4175                 (setq gnus-newsgroup-unreads
4176                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4177                                                number))
4178                 (setq gnus-newsgroup-unselected
4179                       (delq number gnus-newsgroup-unselected)))
4180             (push number gnus-newsgroup-ancient)))))))
4181
4182 (defun gnus-build-all-threads ()
4183   "Read all the headers."
4184   (let ((gnus-summary-ignore-duplicates t)
4185         (mail-parse-charset gnus-newsgroup-charset)
4186         (dependencies gnus-newsgroup-dependencies)
4187         header article)
4188     (save-excursion
4189       (set-buffer nntp-server-buffer)
4190       (let ((case-fold-search nil))
4191         (goto-char (point-min))
4192         (while (not (eobp))
4193           (ignore-errors
4194             (setq article (read (current-buffer))
4195                   header (gnus-nov-parse-line article dependencies)))
4196           (when header
4197             (with-current-buffer gnus-summary-buffer
4198               (push header gnus-newsgroup-headers)
4199               (if (memq (setq article (mail-header-number header))
4200                         gnus-newsgroup-unselected)
4201                   (progn
4202                     (setq gnus-newsgroup-unreads
4203                           (gnus-add-to-sorted-list
4204                            gnus-newsgroup-unreads article))
4205                     (setq gnus-newsgroup-unselected
4206                           (delq article gnus-newsgroup-unselected)))
4207                 (push article gnus-newsgroup-ancient)))
4208             (forward-line 1)))))))
4209
4210 (defun gnus-summary-update-article-line (article header)
4211   "Update the line for ARTICLE using HEADER."
4212   (let* ((id (mail-header-id header))
4213          (thread (gnus-id-to-thread id)))
4214     (unless thread
4215       (error "Article in no thread"))
4216     ;; Update the thread.
4217     (setcar thread header)
4218     (gnus-summary-goto-subject article)
4219     (let* ((datal (gnus-data-find-list article))
4220            (data (car datal))
4221            (buffer-read-only nil)
4222            (level (gnus-summary-thread-level)))
4223       (gnus-delete-line)
4224       (let ((inserted (- (point)
4225                          (progn
4226                            (gnus-summary-insert-line
4227                             header level nil
4228                             (memq article gnus-newsgroup-undownloaded)
4229                             (gnus-article-mark article)
4230                             (memq article gnus-newsgroup-replied)
4231                             (memq article gnus-newsgroup-expirable)
4232                             ;; Only insert the Subject string when it's different
4233                             ;; from the previous Subject string.
4234                             (if (and
4235                                  gnus-show-threads
4236                                  (gnus-subject-equal
4237                                   (condition-case ()
4238                                       (mail-header-subject
4239                                        (gnus-data-header
4240                                         (cadr
4241                                          (gnus-data-find-list
4242                                           article
4243                                           (gnus-data-list t)))))
4244                                     ;; Error on the side of excessive subjects.
4245                                     (error ""))
4246                                   (mail-header-subject header)))
4247                                 ""
4248                               (mail-header-subject header))
4249                             nil (cdr (assq article gnus-newsgroup-scored))
4250                             (memq article gnus-newsgroup-processable))
4251                            (point)))))
4252         (when (cdr datal)
4253           (gnus-data-update-list
4254            (cdr datal)
4255            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4256
4257 (defun gnus-summary-update-article (article &optional iheader)
4258   "Update ARTICLE in the summary buffer."
4259   (set-buffer gnus-summary-buffer)
4260   (let* ((header (gnus-summary-article-header article))
4261          (id (mail-header-id header))
4262          (data (gnus-data-find article))
4263          (thread (gnus-id-to-thread id))
4264          (references (mail-header-references header))
4265          (parent
4266           (gnus-id-to-thread
4267            (or (gnus-parent-id
4268                 (when (and references
4269                            (not (equal "" references)))
4270                   references))
4271                "none")))
4272          (buffer-read-only nil)
4273          (old (car thread)))
4274     (when thread
4275       (unless iheader
4276         (setcar thread nil)
4277         (when parent
4278           (delq thread parent)))
4279       (if (gnus-summary-insert-subject id header)
4280           ;; Set the (possibly) new article number in the data structure.
4281           (gnus-data-set-number data (gnus-id-to-article id))
4282         (setcar thread old)
4283         nil))))
4284
4285 (defun gnus-rebuild-thread (id &optional line)
4286   "Rebuild the thread containing ID.
4287 If LINE, insert the rebuilt thread starting on line LINE."
4288   (let ((buffer-read-only nil)
4289         old-pos current thread data)
4290     (if (not gnus-show-threads)
4291         (setq thread (list (car (gnus-id-to-thread id))))
4292       ;; Get the thread this article is part of.
4293       (setq thread (gnus-remove-thread id)))
4294     (setq old-pos (point-at-bol))
4295     (setq current (save-excursion
4296                     (and (re-search-backward "[\r\n]" nil t)
4297                          (gnus-summary-article-number))))
4298     ;; If this is a gathered thread, we have to go some re-gathering.
4299     (when (stringp (car thread))
4300       (let ((subject (car thread))
4301             roots thr)
4302         (setq thread (cdr thread))
4303         (while thread
4304           (unless (memq (setq thr (gnus-id-to-thread
4305                                    (gnus-root-id
4306                                     (mail-header-id (caar thread)))))
4307                         roots)
4308             (push thr roots))
4309           (setq thread (cdr thread)))
4310         ;; We now have all (unique) roots.
4311         (if (= (length roots) 1)
4312             ;; All the loose roots are now one solid root.
4313             (setq thread (car roots))
4314           (setq thread (cons subject (gnus-sort-threads roots))))))
4315     (let (threads)
4316       ;; We then insert this thread into the summary buffer.
4317       (when line
4318         (goto-char (point-min))
4319         (forward-line (1- line)))
4320       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4321         (if gnus-show-threads
4322             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4323           (gnus-summary-prepare-unthreaded thread))
4324         (setq data (nreverse gnus-newsgroup-data))
4325         (setq threads gnus-newsgroup-threads))
4326       ;; We splice the new data into the data structure.
4327       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4328       ;;!!! then we want to insert at the beginning of the buffer.
4329       ;;!!! That happens to be true with Gnus now, but that may
4330       ;;!!! change in the future.  Perhaps.
4331       (gnus-data-enter-list
4332        (if line nil current) data (- (point) old-pos))
4333       (setq gnus-newsgroup-threads
4334             (nconc threads gnus-newsgroup-threads))
4335       (gnus-data-compute-positions))))
4336
4337 (defun gnus-number-to-header (number)
4338   "Return the header for article NUMBER."
4339   (let ((headers gnus-newsgroup-headers))
4340     (while (and headers
4341                 (not (= number (mail-header-number (car headers)))))
4342       (pop headers))
4343     (when headers
4344       (car headers))))
4345
4346 (defun gnus-parent-headers (in-headers &optional generation)
4347   "Return the headers of the GENERATIONeth parent of HEADERS."
4348   (unless generation
4349     (setq generation 1))
4350   (let ((parent t)
4351         (headers in-headers)
4352         references)
4353     (while (and parent
4354                 (not (zerop generation))
4355                 (setq references (mail-header-references headers)))
4356       (setq headers (if (and references
4357                              (setq parent (gnus-parent-id references)))
4358                         (car (gnus-id-to-thread parent))
4359                       nil))
4360       (decf generation))
4361     (and (not (eq headers in-headers))
4362          headers)))
4363
4364 (defun gnus-id-to-thread (id)
4365   "Return the (sub-)thread where ID appears."
4366   (gnus-gethash id gnus-newsgroup-dependencies))
4367
4368 (defun gnus-id-to-article (id)
4369   "Return the article number of ID."
4370   (let ((thread (gnus-id-to-thread id)))
4371     (when (and thread
4372                (car thread))
4373       (mail-header-number (car thread)))))
4374
4375 (defun gnus-id-to-header (id)
4376   "Return the article headers of ID."
4377   (car (gnus-id-to-thread id)))
4378
4379 (defun gnus-article-displayed-root-p (article)
4380   "Say whether ARTICLE is a root(ish) article."
4381   (let ((level (gnus-summary-thread-level article))
4382         (refs (mail-header-references  (gnus-summary-article-header article)))
4383         particle)
4384     (cond
4385      ((null level) nil)
4386      ((zerop level) t)
4387      ((null refs) t)
4388      ((null (gnus-parent-id refs)) t)
4389      ((and (= 1 level)
4390            (null (setq particle (gnus-id-to-article
4391                                  (gnus-parent-id refs))))
4392            (null (gnus-summary-thread-level particle)))))))
4393
4394 (defun gnus-root-id (id)
4395   "Return the id of the root of the thread where ID appears."
4396   (let (last-id prev)
4397     (while (and id (setq prev (car (gnus-id-to-thread id))))
4398       (setq last-id id
4399             id (gnus-parent-id (mail-header-references prev))))
4400     last-id))
4401
4402 (defun gnus-articles-in-thread (thread)
4403   "Return the list of articles in THREAD."
4404   (cons (mail-header-number (car thread))
4405         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4406
4407 (defun gnus-remove-thread (id &optional dont-remove)
4408   "Remove the thread that has ID in it."
4409   (let (headers thread last-id)
4410     ;; First go up in this thread until we find the root.
4411     (setq last-id (gnus-root-id id)
4412           headers (message-flatten-list (gnus-id-to-thread last-id)))
4413     ;; We have now found the real root of this thread.  It might have
4414     ;; been gathered into some loose thread, so we have to search
4415     ;; through the threads to find the thread we wanted.
4416     (let ((threads gnus-newsgroup-threads)
4417           sub)
4418       (while threads
4419         (setq sub (car threads))
4420         (if (stringp (car sub))
4421             ;; This is a gathered thread, so we look at the roots
4422             ;; below it to find whether this article is in this
4423             ;; gathered root.
4424             (progn
4425               (setq sub (cdr sub))
4426               (while sub
4427                 (when (member (caar sub) headers)
4428                   (setq thread (car threads)
4429                         threads nil
4430                         sub nil))
4431                 (setq sub (cdr sub))))
4432           ;; It's an ordinary thread, so we check it.
4433           (when (eq (car sub) (car headers))
4434             (setq thread sub
4435                   threads nil)))
4436         (setq threads (cdr threads)))
4437       ;; If this article is in no thread, then it's a root.
4438       (if thread
4439           (unless dont-remove
4440             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4441         (setq thread (gnus-id-to-thread last-id)))
4442       (when thread
4443         (prog1
4444             thread                      ; We return this thread.
4445           (unless dont-remove
4446             (if (stringp (car thread))
4447                 (progn
4448                   ;; If we use dummy roots, then we have to remove the
4449                   ;; dummy root as well.
4450                   (when (eq gnus-summary-make-false-root 'dummy)
4451                     ;; We go to the dummy root by going to
4452                     ;; the first sub-"thread", and then one line up.
4453                     (gnus-summary-goto-article
4454                      (mail-header-number (caadr thread)))
4455                     (forward-line -1)
4456                     (gnus-delete-line)
4457                     (gnus-data-compute-positions))
4458                   (setq thread (cdr thread))
4459                   (while thread
4460                     (gnus-remove-thread-1 (car thread))
4461                     (setq thread (cdr thread))))
4462               (gnus-remove-thread-1 thread))))))))
4463
4464 (defun gnus-remove-thread-1 (thread)
4465   "Remove the thread THREAD recursively."
4466   (let ((number (mail-header-number (pop thread)))
4467         d)
4468     (setq thread (reverse thread))
4469     (while thread
4470       (gnus-remove-thread-1 (pop thread)))
4471     (when (setq d (gnus-data-find number))
4472       (goto-char (gnus-data-pos d))
4473       (gnus-summary-show-thread)
4474       (gnus-data-remove
4475        number
4476        (- (point-at-bol)
4477           (prog1
4478               (1+ (point-at-eol))
4479             (gnus-delete-line)))))))
4480
4481 (defun gnus-sort-threads-1 (threads func)
4482   (sort (mapcar (lambda (thread)
4483                   (cons (car thread)
4484                         (and (cdr thread)
4485                              (gnus-sort-threads-1 (cdr thread) func))))
4486                 threads) func))
4487
4488 (defun gnus-sort-threads (threads)
4489   "Sort THREADS."
4490   (if (not gnus-thread-sort-functions)
4491       threads
4492     (gnus-message 8 "Sorting threads...")
4493     (let ((max-lisp-eval-depth 5000))
4494       (prog1 (gnus-sort-threads-1
4495          threads
4496          (gnus-make-sort-function gnus-thread-sort-functions))
4497         (gnus-message 8 "Sorting threads...done")))))
4498
4499 (defun gnus-sort-articles (articles)
4500   "Sort ARTICLES."
4501   (when gnus-article-sort-functions
4502     (gnus-message 7 "Sorting articles...")
4503     (prog1
4504         (setq gnus-newsgroup-headers
4505               (sort articles (gnus-make-sort-function
4506                               gnus-article-sort-functions)))
4507       (gnus-message 7 "Sorting articles...done"))))
4508
4509 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4510 (defmacro gnus-thread-header (thread)
4511   "Return header of first article in THREAD.
4512 Note that THREAD must never, ever be anything else than a variable -
4513 using some other form will lead to serious barfage."
4514   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4515   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4516   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4517         (vector thread) 2))
4518
4519 (defsubst gnus-article-sort-by-number (h1 h2)
4520   "Sort articles by article number."
4521   (< (mail-header-number h1)
4522      (mail-header-number h2)))
4523
4524 (defun gnus-thread-sort-by-number (h1 h2)
4525   "Sort threads by root article number."
4526   (gnus-article-sort-by-number
4527    (gnus-thread-header h1) (gnus-thread-header h2)))
4528
4529 (defsubst gnus-article-sort-by-random (h1 h2)
4530   "Sort articles by article number."
4531   (zerop (random 2)))
4532
4533 (defun gnus-thread-sort-by-random (h1 h2)
4534   "Sort threads by root article number."
4535   (gnus-article-sort-by-random
4536    (gnus-thread-header h1) (gnus-thread-header h2)))
4537
4538 (defsubst gnus-article-sort-by-lines (h1 h2)
4539   "Sort articles by article Lines header."
4540   (< (mail-header-lines h1)
4541      (mail-header-lines h2)))
4542
4543 (defun gnus-thread-sort-by-lines (h1 h2)
4544   "Sort threads by root article Lines header."
4545   (gnus-article-sort-by-lines
4546    (gnus-thread-header h1) (gnus-thread-header h2)))
4547
4548 (defsubst gnus-article-sort-by-chars (h1 h2)
4549   "Sort articles by octet length."
4550   (< (mail-header-chars h1)
4551      (mail-header-chars h2)))
4552
4553 (defun gnus-thread-sort-by-chars (h1 h2)
4554   "Sort threads by root article octet length."
4555   (gnus-article-sort-by-chars
4556    (gnus-thread-header h1) (gnus-thread-header h2)))
4557
4558 (defsubst gnus-article-sort-by-author (h1 h2)
4559   "Sort articles by root author."
4560   (string-lessp
4561    (let ((addr (car (mime-entity-read-field h1 'From))))
4562      (or (std11-full-name-string addr)
4563          (std11-address-string addr)
4564          ""))
4565    (let ((addr (car (mime-entity-read-field h2 'From))))
4566      (or (std11-full-name-string addr)
4567          (std11-address-string addr)
4568          ""))
4569    ))
4570
4571 (defun gnus-thread-sort-by-author (h1 h2)
4572   "Sort threads by root author."
4573   (gnus-article-sort-by-author
4574    (gnus-thread-header h1)  (gnus-thread-header h2)))
4575
4576 (defsubst gnus-article-sort-by-recipient (h1 h2)
4577   "Sort articles by recipient."
4578   (string-lessp
4579    (let ((extract (funcall
4580                    gnus-extract-address-components
4581                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4582      (or (car extract) (cadr extract)))
4583    (let ((extract (funcall
4584                    gnus-extract-address-components
4585                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4586      (or (car extract) (cadr extract)))))
4587
4588 (defsubst gnus-article-sort-by-subject (h1 h2)
4589   "Sort articles by root subject."
4590   (string-lessp
4591    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4592    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4593
4594 (defun gnus-thread-sort-by-subject (h1 h2)
4595   "Sort threads by root subject."
4596   (gnus-article-sort-by-subject
4597    (gnus-thread-header h1) (gnus-thread-header h2)))
4598
4599 (defsubst gnus-article-sort-by-date (h1 h2)
4600   "Sort articles by root article date."
4601   (time-less-p
4602    (gnus-date-get-time (mail-header-date h1))
4603    (gnus-date-get-time (mail-header-date h2))))
4604
4605 (defun gnus-thread-sort-by-date (h1 h2)
4606   "Sort threads by root article date."
4607   (gnus-article-sort-by-date
4608    (gnus-thread-header h1) (gnus-thread-header h2)))
4609
4610 (defsubst gnus-article-sort-by-score (h1 h2)
4611   "Sort articles by root article score.
4612 Unscored articles will be counted as having a score of zero."
4613   (> (or (cdr (assq (mail-header-number h1)
4614                     gnus-newsgroup-scored))
4615          gnus-summary-default-score 0)
4616      (or (cdr (assq (mail-header-number h2)
4617                     gnus-newsgroup-scored))
4618          gnus-summary-default-score 0)))
4619
4620 (defun gnus-thread-sort-by-score (h1 h2)
4621   "Sort threads by root article score."
4622   (gnus-article-sort-by-score
4623    (gnus-thread-header h1) (gnus-thread-header h2)))
4624
4625 (defun gnus-thread-sort-by-total-score (h1 h2)
4626   "Sort threads by the sum of all scores in the thread.
4627 Unscored articles will be counted as having a score of zero."
4628   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4629
4630 (defun gnus-thread-total-score (thread)
4631   ;; This function find the total score of THREAD.
4632   (cond
4633    ((null thread)
4634     0)
4635    ((consp thread)
4636     (if (stringp (car thread))
4637         (apply gnus-thread-score-function 0
4638                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4639       (gnus-thread-total-score-1 thread)))
4640    (t
4641     (gnus-thread-total-score-1 (list thread)))))
4642
4643 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4644   "Sort threads such that the thread with the most recently arrived article comes first."
4645   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4646
4647 (defun gnus-thread-highest-number (thread)
4648   "Return the highest article number in THREAD."
4649   (apply 'max (mapcar (lambda (header)
4650                         (mail-header-number header))
4651                       (message-flatten-list thread))))
4652
4653 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4654   "Sort threads such that the thread with the most recently dated article comes first."
4655   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4656
4657 (defun gnus-thread-latest-date (thread)
4658   "Return the highest article date in THREAD."
4659   (let ((previous-time 0))
4660     (apply 'max
4661            (mapcar
4662             (lambda (header)
4663               (setq previous-time
4664                     (condition-case ()
4665                         (time-to-seconds (mail-header-parse-date
4666                                           (mail-header-date header)))
4667                       (error previous-time))))
4668             (sort
4669              (message-flatten-list thread)
4670              (lambda (h1 h2)
4671                (< (mail-header-number h1)
4672                   (mail-header-number h2))))))))
4673
4674 (defun gnus-thread-total-score-1 (root)
4675   ;; This function find the total score of the thread below ROOT.
4676   (setq root (car root))
4677   (apply gnus-thread-score-function
4678          (or (append
4679               (mapcar 'gnus-thread-total-score
4680                       (cdr (gnus-id-to-thread (mail-header-id root))))
4681               (when (> (mail-header-number root) 0)
4682                 (list (or (cdr (assq (mail-header-number root)
4683                                      gnus-newsgroup-scored))
4684                           gnus-summary-default-score 0))))
4685              (list gnus-summary-default-score)
4686              '(0))))
4687
4688 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
4689 (defvar gnus-tmp-prev-subject nil)
4690 (defvar gnus-tmp-false-parent nil)
4691 (defvar gnus-tmp-root-expunged nil)
4692 (defvar gnus-tmp-dummy-line nil)
4693
4694 (eval-when-compile (defvar gnus-tmp-header))
4695 (defun gnus-extra-header (type &optional header)
4696   "Return the extra header of TYPE."
4697   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
4698       ""))
4699
4700 (defvar gnus-tmp-thread-tree-header-string "")
4701
4702 (defcustom gnus-sum-thread-tree-root "> "
4703   "With %B spec, used for the root of a thread.
4704 If nil, use subject instead."
4705   :version "22.1"
4706   :type '(radio (const :format "%v  " nil) string)
4707   :group 'gnus-thread)
4708 (defcustom gnus-sum-thread-tree-false-root "> "
4709   "With %B spec, used for a false root of a thread.
4710 If nil, use subject instead."
4711   :version "22.1"
4712   :type '(radio (const :format "%v  " nil) string)
4713   :group 'gnus-thread)
4714 (defcustom gnus-sum-thread-tree-single-indent ""
4715   "With %B spec, used for a thread with just one message.
4716 If nil, use subject instead."
4717   :version "22.1"
4718   :type '(radio (const :format "%v  " nil) string)
4719   :group 'gnus-thread)
4720 (defcustom gnus-sum-thread-tree-vertical "| "
4721   "With %B spec, used for drawing a vertical line."
4722   :version "22.1"
4723   :type 'string
4724   :group 'gnus-thread)
4725 (defcustom gnus-sum-thread-tree-indent "  "
4726   "With %B spec, used for indenting."
4727   :version "22.1"
4728   :type 'string
4729   :group 'gnus-thread)
4730 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
4731   "With %B spec, used for a leaf with brothers."
4732   :version "22.1"
4733   :type 'string
4734   :group 'gnus-thread)
4735 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
4736   "With %B spec, used for a leaf without brothers."
4737   :version "22.1"
4738   :type 'string
4739   :group 'gnus-thread)
4740
4741 (defun gnus-summary-prepare-threads (threads)
4742   "Prepare summary buffer from THREADS and indentation LEVEL.
4743 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
4744 or a straight list of headers."
4745   (gnus-message 7 "Generating summary...")
4746
4747   (setq gnus-newsgroup-threads threads)
4748   (beginning-of-line)
4749
4750   (let ((gnus-tmp-level 0)
4751         (default-score (or gnus-summary-default-score 0))
4752         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
4753         (building-line-count gnus-summary-display-while-building)
4754         (building-count (integerp gnus-summary-display-while-building))
4755         thread number subject stack state gnus-tmp-gathered beg-match
4756         new-roots gnus-tmp-new-adopts thread-end simp-subject
4757         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
4758         gnus-tmp-replied gnus-tmp-subject-or-nil
4759         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
4760         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
4761         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
4762         tree-stack)
4763
4764     (setq gnus-tmp-prev-subject nil
4765           gnus-tmp-thread-tree-header-string "")
4766
4767     (if (vectorp (car threads))
4768         ;; If this is a straight (sic) list of headers, then a
4769         ;; threaded summary display isn't required, so we just create
4770         ;; an unthreaded one.
4771         (gnus-summary-prepare-unthreaded threads)
4772
4773       ;; Do the threaded display.
4774
4775       (if gnus-summary-display-while-building
4776           (switch-to-buffer (buffer-name)))
4777       (while (or threads stack gnus-tmp-new-adopts new-roots)
4778
4779         (if (and (= gnus-tmp-level 0)
4780                  (or (not stack)
4781                      (= (caar stack) 0))
4782                  (not gnus-tmp-false-parent)
4783                  (or gnus-tmp-new-adopts new-roots))
4784             (if gnus-tmp-new-adopts
4785                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
4786                       thread (list (car gnus-tmp-new-adopts))
4787                       gnus-tmp-header (caar thread)
4788                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
4789               (when new-roots
4790                 (setq thread (list (car new-roots))
4791                       gnus-tmp-header (caar thread)
4792                       new-roots (cdr new-roots))))
4793
4794           (if threads
4795               ;; If there are some threads, we do them before the
4796               ;; threads on the stack.
4797               (setq thread threads
4798                     gnus-tmp-header (caar thread))
4799             ;; There were no current threads, so we pop something off
4800             ;; the stack.
4801             (setq state (car stack)
4802                   gnus-tmp-level (car state)
4803                   tree-stack (cadr state)
4804                   thread (caddr state)
4805                   stack (cdr stack)
4806                   gnus-tmp-header (caar thread))))
4807
4808         (setq gnus-tmp-false-parent nil)
4809         (setq gnus-tmp-root-expunged nil)
4810         (setq thread-end nil)
4811
4812         (if (stringp gnus-tmp-header)
4813             ;; The header is a dummy root.
4814             (cond
4815              ((eq gnus-summary-make-false-root 'adopt)
4816               ;; We let the first article adopt the rest.
4817               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
4818                                                (cddar thread)))
4819               (setq gnus-tmp-gathered
4820                     (nconc (mapcar
4821                             (lambda (h) (mail-header-number (car h)))
4822                             (cddar thread))
4823                            gnus-tmp-gathered))
4824               (setq thread (cons (list (caar thread)
4825                                        (cadar thread))
4826                                  (cdr thread)))
4827               (setq gnus-tmp-level -1
4828                     gnus-tmp-false-parent t))
4829              ((eq gnus-summary-make-false-root 'empty)
4830               ;; We print adopted articles with empty subject fields.
4831               (setq gnus-tmp-gathered
4832                     (nconc (mapcar
4833                             (lambda (h) (mail-header-number (car h)))
4834                             (cddar thread))
4835                            gnus-tmp-gathered))
4836               (setq gnus-tmp-level -1))
4837              ((eq gnus-summary-make-false-root 'dummy)
4838               ;; We remember that we probably want to output a dummy
4839               ;; root.
4840               (setq gnus-tmp-dummy-line gnus-tmp-header)
4841               (setq gnus-tmp-prev-subject gnus-tmp-header))
4842              (t
4843               ;; We do not make a root for the gathered
4844               ;; sub-threads at all.
4845               (setq gnus-tmp-level -1)))
4846
4847           (setq number (mail-header-number gnus-tmp-header)
4848                 subject (mail-header-subject gnus-tmp-header)
4849                 simp-subject (gnus-simplify-subject-fully subject))
4850
4851           (cond
4852            ;; If the thread has changed subject, we might want to make
4853            ;; this subthread into a root.
4854            ((and (null gnus-thread-ignore-subject)
4855                  (not (zerop gnus-tmp-level))
4856                  gnus-tmp-prev-subject
4857                  (not (string= gnus-tmp-prev-subject simp-subject)))
4858             (setq new-roots (nconc new-roots (list (car thread)))
4859                   thread-end t
4860                   gnus-tmp-header nil))
4861            ;; If the article lies outside the current limit,
4862            ;; then we do not display it.
4863            ((not (memq number gnus-newsgroup-limit))
4864             (setq gnus-tmp-gathered
4865                   (nconc (mapcar
4866                           (lambda (h) (mail-header-number (car h)))
4867                           (cdar thread))
4868                          gnus-tmp-gathered))
4869             (setq gnus-tmp-new-adopts (if (cdar thread)
4870                                           (append gnus-tmp-new-adopts
4871                                                   (cdar thread))
4872                                         gnus-tmp-new-adopts)
4873                   thread-end t
4874                   gnus-tmp-header nil)
4875             (when (zerop gnus-tmp-level)
4876               (setq gnus-tmp-root-expunged t)))
4877            ;; Perhaps this article is to be marked as read?
4878            ((and gnus-summary-mark-below
4879                  (< (or (cdr (assq number gnus-newsgroup-scored))
4880                         default-score)
4881                     gnus-summary-mark-below)
4882                  ;; Don't touch sparse articles.
4883                  (not (gnus-summary-article-sparse-p number))
4884                  (not (gnus-summary-article-ancient-p number)))
4885             (setq gnus-newsgroup-unreads
4886                   (delq number gnus-newsgroup-unreads))
4887             (if gnus-newsgroup-auto-expire
4888                 (setq gnus-newsgroup-expirable
4889                       (gnus-add-to-sorted-list
4890                        gnus-newsgroup-expirable number))
4891               (push (cons number gnus-low-score-mark)
4892                     gnus-newsgroup-reads))))
4893
4894           (when gnus-tmp-header
4895             ;; We may have an old dummy line to output before this
4896             ;; article.
4897             (when (and gnus-tmp-dummy-line
4898                        (gnus-subject-equal
4899                         gnus-tmp-dummy-line
4900                         (mail-header-subject gnus-tmp-header)))
4901               (gnus-summary-insert-dummy-line
4902                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
4903               (setq gnus-tmp-dummy-line nil))
4904
4905             ;; Compute the mark.
4906             (setq gnus-tmp-unread (gnus-article-mark number))
4907
4908             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
4909                                   gnus-tmp-header gnus-tmp-level)
4910                   gnus-newsgroup-data)
4911
4912             ;; Actually insert the line.
4913             (setq
4914              gnus-tmp-subject-or-nil
4915              (cond
4916               ((and gnus-thread-ignore-subject
4917                     gnus-tmp-prev-subject
4918                     (not (string= gnus-tmp-prev-subject simp-subject)))
4919                subject)
4920               ((zerop gnus-tmp-level)
4921                (if (and (eq gnus-summary-make-false-root 'empty)
4922                         (memq number gnus-tmp-gathered)
4923                         gnus-tmp-prev-subject
4924                         (string= gnus-tmp-prev-subject simp-subject))
4925                    gnus-summary-same-subject
4926                  subject))
4927               (t gnus-summary-same-subject)))
4928             (if (and (eq gnus-summary-make-false-root 'adopt)
4929                      (= gnus-tmp-level 1)
4930                      (memq number gnus-tmp-gathered))
4931                 (setq gnus-tmp-opening-bracket ?\<
4932                       gnus-tmp-closing-bracket ?\>)
4933               (setq gnus-tmp-opening-bracket ?\[
4934                     gnus-tmp-closing-bracket ?\]))
4935             (setq
4936              gnus-tmp-indentation
4937              (aref gnus-thread-indent-array gnus-tmp-level)
4938              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
4939              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
4940                                 gnus-summary-default-score 0)
4941              gnus-tmp-score-char
4942              (if (or (null gnus-summary-default-score)
4943                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
4944                          gnus-summary-zcore-fuzz))
4945                  ?\ ;;;Whitespace
4946                (if (< gnus-tmp-score gnus-summary-default-score)
4947                    gnus-score-below-mark gnus-score-over-mark))
4948              gnus-tmp-replied
4949              (cond ((memq number gnus-newsgroup-processable)
4950                     gnus-process-mark)
4951                    ((memq number gnus-newsgroup-cached)
4952                     gnus-cached-mark)
4953                    ((memq number gnus-newsgroup-replied)
4954                     gnus-replied-mark)
4955                    ((memq number gnus-newsgroup-forwarded)
4956                     gnus-forwarded-mark)
4957                    ((memq number gnus-newsgroup-saved)
4958                     gnus-saved-mark)
4959                    ((memq number gnus-newsgroup-recent)
4960                     gnus-recent-mark)
4961                    ((memq number gnus-newsgroup-unseen)
4962                     gnus-unseen-mark)
4963                    (t gnus-no-mark))
4964              gnus-tmp-downloaded
4965              (cond ((memq number gnus-newsgroup-undownloaded)
4966                     gnus-undownloaded-mark)
4967                    (gnus-newsgroup-agentized
4968                     gnus-downloaded-mark)
4969                    (t
4970                     gnus-no-mark))
4971              gnus-tmp-from (mail-header-from gnus-tmp-header)
4972              gnus-tmp-name
4973              (cond
4974               ((string-match "<[^>]+> *$" gnus-tmp-from)
4975                (setq beg-match (match-beginning 0))
4976                (or (and (string-match "^\".+\"" gnus-tmp-from)
4977                         (substring gnus-tmp-from 1 (1- (match-end 0))))
4978                    (substring gnus-tmp-from 0 beg-match)))
4979               ((string-match "(.+)" gnus-tmp-from)
4980                (substring gnus-tmp-from
4981                           (1+ (match-beginning 0)) (1- (match-end 0))))
4982               (t gnus-tmp-from))
4983
4984              ;; Do the %B string
4985              gnus-tmp-thread-tree-header-string
4986              (cond
4987               ((not gnus-show-threads) "")
4988               ((zerop gnus-tmp-level)
4989                (cond ((cdar thread)
4990                       (or gnus-sum-thread-tree-root subject))
4991                      (gnus-tmp-new-adopts
4992                       (or gnus-sum-thread-tree-false-root subject))
4993                      (t
4994                       (or gnus-sum-thread-tree-single-indent subject))))
4995               (t
4996                (concat (apply 'concat
4997                               (mapcar (lambda (item)
4998                                         (if (= item 1)
4999                                             gnus-sum-thread-tree-vertical
5000                                           gnus-sum-thread-tree-indent))
5001                                       (cdr (reverse tree-stack))))
5002                        (if (nth 1 thread)
5003                            gnus-sum-thread-tree-leaf-with-other
5004                          gnus-sum-thread-tree-single-leaf)))))
5005             (when (string= gnus-tmp-name "")
5006               (setq gnus-tmp-name gnus-tmp-from))
5007             (unless (numberp gnus-tmp-lines)
5008               (setq gnus-tmp-lines -1))
5009             (if (= gnus-tmp-lines -1)
5010                 (setq gnus-tmp-lines "?")
5011               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5012               (gnus-put-text-property
5013              (point)
5014              (progn (eval gnus-summary-line-format-spec) (point))
5015                'gnus-number number)
5016             (when gnus-visual-p
5017               (forward-line -1)
5018               (gnus-run-hooks 'gnus-summary-update-hook)
5019               (forward-line 1))
5020
5021             (setq gnus-tmp-prev-subject simp-subject)))
5022
5023         (when (nth 1 thread)
5024           (push (list (max 0 gnus-tmp-level)
5025                       (copy-sequence tree-stack)
5026                       (nthcdr 1 thread))
5027                 stack))
5028         (push (if (nth 1 thread) 1 0) tree-stack)
5029         (incf gnus-tmp-level)
5030         (setq threads (if thread-end nil (cdar thread)))
5031         (if gnus-summary-display-while-building
5032             (if building-count
5033                 (progn
5034                   ;; use a set frequency
5035                   (setq building-line-count (1- building-line-count))
5036                   (when (= building-line-count 0)
5037                     (sit-for 0)
5038                     (setq building-line-count
5039                           gnus-summary-display-while-building)))
5040               ;; always
5041               (sit-for 0)))
5042         (unless threads
5043           (setq gnus-tmp-level 0)))))
5044   (gnus-message 7 "Generating summary...done"))
5045
5046 (defun gnus-summary-prepare-unthreaded (headers)
5047   "Generate an unthreaded summary buffer based on HEADERS."
5048   (let (header number mark)
5049
5050     (beginning-of-line)
5051
5052     (while headers
5053       ;; We may have to root out some bad articles...
5054       (when (memq (setq number (mail-header-number
5055                                 (setq header (pop headers))))
5056                   gnus-newsgroup-limit)
5057         ;; Mark article as read when it has a low score.
5058         (when (and gnus-summary-mark-below
5059                    (< (or (cdr (assq number gnus-newsgroup-scored))
5060                           gnus-summary-default-score 0)
5061                       gnus-summary-mark-below)
5062                    (not (gnus-summary-article-ancient-p number)))
5063           (setq gnus-newsgroup-unreads
5064                 (delq number gnus-newsgroup-unreads))
5065           (if gnus-newsgroup-auto-expire
5066               (push number gnus-newsgroup-expirable)
5067             (push (cons number gnus-low-score-mark)
5068                   gnus-newsgroup-reads)))
5069
5070         (setq mark (gnus-article-mark number))
5071         (push (gnus-data-make number mark (1+ (point)) header 0)
5072               gnus-newsgroup-data)
5073         (gnus-summary-insert-line
5074          header 0 number
5075          (memq number gnus-newsgroup-undownloaded)
5076          mark (memq number gnus-newsgroup-replied)
5077          (memq number gnus-newsgroup-expirable)
5078          (mail-header-subject header) nil
5079          (cdr (assq number gnus-newsgroup-scored))
5080          (memq number gnus-newsgroup-processable))))))
5081
5082 (defun gnus-summary-remove-list-identifiers ()
5083   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5084   (let ((regexp (if (consp gnus-list-identifiers)
5085                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5086                   gnus-list-identifiers))
5087         changed subject)
5088     (when regexp
5089       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5090       (dolist (header gnus-newsgroup-headers)
5091         (setq subject (mail-header-subject header)
5092               changed nil)
5093         (while (string-match regexp subject)
5094           (setq subject
5095                 (concat (substring subject 0 (match-beginning 1))
5096                         (substring subject (match-end 0)))
5097                 changed t))
5098         (when changed
5099           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5100             (setq subject
5101                   (concat (substring subject 0 (match-beginning 1))
5102                           (substring subject (match-end 1)))))
5103           (mail-header-set-subject header subject))))))
5104
5105 (defun gnus-fetch-headers (articles)
5106   "Fetch headers of ARTICLES."
5107   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5108     (gnus-message 5 "Fetching headers for %s..." name)
5109     (prog1
5110         (if (eq 'nov
5111                 (setq gnus-headers-retrieved-by
5112                       (gnus-retrieve-headers
5113                        articles gnus-newsgroup-name
5114                        ;; We might want to fetch old headers, but
5115                        ;; not if there is only 1 article.
5116                        (and (or (and
5117                                  (not (eq gnus-fetch-old-headers 'some))
5118                                  (not (numberp gnus-fetch-old-headers)))
5119                                 (> (length articles) 1))
5120                             gnus-fetch-old-headers))))
5121             (gnus-get-newsgroup-headers-xover
5122              articles nil nil gnus-newsgroup-name t)
5123           (gnus-get-newsgroup-headers))
5124       (gnus-message 5 "Fetching headers for %s...done" name))))
5125
5126 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5127   "Select newsgroup GROUP.
5128 If READ-ALL is non-nil, all articles in the group are selected.
5129 If SELECT-ARTICLES, only select those articles from GROUP."
5130   (let* ((entry (gnus-group-entry group))
5131          ;;!!! Dirty hack; should be removed.
5132          (gnus-summary-ignore-duplicates
5133           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5134               t
5135             gnus-summary-ignore-duplicates))
5136          (info (nth 2 entry))
5137          articles fetched-articles cached)
5138
5139     (unless (gnus-check-server
5140              (set (make-local-variable 'gnus-current-select-method)
5141                   (gnus-find-method-for-group group)))
5142       (error "Couldn't open server"))
5143
5144     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5145         (gnus-activate-group group)     ; Or we can activate it...
5146         (progn                          ; Or we bug out.
5147           (when (equal major-mode 'gnus-summary-mode)
5148             (gnus-kill-buffer (current-buffer)))
5149           (error "Couldn't activate group %s: %s"
5150                  group (gnus-status-message group))))
5151
5152     (unless (gnus-request-group group t)
5153       (when (equal major-mode 'gnus-summary-mode)
5154         (gnus-kill-buffer (current-buffer)))
5155       (error "Couldn't request group %s: %s"
5156              group (gnus-status-message group)))
5157
5158     (when gnus-agent
5159       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5160
5161       (setq gnus-summary-use-undownloaded-faces
5162             (gnus-agent-find-parameter
5163              group
5164              'agent-enable-undownloaded-faces)))
5165
5166     (setq gnus-newsgroup-name group
5167           gnus-newsgroup-unselected nil
5168           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5169
5170     (let ((display (gnus-group-find-parameter group 'display)))
5171       (setq gnus-newsgroup-display
5172             (cond
5173              ((not (zerop (or (car-safe read-all) 0)))
5174               ;; The user entered the group with C-u SPC/RET, let's show
5175               ;; all articles.
5176               'gnus-not-ignore)
5177              ((eq display 'all)
5178               'gnus-not-ignore)
5179              ((arrayp display)
5180               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5181              ((numberp display)
5182               ;; The following is probably the "correct" solution, but
5183               ;; it makes Gnus fetch all headers and then limit the
5184               ;; articles (which is slow), so instead we hack the
5185               ;; select-articles parameter instead. -- Simon Josefsson
5186               ;; <jas@kth.se>
5187               ;;
5188               ;; (gnus-byte-compile
5189               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5190               ;;                         display)))))
5191               (setq select-articles
5192                     (gnus-uncompress-range
5193                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5194                              (if (> tmp 0)
5195                                  tmp
5196                                1))
5197                            (cdr (gnus-active group)))))
5198               nil)
5199              (t
5200               nil))))
5201
5202     (gnus-summary-setup-default-charset)
5203
5204     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5205     (when (gnus-virtual-group-p group)
5206       (setq cached gnus-newsgroup-cached))
5207
5208     (setq gnus-newsgroup-unreads
5209           (gnus-sorted-ndifference
5210            (gnus-sorted-ndifference gnus-newsgroup-unreads
5211                                     gnus-newsgroup-marked)
5212            gnus-newsgroup-dormant))
5213
5214     (setq gnus-newsgroup-processable nil)
5215
5216     (gnus-update-read-articles group gnus-newsgroup-unreads)
5217
5218     ;; Adjust and set lists of article marks.
5219     (when info
5220       (gnus-adjust-marked-articles info))
5221     (if (setq articles select-articles)
5222         (setq gnus-newsgroup-unselected
5223               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5224       (setq articles (gnus-articles-to-read group read-all)))
5225
5226     (cond
5227      ((null articles)
5228       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5229       'quit)
5230      ((eq articles 0) nil)
5231      (t
5232       ;; Init the dependencies hash table.
5233       (setq gnus-newsgroup-dependencies
5234             (gnus-make-hashtable (length articles)))
5235       (gnus-set-global-variables)
5236       ;; Retrieve the headers and read them in.
5237
5238       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5239
5240       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5241       (when cached
5242         (setq gnus-newsgroup-cached cached))
5243
5244       ;; Suppress duplicates?
5245       (when gnus-suppress-duplicates
5246         (gnus-dup-suppress-articles))
5247
5248       ;; Set the initial limit.
5249       (setq gnus-newsgroup-limit (copy-sequence articles))
5250       ;; Remove canceled articles from the list of unread articles.
5251       (setq fetched-articles
5252             (mapcar (lambda (headers) (mail-header-number headers))
5253                     gnus-newsgroup-headers))
5254       (setq gnus-newsgroup-articles fetched-articles)
5255       (setq gnus-newsgroup-unreads
5256             (gnus-sorted-nintersection
5257              gnus-newsgroup-unreads fetched-articles))
5258       (gnus-compute-unseen-list)
5259
5260       ;; Removed marked articles that do not exist.
5261       (gnus-update-missing-marks
5262        (gnus-sorted-difference articles fetched-articles))
5263       ;; We might want to build some more threads first.
5264       (when (and gnus-fetch-old-headers
5265                  (eq gnus-headers-retrieved-by 'nov))
5266         (if (eq gnus-fetch-old-headers 'invisible)
5267             (gnus-build-all-threads)
5268           (gnus-build-old-threads)))
5269       ;; Let the Gnus agent mark articles as read.
5270       (when gnus-agent
5271         (gnus-agent-get-undownloaded-list))
5272       ;; Remove list identifiers from subject
5273       (when gnus-list-identifiers
5274         (gnus-summary-remove-list-identifiers))
5275       ;; Check whether auto-expire is to be done in this group.
5276       (setq gnus-newsgroup-auto-expire
5277             (gnus-group-auto-expirable-p group))
5278       ;; Set up the article buffer now, if necessary.
5279       (unless gnus-single-article-buffer
5280         (gnus-article-setup-buffer))
5281       ;; First and last article in this newsgroup.
5282       (when gnus-newsgroup-headers
5283         (setq gnus-newsgroup-begin
5284               (mail-header-number (car gnus-newsgroup-headers))
5285               gnus-newsgroup-end
5286               (mail-header-number
5287                (gnus-last-element gnus-newsgroup-headers))))
5288       ;; GROUP is successfully selected.
5289       (or gnus-newsgroup-headers t)))))
5290
5291 (defun gnus-compute-unseen-list ()
5292   ;; The `seen' marks are treated specially.
5293   (if (not gnus-newsgroup-seen)
5294       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5295     (setq gnus-newsgroup-unseen
5296           (gnus-inverse-list-range-intersection
5297            gnus-newsgroup-articles gnus-newsgroup-seen))))
5298
5299 (defun gnus-summary-display-make-predicate (display)
5300   (require 'gnus-agent)
5301   (when (= (length display) 1)
5302     (setq display (car display)))
5303   (unless gnus-summary-display-cache
5304     (dolist (elem (append '((unread . unread)
5305                             (read . read)
5306                             (unseen . unseen))
5307                           gnus-article-mark-lists))
5308       (push (cons (cdr elem)
5309                   (gnus-byte-compile
5310                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5311             gnus-summary-display-cache)))
5312   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5313         (gnus-category-predicate-cache gnus-summary-display-cache))
5314     (gnus-get-predicate display)))
5315
5316 ;; Uses the dynamically bound `number' variable.
5317 (eval-when-compile
5318   (defvar number))
5319 (defun gnus-article-marked-p (type &optional article)
5320   (let ((article (or article number)))
5321     (cond
5322      ((eq type 'tick)
5323       (memq article gnus-newsgroup-marked))
5324      ((eq type 'spam)
5325       (memq article gnus-newsgroup-spam-marked))
5326      ((eq type 'unsend)
5327       (memq article gnus-newsgroup-unsendable))
5328      ((eq type 'undownload)
5329       (memq article gnus-newsgroup-undownloaded))
5330      ((eq type 'download)
5331       (memq article gnus-newsgroup-downloadable))
5332      ((eq type 'unread)
5333       (memq article gnus-newsgroup-unreads))
5334      ((eq type 'read)
5335       (memq article gnus-newsgroup-reads))
5336      ((eq type 'dormant)
5337       (memq article gnus-newsgroup-dormant) )
5338      ((eq type 'expire)
5339       (memq article gnus-newsgroup-expirable))
5340      ((eq type 'reply)
5341       (memq article gnus-newsgroup-replied))
5342      ((eq type 'killed)
5343       (memq article gnus-newsgroup-killed))
5344      ((eq type 'bookmark)
5345       (assq article gnus-newsgroup-bookmarks))
5346      ((eq type 'score)
5347       (assq article gnus-newsgroup-scored))
5348      ((eq type 'save)
5349       (memq article gnus-newsgroup-saved))
5350      ((eq type 'cache)
5351       (memq article gnus-newsgroup-cached))
5352      ((eq type 'forward)
5353       (memq article gnus-newsgroup-forwarded))
5354      ((eq type 'seen)
5355       (not (memq article gnus-newsgroup-unseen)))
5356      ((eq type 'recent)
5357       (memq article gnus-newsgroup-recent))
5358      (t t))))
5359
5360 (defun gnus-articles-to-read (group &optional read-all)
5361   "Find out what articles the user wants to read."
5362   (let* ((articles
5363           ;; Select all articles if `read-all' is non-nil, or if there
5364           ;; are no unread articles.
5365           (if (or read-all
5366                   (and (zerop (length gnus-newsgroup-marked))
5367                        (zerop (length gnus-newsgroup-unreads)))
5368                   ;; Fetch all if the predicate is non-nil.
5369                   gnus-newsgroup-display)
5370               ;; We want to select the headers for all the articles in
5371               ;; the group, so we select either all the active
5372               ;; articles in the group, or (if that's nil), the
5373               ;; articles in the cache.
5374               (or
5375                (gnus-uncompress-range (gnus-active group))
5376                (gnus-cache-articles-in-group group))
5377             ;; Select only the "normal" subset of articles.
5378             (gnus-sorted-nunion
5379              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5380              gnus-newsgroup-unreads)))
5381          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5382          (scored (length scored-list))
5383          (number (length articles))
5384          (marked (+ (length gnus-newsgroup-marked)
5385                     (length gnus-newsgroup-dormant)))
5386          (select
5387           (cond
5388            ((numberp read-all)
5389             read-all)
5390            ((numberp gnus-newsgroup-display)
5391             gnus-newsgroup-display)
5392            (t
5393             (condition-case ()
5394                 (cond
5395                  ((and (or (<= scored marked) (= scored number))
5396                        (numberp gnus-large-newsgroup)
5397                        (> number gnus-large-newsgroup))
5398                   (let* ((cursor-in-echo-area nil)
5399                          (initial (gnus-parameter-large-newsgroup-initial
5400                                    gnus-newsgroup-name))
5401                          (input
5402                           (read-string
5403                            (format
5404                             "How many articles from %s (%s %d): "
5405                             (gnus-limit-string
5406                              (gnus-group-decoded-name gnus-newsgroup-name)
5407                              35)
5408                             (if initial "max" "default")
5409                             number)
5410                            (if initial
5411                                (cons (number-to-string initial)
5412                                      0)))))
5413                     (if (string-match "^[ \t]*$" input) number input)))
5414                  ((and (> scored marked) (< scored number)
5415                        (> (- scored number) 20))
5416                   (let ((input
5417                          (read-string
5418                           (format "%s %s (%d scored, %d total): "
5419                                   "How many articles from"
5420                                   (gnus-group-decoded-name group)
5421                                   scored number))))
5422                     (if (string-match "^[ \t]*$" input)
5423                         number input)))
5424                  (t number))
5425               (quit
5426                (message "Quit getting the articles to read")
5427                nil))))))
5428     (setq select (if (stringp select) (string-to-number select) select))
5429     (if (or (null select) (zerop select))
5430         select
5431       (if (and (not (zerop scored)) (<= (abs select) scored))
5432           (progn
5433             (setq articles (sort scored-list '<))
5434             (setq number (length articles)))
5435         (setq articles (copy-sequence articles)))
5436
5437       (when (< (abs select) number)
5438         (if (< select 0)
5439             ;; Select the N oldest articles.
5440             (setcdr (nthcdr (1- (abs select)) articles) nil)
5441           ;; Select the N most recent articles.
5442           (setq articles (nthcdr (- number select) articles))))
5443       (setq gnus-newsgroup-unselected
5444             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5445       (when gnus-alter-articles-to-read-function
5446         (setq articles
5447               (sort
5448                (funcall gnus-alter-articles-to-read-function
5449                         gnus-newsgroup-name articles)
5450                '<)))
5451       articles)))
5452
5453 (defun gnus-killed-articles (killed articles)
5454   (let (out)
5455     (while articles
5456       (when (inline (gnus-member-of-range (car articles) killed))
5457         (push (car articles) out))
5458       (setq articles (cdr articles)))
5459     out))
5460
5461 (defun gnus-uncompress-marks (marks)
5462   "Uncompress the mark ranges in MARKS."
5463   (let ((uncompressed '(score bookmark))
5464         out)
5465     (while marks
5466       (if (memq (caar marks) uncompressed)
5467           (push (car marks) out)
5468         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5469       (setq marks (cdr marks)))
5470     out))
5471
5472 (defun gnus-article-mark-to-type (mark)
5473   "Return the type of MARK."
5474   (or (cadr (assq mark gnus-article-special-mark-lists))
5475       'list))
5476
5477 (defun gnus-article-unpropagatable-p (mark)
5478   "Return whether MARK should be propagated to back end."
5479   (memq mark gnus-article-unpropagated-mark-lists))
5480
5481 (defun gnus-adjust-marked-articles (info)
5482   "Set all article lists and remove all marks that are no longer valid."
5483   (let* ((marked-lists (gnus-info-marks info))
5484          (active (gnus-active (gnus-info-group info)))
5485          (min (car active))
5486          (max (cdr active))
5487          (types gnus-article-mark-lists)
5488          marks var articles article mark mark-type
5489          bgn end)
5490
5491     (dolist (marks marked-lists)
5492       (setq mark (car marks)
5493             mark-type (gnus-article-mark-to-type mark)
5494             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5495
5496       ;; We set the variable according to the type of the marks list,
5497       ;; and then adjust the marks to a subset of the active articles.
5498       (cond
5499        ;; Adjust "simple" lists - compressed yet unsorted
5500        ((eq mark-type 'list)
5501         ;; Simultaneously uncompress and clip to active range
5502         ;; See gnus-uncompress-range for a description of possible marks
5503         (let (l lh)
5504           (if (not (cadr marks))
5505               (set var nil)
5506             (setq articles (if (numberp (cddr marks))
5507                                (list (cdr marks))
5508                              (cdr marks))
5509                   lh (cons nil nil)
5510                   l lh)
5511
5512             (while (setq article (pop articles))
5513               (cond ((consp article)
5514                      (setq bgn (max (car article) min)
5515                            end (min (cdr article) max))
5516                      (while (<= bgn end)
5517                        (setq l (setcdr l (cons bgn nil))
5518                              bgn (1+ bgn))))
5519                     ((and (<= min article)
5520                           (>= max article))
5521                      (setq l (setcdr l (cons article nil))))))
5522             (set var (cdr lh)))))
5523        ;; Adjust assocs.
5524        ((eq mark-type 'tuple)
5525         (set var (setq articles (cdr marks)))
5526         (when (not (listp (cdr (symbol-value var))))
5527           (set var (list (symbol-value var))))
5528         (when (not (listp (cdr articles)))
5529           (setq articles (list articles)))
5530         (while articles
5531           (when (or (not (consp (setq article (pop articles))))
5532                     (< (car article) min)
5533                     (> (car article) max))
5534             (set var (delq article (symbol-value var))))))
5535        ;; Adjust ranges (sloppily).
5536        ((eq mark-type 'range)
5537         (cond
5538          ((eq mark 'seen)
5539           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5540           ;; It should be (seen (NUM1 . NUM2)).
5541           (when (numberp (cddr marks))
5542             (setcdr marks (list (cdr marks))))
5543           (setq articles (cdr marks))
5544           (while (and articles
5545                       (or (and (consp (car articles))
5546                                (> min (cdar articles)))
5547                           (and (numberp (car articles))
5548                                (> min (car articles)))))
5549             (pop articles))
5550           (set var articles))))))))
5551
5552 (defun gnus-update-missing-marks (missing)
5553   "Go through the list of MISSING articles and remove them from the mark lists."
5554   (when missing
5555     (let (var m)
5556       ;; Go through all types.
5557       (dolist (elem gnus-article-mark-lists)
5558         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5559           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5560           (when (symbol-value var)
5561             ;; This list has articles.  So we delete all missing
5562             ;; articles from it.
5563             (setq m missing)
5564             (while m
5565               (set var (delq (pop m) (symbol-value var))))))))))
5566
5567 (defun gnus-update-marks ()
5568   "Enter the various lists of marked articles into the newsgroup info list."
5569   (let ((types gnus-article-mark-lists)
5570         (info (gnus-get-info gnus-newsgroup-name))
5571         type list newmarked symbol delta-marks)
5572     (when info
5573       ;; Add all marks lists to the list of marks lists.
5574       (while (setq type (pop types))
5575         (setq list (symbol-value
5576                     (setq symbol
5577                           (intern (format "gnus-newsgroup-%s" (car type))))))
5578
5579         (when list
5580           ;; Get rid of the entries of the articles that have the
5581           ;; default score.
5582           (when (and (eq (cdr type) 'score)
5583                      gnus-save-score
5584                      list)
5585             (let* ((arts list)
5586                    (prev (cons nil list))
5587                    (all prev))
5588               (while arts
5589                 (if (or (not (consp (car arts)))
5590                         (= (cdar arts) gnus-summary-default-score))
5591                     (setcdr prev (cdr arts))
5592                   (setq prev arts))
5593                 (setq arts (cdr arts)))
5594               (setq list (cdr all)))))
5595
5596         (when (eq (cdr type) 'seen)
5597           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5598
5599         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5600           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5601
5602         (when (and (gnus-check-backend-function
5603                     'request-set-mark gnus-newsgroup-name)
5604                    (not (gnus-article-unpropagatable-p (cdr type))))
5605           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5606                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5607                  (add (gnus-remove-from-range
5608                        (gnus-copy-sequence list) old)))
5609             (when add
5610               (push (list add 'add (list (cdr type))) delta-marks))
5611             (when del
5612               (push (list del 'del (list (cdr type))) delta-marks))))
5613
5614         (when list
5615           (push (cons (cdr type) list) newmarked)))
5616
5617       (when delta-marks
5618         (unless (gnus-check-group gnus-newsgroup-name)
5619           (error "Can't open server for %s" gnus-newsgroup-name))
5620         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5621
5622       ;; Enter these new marks into the info of the group.
5623       (if (nthcdr 3 info)
5624           (setcar (nthcdr 3 info) newmarked)
5625         ;; Add the marks lists to the end of the info.
5626         (when newmarked
5627           (setcdr (nthcdr 2 info) (list newmarked))))
5628
5629       ;; Cut off the end of the info if there's nothing else there.
5630       (let ((i 5))
5631         (while (and (> i 2)
5632                     (not (nth i info)))
5633           (when (nthcdr (decf i) info)
5634             (setcdr (nthcdr i info) nil)))))))
5635
5636 (defun gnus-set-mode-line (where)
5637   "Set the mode line of the article or summary buffers.
5638 If WHERE is `summary', the summary mode line format will be used."
5639   ;; Is this mode line one we keep updated?
5640   (when (and (memq where gnus-updated-mode-lines)
5641              (symbol-value
5642               (intern (format "gnus-%s-mode-line-format-spec" where))))
5643     (let (mode-string)
5644       (save-excursion
5645         ;; We evaluate this in the summary buffer since these
5646         ;; variables are buffer-local to that buffer.
5647         (set-buffer gnus-summary-buffer)
5648         ;; We bind all these variables that are used in the `eval' form
5649         ;; below.
5650         (let* ((mformat (symbol-value
5651                          (intern
5652                           (format "gnus-%s-mode-line-format-spec" where))))
5653                (gnus-tmp-group-name (gnus-group-decoded-name
5654                                      gnus-newsgroup-name))
5655                (gnus-tmp-article-number (or gnus-current-article 0))
5656                (gnus-tmp-unread gnus-newsgroup-unreads)
5657                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
5658                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
5659                (gnus-tmp-unread-and-unselected
5660                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
5661                             (zerop gnus-tmp-unselected))
5662                        "")
5663                       ((zerop gnus-tmp-unselected)
5664                        (format "{%d more}" gnus-tmp-unread-and-unticked))
5665                       (t (format "{%d(+%d) more}"
5666                                  gnus-tmp-unread-and-unticked
5667                                  gnus-tmp-unselected))))
5668                (gnus-tmp-subject
5669                 (if (and gnus-current-headers
5670                          (vectorp gnus-current-headers))
5671                     (gnus-mode-string-quote
5672                      (mail-header-subject gnus-current-headers))
5673                   ""))
5674                bufname-length max-len
5675                gnus-tmp-header);; passed as argument to any user-format-funcs
5676           (setq mode-string (eval mformat))
5677           (setq bufname-length (if (string-match "%b" mode-string)
5678                                    (- (length
5679                                        (buffer-name
5680                                         (if (eq where 'summary)
5681                                             nil
5682                                           (get-buffer gnus-article-buffer))))
5683                                       2)
5684                                  0))
5685           (setq max-len (max 4 (if gnus-mode-non-string-length
5686                                    (- (window-width)
5687                                       gnus-mode-non-string-length
5688                                       bufname-length)
5689                                  (length mode-string))))
5690           ;; We might have to chop a bit of the string off...
5691           (when (> (length mode-string) max-len)
5692             (setq mode-string
5693                   (concat (gnus-truncate-string mode-string (- max-len 3))
5694                           "...")))
5695           ;; Pad the mode string a bit.
5696           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
5697       ;; Update the mode line.
5698       (setq mode-line-buffer-identification
5699             (gnus-mode-line-buffer-identification (list mode-string)))
5700       (set-buffer-modified-p t))))
5701
5702 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
5703   "Go through the HEADERS list and add all Xrefs to a hash table.
5704 The resulting hash table is returned, or nil if no Xrefs were found."
5705   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
5706          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
5707          (xref-hashtb (gnus-make-hashtable))
5708          start group entry number xrefs header)
5709     (while headers
5710       (setq header (pop headers))
5711       (when (and (setq xrefs (mail-header-xref header))
5712                  (not (memq (setq number (mail-header-number header))
5713                             unreads)))
5714         (setq start 0)
5715         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
5716           (setq start (match-end 0))
5717           (setq group (if prefix
5718                           (concat prefix (substring xrefs (match-beginning 1)
5719                                                     (match-end 1)))
5720                         (substring xrefs (match-beginning 1) (match-end 1))))
5721           (setq number
5722                 (string-to-int (substring xrefs (match-beginning 2)
5723                                           (match-end 2))))
5724           (if (setq entry (gnus-gethash group xref-hashtb))
5725               (setcdr entry (cons number (cdr entry)))
5726             (gnus-sethash group (cons number nil) xref-hashtb)))))
5727     (and start xref-hashtb)))
5728
5729 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
5730   "Look through all the headers and mark the Xrefs as read."
5731   (let ((virtual (gnus-virtual-group-p from-newsgroup))
5732         name info xref-hashtb idlist method nth4)
5733     (save-excursion
5734       (set-buffer gnus-group-buffer)
5735       (when (setq xref-hashtb
5736                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
5737         (mapatoms
5738          (lambda (group)
5739            (unless (string= from-newsgroup (setq name (symbol-name group)))
5740              (setq idlist (symbol-value group))
5741              ;; Dead groups are not updated.
5742              (and (prog1
5743                       (setq info (gnus-get-info name))
5744                     (when (stringp (setq nth4 (gnus-info-method info)))
5745                       (setq nth4 (gnus-server-to-method nth4))))
5746                   ;; Only do the xrefs if the group has the same
5747                   ;; select method as the group we have just read.
5748                   (or (gnus-methods-equal-p
5749                        nth4 (gnus-find-method-for-group from-newsgroup))
5750                       virtual
5751                       (equal nth4 (setq method (gnus-find-method-for-group
5752                                                 from-newsgroup)))
5753                       (and (equal (car nth4) (car method))
5754                            (equal (nth 1 nth4) (nth 1 method))))
5755                   gnus-use-cross-reference
5756                   (or (not (eq gnus-use-cross-reference t))
5757                       virtual
5758                       ;; Only do cross-references on subscribed
5759                       ;; groups, if that is what is wanted.
5760                       (<= (gnus-info-level info) gnus-level-subscribed))
5761                   (gnus-group-make-articles-read name idlist))))
5762          xref-hashtb)))))
5763
5764 (defun gnus-compute-read-articles (group articles)
5765   (let* ((entry (gnus-group-entry group))
5766          (info (nth 2 entry))
5767          (active (gnus-active group))
5768          ninfo)
5769     (when entry
5770       ;; First peel off all invalid article numbers.
5771       (when active
5772         (let ((ids articles)
5773               id first)
5774           (while (setq id (pop ids))
5775             (when (and first (> id (cdr active)))
5776               ;; We'll end up in this situation in one particular
5777               ;; obscure situation.  If you re-scan a group and get
5778               ;; a new article that is cross-posted to a different
5779               ;; group that has not been re-scanned, you might get
5780               ;; crossposted article that has a higher number than
5781               ;; Gnus believes possible.  So we re-activate this
5782               ;; group as well.  This might mean doing the
5783               ;; crossposting thingy will *increase* the number
5784               ;; of articles in some groups.  Tsk, tsk.
5785               (setq active (or (gnus-activate-group group) active)))
5786             (when (or (> id (cdr active))
5787                       (< id (car active)))
5788               (setq articles (delq id articles))))))
5789       ;; If the read list is nil, we init it.
5790       (if (and active
5791                (null (gnus-info-read info))
5792                (> (car active) 1))
5793           (setq ninfo (cons 1 (1- (car active))))
5794         (setq ninfo (gnus-info-read info)))
5795       ;; Then we add the read articles to the range.
5796       (gnus-add-to-range
5797        ninfo (setq articles (sort articles '<))))))
5798
5799 (defun gnus-group-make-articles-read (group articles)
5800   "Update the info of GROUP to say that ARTICLES are read."
5801   (let* ((num 0)
5802          (entry (gnus-group-entry group))
5803          (info (nth 2 entry))
5804          (active (gnus-active group))
5805          range)
5806     (when entry
5807       (setq range (gnus-compute-read-articles group articles))
5808       (with-current-buffer gnus-group-buffer
5809         (gnus-undo-register
5810           `(progn
5811              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
5812              (gnus-info-set-read ',info ',(gnus-info-read info))
5813              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
5814              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
5815              (gnus-group-update-group ,group t))))
5816       ;; Add the read articles to the range.
5817       (gnus-info-set-read info range)
5818       (gnus-request-set-mark group (list (list range 'add '(read))))
5819       ;; Then we have to re-compute how many unread
5820       ;; articles there are in this group.
5821       (when active
5822         (cond
5823          ((not range)
5824           (setq num (- (1+ (cdr active)) (car active))))
5825          ((not (listp (cdr range)))
5826           (setq num (- (cdr active) (- (1+ (cdr range))
5827                                        (car range)))))
5828          (t
5829           (while range
5830             (if (numberp (car range))
5831                 (setq num (1+ num))
5832               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
5833             (setq range (cdr range)))
5834           (setq num (- (cdr active) num))))
5835         ;; Update the number of unread articles.
5836         (setcar entry num)
5837         ;; Update the group buffer.
5838         (unless (gnus-ephemeral-group-p group)
5839           (gnus-group-update-group group t))))))
5840
5841 (defvar gnus-newsgroup-none-id 0)
5842
5843 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
5844   (let ((cur nntp-server-buffer)
5845         (dependencies
5846          (or dependencies
5847              (with-current-buffer gnus-summary-buffer
5848                gnus-newsgroup-dependencies)))
5849         headers id end ref number
5850         (mail-parse-charset gnus-newsgroup-charset)
5851         (mail-parse-ignored-charsets
5852          (save-excursion (condition-case nil
5853                              (set-buffer gnus-summary-buffer)
5854                            (error))
5855                          gnus-newsgroup-ignored-charsets)))
5856     (save-excursion
5857       (set-buffer nntp-server-buffer)
5858       ;; Translate all TAB characters into SPACE characters.
5859       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
5860       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
5861       (ietf-drums-unfold-fws)
5862       (gnus-run-hooks 'gnus-parse-headers-hook)
5863       (let ((case-fold-search t)
5864             in-reply-to header p lines chars ctype)
5865         (goto-char (point-min))
5866         ;; Search to the beginning of the next header.  Error messages
5867         ;; do not begin with 2 or 3.
5868         (while (re-search-forward "^[23][0-9]+ " nil t)
5869           (setq id nil
5870                 ref nil)
5871           ;; This implementation of this function, with nine
5872           ;; search-forwards instead of the one re-search-forward and
5873           ;; a case (which basically was the old function) is actually
5874           ;; about twice as fast, even though it looks messier.  You
5875           ;; can't have everything, I guess.  Speed and elegance
5876           ;; doesn't always go hand in hand.
5877           (setq
5878            header
5879            (make-full-mail-header
5880             ;; Number.
5881             (prog1
5882                 (setq number (read cur))
5883               (end-of-line)
5884               (setq p (point))
5885               (narrow-to-region (point)
5886                                 (or (and (search-forward "\n.\n" nil t)
5887                                          (- (point) 2))
5888                                     (point))))
5889             ;; Subject.
5890             (progn
5891               (goto-char p)
5892               (if (search-forward "\nsubject:" nil t)
5893                   (nnheader-header-value)
5894                 "(none)"))
5895             ;; From.
5896             (progn
5897               (goto-char p)
5898               (if (search-forward "\nfrom:" nil t)
5899                   (nnheader-header-value)
5900                 "(nobody)"))
5901             ;; Date.
5902             (progn
5903               (goto-char p)
5904               (if (search-forward "\ndate:" nil t)
5905                   (nnheader-header-value) ""))
5906             ;; Message-ID.
5907             (progn
5908               (goto-char p)
5909               (setq id (if (re-search-forward
5910                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
5911                            ;; We do it this way to make sure the Message-ID
5912                            ;; is (somewhat) syntactically valid.
5913                            (buffer-substring (match-beginning 1)
5914                                              (match-end 1))
5915                          ;; If there was no message-id, we just fake one
5916                          ;; to make subsequent routines simpler.
5917                          (nnheader-generate-fake-message-id number))))
5918             ;; References.
5919             (progn
5920               (goto-char p)
5921               (if (search-forward "\nreferences:" nil t)
5922                   (progn
5923                     (setq end (point))
5924                     (prog1
5925                         (nnheader-header-value)
5926                       (setq ref
5927                             (buffer-substring
5928                              (progn
5929                                ;; (end-of-line)
5930                                (search-backward ">" end t)
5931                                (1+ (point)))
5932                              (progn
5933                                (search-backward "<" end t)
5934                                (point))))))
5935                 ;; Get the references from the in-reply-to header if there
5936                 ;; were no references and the in-reply-to header looks
5937                 ;; promising.
5938                 (if (and (search-forward "\nin-reply-to:" nil t)
5939                          (setq in-reply-to (nnheader-header-value))
5940                          (string-match "<[^>]+>" in-reply-to))
5941                     (let (ref2)
5942                       (setq ref (substring in-reply-to (match-beginning 0)
5943                                            (match-end 0)))
5944                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
5945                         (setq ref2 (substring in-reply-to (match-beginning 0)
5946                                               (match-end 0)))
5947                         (when (> (length ref2) (length ref))
5948                           (setq ref ref2)))
5949                       ref)
5950                   (setq ref nil))))
5951             ;; Chars.
5952             (progn
5953               (goto-char p)
5954               (if (search-forward "\nchars: " nil t)
5955                   (if (numberp (setq chars (ignore-errors (read cur))))
5956                       chars -1)
5957                 -1))
5958             ;; Lines.
5959             (progn
5960               (goto-char p)
5961               (if (search-forward "\nlines: " nil t)
5962                   (if (numberp (setq lines (ignore-errors (read cur))))
5963                       lines -1)
5964                 -1))
5965             ;; Xref.
5966             (progn
5967               (goto-char p)
5968               (and (search-forward "\nxref:" nil t)
5969                    (nnheader-header-value)))
5970             ;; Extra.
5971             (when gnus-extra-headers
5972               (let ((extra gnus-extra-headers)
5973                     out)
5974                 (while extra
5975                   (goto-char p)
5976                   (when (search-forward
5977                          (concat "\n" (symbol-name (car extra)) ":") nil t)
5978                     (push (cons (car extra) (nnheader-header-value)) out))
5979                   (pop extra))
5980                 out))))
5981           (goto-char p)
5982           (if (and (search-forward "\ncontent-type: " nil t)
5983                    (setq ctype (nnheader-header-value)))
5984               (mime-entity-set-content-type-internal
5985                header (mime-parse-Content-Type ctype)))
5986           (when (equal id ref)
5987             (setq ref nil))
5988
5989           (when gnus-alter-header-function
5990             (funcall gnus-alter-header-function header)
5991             (setq id (mail-header-id header)
5992                   ref (gnus-parent-id (mail-header-references header))))
5993
5994           (when (setq header
5995                       (gnus-dependencies-add-header
5996                        header dependencies force-new))
5997             (push header headers))
5998           (goto-char (point-max))
5999           (widen))
6000         (nreverse headers)))))
6001
6002 ;; Goes through the xover lines and returns a list of vectors
6003 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6004                                                   force-new dependencies
6005                                                   group also-fetch-heads)
6006   "Parse the news overview data in the server buffer.
6007 Return a list of headers that match SEQUENCE (see
6008 `nntp-retrieve-headers')."
6009   ;; Get the Xref when the users reads the articles since most/some
6010   ;; NNTP servers do not include Xrefs when using XOVER.
6011   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6012   (let ((mail-parse-charset gnus-newsgroup-charset)
6013         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6014         (cur nntp-server-buffer)
6015         (dependencies (or dependencies gnus-newsgroup-dependencies))
6016         (allp (cond
6017                ((eq gnus-read-all-available-headers t)
6018                 t)
6019                ((stringp gnus-read-all-available-headers)
6020                 (string-match gnus-read-all-available-headers group))
6021                (t
6022                 nil)))
6023         number headers header)
6024     (save-excursion
6025       (set-buffer nntp-server-buffer)
6026       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6027       ;; Allow the user to mangle the headers before parsing them.
6028       (gnus-run-hooks 'gnus-parse-headers-hook)
6029       (goto-char (point-min))
6030       (gnus-parse-without-error
6031         (while (and (or sequence allp)
6032                     (not (eobp)))
6033           (setq number (read cur))
6034           (when (not allp)
6035             (while (and sequence
6036                         (< (car sequence) number))
6037               (setq sequence (cdr sequence))))
6038           (when (and (or allp
6039                          (and sequence
6040                               (eq number (car sequence))))
6041                      (progn
6042                        (setq sequence (cdr sequence))
6043                        (setq header (inline
6044                                       (gnus-nov-parse-line
6045                                        number dependencies force-new)))))
6046             (push header headers))
6047           (forward-line 1)))
6048       ;; A common bug in inn is that if you have posted an article and
6049       ;; then retrieves the active file, it will answer correctly --
6050       ;; the new article is included.  However, a NOV entry for the
6051       ;; article may not have been generated yet, so this may fail.
6052       ;; We work around this problem by retrieving the last few
6053       ;; headers using HEAD.
6054       (if (or (not also-fetch-heads)
6055               (not sequence))
6056           ;; We (probably) got all the headers.
6057           (nreverse headers)
6058         (let ((gnus-nov-is-evil t))
6059           (nconc
6060            (nreverse headers)
6061            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6062              (gnus-get-newsgroup-headers))))))))
6063
6064 (defun gnus-article-get-xrefs ()
6065   "Fill in the Xref value in `gnus-current-headers', if necessary.
6066 This is meant to be called in `gnus-article-internal-prepare-hook'."
6067   (let ((headers (with-current-buffer gnus-summary-buffer
6068                    gnus-current-headers)))
6069     (or (not gnus-use-cross-reference)
6070         (not headers)
6071         (and (mail-header-xref headers)
6072              (not (string= (mail-header-xref headers) "")))
6073         (let ((case-fold-search t)
6074               xref)
6075           (save-restriction
6076             (nnheader-narrow-to-headers)
6077             (goto-char (point-min))
6078             (when (or (and (not (eobp))
6079                            (eq (downcase (char-after)) ?x)
6080                            (looking-at "Xref:"))
6081                       (search-forward "\nXref:" nil t))
6082               (goto-char (1+ (match-end 0)))
6083               (setq xref (buffer-substring (point) (point-at-eol)))
6084               (mail-header-set-xref headers xref)))))))
6085
6086 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6087   "Find article ID and insert the summary line for that article.
6088 OLD-HEADER can either be a header or a line number to insert
6089 the subject line on."
6090   (let* ((line (and (numberp old-header) old-header))
6091          (old-header (and (vectorp old-header) old-header))
6092          (header (cond ((and old-header use-old-header)
6093                         old-header)
6094                        ((and (numberp id)
6095                              (gnus-number-to-header id))
6096                         (gnus-number-to-header id))
6097                        (t
6098                         (gnus-read-header id))))
6099          (number (and (numberp id) id))
6100          d)
6101     (when header
6102       ;; Rebuild the thread that this article is part of and go to the
6103       ;; article we have fetched.
6104       (when (and (not gnus-show-threads)
6105                  old-header)
6106         (when (and number
6107                    (setq d (gnus-data-find (mail-header-number old-header))))
6108           (goto-char (gnus-data-pos d))
6109           (gnus-data-remove
6110            number
6111            (- (point-at-bol)
6112               (prog1
6113                   (1+ (point-at-eol))
6114                 (gnus-delete-line))))))
6115       ;; Remove list identifiers from subject.
6116       (when gnus-list-identifiers
6117         (let ((gnus-newsgroup-headers (list header)))
6118           (gnus-summary-remove-list-identifiers)))
6119       (when old-header
6120         (mail-header-set-number header (mail-header-number old-header)))
6121       (setq gnus-newsgroup-sparse
6122             (delq (setq number (mail-header-number header))
6123                   gnus-newsgroup-sparse))
6124       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6125       (push number gnus-newsgroup-limit)
6126       (gnus-rebuild-thread (mail-header-id header) line)
6127       (gnus-summary-goto-subject number nil t))
6128     (when (and (numberp number)
6129                (> number 0))
6130       ;; We have to update the boundaries even if we can't fetch the
6131       ;; article if ID is a number -- so that the next `P' or `N'
6132       ;; command will fetch the previous (or next) article even
6133       ;; if the one we tried to fetch this time has been canceled.
6134       (when (> number gnus-newsgroup-end)
6135         (setq gnus-newsgroup-end number))
6136       (when (< number gnus-newsgroup-begin)
6137         (setq gnus-newsgroup-begin number))
6138       (setq gnus-newsgroup-unselected
6139             (delq number gnus-newsgroup-unselected)))
6140     ;; Report back a success?
6141     (and header (mail-header-number header))))
6142
6143 ;;; Process/prefix in the summary buffer
6144
6145 (defun gnus-summary-work-articles (n)
6146   "Return a list of articles to be worked upon.
6147 The prefix argument, the list of process marked articles, and the
6148 current article will be taken into consideration."
6149   (save-excursion
6150     (set-buffer gnus-summary-buffer)
6151     (cond
6152      (n
6153       ;; A numerical prefix has been given.
6154       (setq n (prefix-numeric-value n))
6155       (let ((backward (< n 0))
6156             (n (abs (prefix-numeric-value n)))
6157             articles article)
6158         (save-excursion
6159           (while
6160               (and (> n 0)
6161                    (push (setq article (gnus-summary-article-number))
6162                          articles)
6163                    (if backward
6164                        (gnus-summary-find-prev nil article)
6165                      (gnus-summary-find-next nil article)))
6166             (decf n)))
6167         (nreverse articles)))
6168      ((and (gnus-region-active-p) (mark))
6169       (message "region active")
6170       ;; Work on the region between point and mark.
6171       (let ((max (max (point) (mark)))
6172             articles article)
6173         (save-excursion
6174           (goto-char (min (point) (mark)))
6175           (while
6176               (and
6177                (push (setq article (gnus-summary-article-number)) articles)
6178                (gnus-summary-find-next nil article)
6179                (< (point) max)))
6180           (nreverse articles))))
6181      (gnus-newsgroup-processable
6182       ;; There are process-marked articles present.
6183       ;; Save current state.
6184       (gnus-summary-save-process-mark)
6185       ;; Return the list.
6186       (reverse gnus-newsgroup-processable))
6187      (t
6188       ;; Just return the current article.
6189       (list (gnus-summary-article-number))))))
6190
6191 (defmacro gnus-summary-iterate (arg &rest forms)
6192   "Iterate over the process/prefixed articles and do FORMS.
6193 ARG is the interactive prefix given to the command.  FORMS will be
6194 executed with point over the summary line of the articles."
6195   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6196     `(let ((,articles (gnus-summary-work-articles ,arg)))
6197        (while ,articles
6198          (gnus-summary-goto-subject (car ,articles))
6199          ,@forms
6200          (pop ,articles)))))
6201
6202 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6203 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6204
6205 (defun gnus-summary-save-process-mark ()
6206   "Push the current set of process marked articles on the stack."
6207   (interactive)
6208   (push (copy-sequence gnus-newsgroup-processable)
6209         gnus-newsgroup-process-stack))
6210
6211 (defun gnus-summary-kill-process-mark ()
6212   "Push the current set of process marked articles on the stack and unmark."
6213   (interactive)
6214   (gnus-summary-save-process-mark)
6215   (gnus-summary-unmark-all-processable))
6216
6217 (defun gnus-summary-yank-process-mark ()
6218   "Pop the last process mark state off the stack and restore it."
6219   (interactive)
6220   (unless gnus-newsgroup-process-stack
6221     (error "Empty mark stack"))
6222   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6223
6224 (defun gnus-summary-process-mark-set (set)
6225   "Make SET into the current process marked articles."
6226   (gnus-summary-unmark-all-processable)
6227   (mapc 'gnus-summary-set-process-mark set))
6228
6229 ;;; Searching and stuff
6230
6231 (defun gnus-summary-search-group (&optional backward use-level)
6232   "Search for next unread newsgroup.
6233 If optional argument BACKWARD is non-nil, search backward instead."
6234   (save-excursion
6235     (set-buffer gnus-group-buffer)
6236     (when (gnus-group-search-forward
6237            backward nil (if use-level (gnus-group-group-level) nil))
6238       (gnus-group-group-name))))
6239
6240 (defun gnus-summary-best-group (&optional exclude-group)
6241   "Find the name of the best unread group.
6242 If EXCLUDE-GROUP, do not go to this group."
6243   (with-current-buffer gnus-group-buffer
6244     (save-excursion
6245       (gnus-group-best-unread-group exclude-group))))
6246
6247 (defun gnus-summary-find-next (&optional unread article backward)
6248   (if backward
6249       (gnus-summary-find-prev unread article)
6250     (let* ((dummy (gnus-summary-article-intangible-p))
6251            (article (or article (gnus-summary-article-number)))
6252            (data (gnus-data-find-list article))
6253            result)
6254       (when (and (not dummy)
6255                  (or (not gnus-summary-check-current)
6256                      (not unread)
6257                      (not (gnus-data-unread-p (car data)))))
6258         (setq data (cdr data)))
6259       (when (setq result
6260                   (if unread
6261                       (progn
6262                         (while data
6263                           (unless (memq (gnus-data-number (car data))
6264                                         (cond
6265                                          ((eq gnus-auto-goto-ignores
6266                                               'always-undownloaded)
6267                                           gnus-newsgroup-undownloaded)
6268                                          (gnus-plugged
6269                                           nil)
6270                                          ((eq gnus-auto-goto-ignores
6271                                               'unfetched)
6272                                           gnus-newsgroup-unfetched)
6273                                          ((eq gnus-auto-goto-ignores
6274                                               'undownloaded)
6275                                           gnus-newsgroup-undownloaded)))
6276                             (when (gnus-data-unread-p (car data))
6277                               (setq result (car data)
6278                                     data nil)))
6279                           (setq data (cdr data)))
6280                         result)
6281                     (car data)))
6282         (goto-char (gnus-data-pos result))
6283         (gnus-data-number result)))))
6284
6285 (defun gnus-summary-find-prev (&optional unread article)
6286   (let* ((eobp (eobp))
6287          (article (or article (gnus-summary-article-number)))
6288          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6289          result)
6290     (when (and (not eobp)
6291                (or (not gnus-summary-check-current)
6292                    (not unread)
6293                    (not (gnus-data-unread-p (car data)))))
6294       (setq data (cdr data)))
6295     (when (setq result
6296                 (if unread
6297                     (progn
6298                       (while data
6299                         (unless (memq (gnus-data-number (car data))
6300                                       (cond
6301                                        ((eq gnus-auto-goto-ignores
6302                                             'always-undownloaded)
6303                                         gnus-newsgroup-undownloaded)
6304                                        (gnus-plugged
6305                                         nil)
6306                                        ((eq gnus-auto-goto-ignores
6307                                             'unfetched)
6308                                         gnus-newsgroup-unfetched)
6309                                        ((eq gnus-auto-goto-ignores
6310                                             'undownloaded)
6311                                         gnus-newsgroup-undownloaded)))
6312                           (when (gnus-data-unread-p (car data))
6313                             (setq result (car data)
6314                                   data nil)))
6315                         (setq data (cdr data)))
6316                       result)
6317                   (car data)))
6318       (goto-char (gnus-data-pos result))
6319       (gnus-data-number result))))
6320
6321 (defun gnus-summary-find-subject (subject &optional unread backward article)
6322   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6323          (article (or article (gnus-summary-article-number)))
6324          (articles (gnus-data-list backward))
6325          (arts (gnus-data-find-list article articles))
6326          result)
6327     (when (or (not gnus-summary-check-current)
6328               (not unread)
6329               (not (gnus-data-unread-p (car arts))))
6330       (setq arts (cdr arts)))
6331     (while arts
6332       (and (or (not unread)
6333                (gnus-data-unread-p (car arts)))
6334            (vectorp (gnus-data-header (car arts)))
6335            (gnus-subject-equal
6336             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6337            (setq result (car arts)
6338                  arts nil))
6339       (setq arts (cdr arts)))
6340     (and result
6341          (goto-char (gnus-data-pos result))
6342          (gnus-data-number result))))
6343
6344 (defun gnus-summary-search-forward (&optional unread subject backward)
6345   "Search forward for an article.
6346 If UNREAD, look for unread articles.  If SUBJECT, look for
6347 articles with that subject.  If BACKWARD, search backward instead."
6348   (cond (subject (gnus-summary-find-subject subject unread backward))
6349         (backward (gnus-summary-find-prev unread))
6350         (t (gnus-summary-find-next unread))))
6351
6352 (defun gnus-recenter (&optional n)
6353   "Center point in window and redisplay frame.
6354 Also do horizontal recentering."
6355   (interactive "P")
6356   (when (and gnus-auto-center-summary
6357              (not (eq gnus-auto-center-summary 'vertical)))
6358     (gnus-horizontal-recenter))
6359   (recenter n))
6360
6361 (defun gnus-summary-recenter ()
6362   "Center point in the summary window.
6363 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6364 displayed, no centering will be performed."
6365   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6366   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6367   (interactive)
6368   ;; The user has to want it.
6369   (when gnus-auto-center-summary
6370     (let* ((top (cond ((< (window-height) 4) 0)
6371                       ((< (window-height) 7) 1)
6372                       (t (if (numberp gnus-auto-center-summary)
6373                              gnus-auto-center-summary
6374                            (/ (1- (window-height)) 2)))))
6375            (height (1- (window-height)))
6376            (bottom (save-excursion (goto-char (point-max))
6377                                    (forward-line (- height))
6378                                    (point)))
6379            (window (get-buffer-window (current-buffer))))
6380       (when (get-buffer-window gnus-article-buffer)
6381         ;; Only do recentering when the article buffer is displayed,
6382         ;; Set the window start to either `bottom', which is the biggest
6383         ;; possible valid number, or the second line from the top,
6384         ;; whichever is the least.
6385         (let ((top-pos (save-excursion (forward-line (- top)) (point))))
6386           (if (> bottom top-pos)
6387               ;; Keep the second line from the top visible
6388               (set-window-start window top-pos t)
6389             ;; Try to keep the bottom line visible; if it's partially
6390             ;; obscured, either scroll one more line to make it fully
6391             ;; visible, or revert to using TOP-POS.
6392             (save-excursion
6393               (goto-char (point-max))
6394               (forward-line -1)
6395               (let ((last-line-start (point)))
6396                 (goto-char bottom)
6397                 (set-window-start window (point) t)
6398                 (when (not (pos-visible-in-window-p last-line-start window))
6399                   (forward-line 1)
6400                   (set-window-start window (min (point) top-pos) t)))))))
6401       ;; Do horizontal recentering while we're at it.
6402       (when (and (get-buffer-window (current-buffer) t)
6403                  (not (eq gnus-auto-center-summary 'vertical)))
6404         (let ((selected (selected-window)))
6405           (select-window (get-buffer-window (current-buffer) t))
6406           (gnus-summary-position-point)
6407           (gnus-horizontal-recenter)
6408           (select-window selected))))))
6409
6410 (defun gnus-summary-jump-to-group (newsgroup)
6411   "Move point to NEWSGROUP in group mode buffer."
6412   ;; Keep update point of group mode buffer if visible.
6413   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6414       (save-window-excursion
6415         ;; Take care of tree window mode.
6416         (when (get-buffer-window gnus-group-buffer)
6417           (pop-to-buffer gnus-group-buffer))
6418         (gnus-group-jump-to-group newsgroup))
6419     (save-excursion
6420       ;; Take care of tree window mode.
6421       (if (get-buffer-window gnus-group-buffer)
6422           (pop-to-buffer gnus-group-buffer)
6423         (set-buffer gnus-group-buffer))
6424       (gnus-group-jump-to-group newsgroup))))
6425
6426 ;; This function returns a list of article numbers based on the
6427 ;; difference between the ranges of read articles in this group and
6428 ;; the range of active articles.
6429 (defun gnus-list-of-unread-articles (group)
6430   (let* ((read (gnus-info-read (gnus-get-info group)))
6431          (active (or (gnus-active group) (gnus-activate-group group)))
6432          (last (or (cdr active)
6433                    (error "Group %s couldn't be activated " group)))
6434          first nlast unread)
6435     ;; If none are read, then all are unread.
6436     (if (not read)
6437         (setq first (car active))
6438       ;; If the range of read articles is a single range, then the
6439       ;; first unread article is the article after the last read
6440       ;; article.  Sounds logical, doesn't it?
6441       (if (and (not (listp (cdr read)))
6442                (or (< (car read) (car active))
6443                    (progn (setq read (list read))
6444                           nil)))
6445           (setq first (max (car active) (1+ (cdr read))))
6446         ;; `read' is a list of ranges.
6447         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6448                                   (caar read)))
6449                   1)
6450           (setq first (car active)))
6451         (while read
6452           (when first
6453             (while (< first nlast)
6454               (setq unread (cons first unread)
6455                     first (1+ first))))
6456           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6457           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6458           (setq read (cdr read)))))
6459     ;; And add the last unread articles.
6460     (while (<= first last)
6461       (setq unread (cons first unread)
6462             first (1+ first)))
6463     ;; Return the list of unread articles.
6464     (delq 0 (nreverse unread))))
6465
6466 (defun gnus-list-of-read-articles (group)
6467   "Return a list of unread, unticked and non-dormant articles."
6468   (let* ((info (gnus-get-info group))
6469          (marked (gnus-info-marks info))
6470          (active (gnus-active group)))
6471     (and info active
6472          (gnus-list-range-difference
6473           (gnus-list-range-difference
6474            (gnus-sorted-complement
6475             (gnus-uncompress-range active)
6476             (gnus-list-of-unread-articles group))
6477            (cdr (assq 'dormant marked)))
6478           (cdr (assq 'tick marked))))))
6479
6480 ;; This function returns a sequence of article numbers based on the
6481 ;; difference between the ranges of read articles in this group and
6482 ;; the range of active articles.
6483 (defun gnus-sequence-of-unread-articles (group)
6484   (let* ((read (gnus-info-read (gnus-get-info group)))
6485          (active (or (gnus-active group) (gnus-activate-group group)))
6486          (last (cdr active))
6487          first nlast unread)
6488     ;; If none are read, then all are unread.
6489     (if (not read)
6490         (setq first (car active))
6491       ;; If the range of read articles is a single range, then the
6492       ;; first unread article is the article after the last read
6493       ;; article.  Sounds logical, doesn't it?
6494       (if (and (not (listp (cdr read)))
6495                (or (< (car read) (car active))
6496                    (progn (setq read (list read))
6497                           nil)))
6498           (setq first (max (car active) (1+ (cdr read))))
6499         ;; `read' is a list of ranges.
6500         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6501                                   (caar read)))
6502                   1)
6503           (setq first (car active)))
6504         (while read
6505           (when first
6506             (push (cons first nlast) unread))
6507           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6508           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6509           (setq read (cdr read)))))
6510     ;; And add the last unread articles.
6511     (cond ((< first last)
6512            (push (cons first last) unread))
6513           ((= first last)
6514            (push first unread)))
6515     ;; Return the sequence of unread articles.
6516     (delq 0 (nreverse unread))))
6517
6518 ;; Various summary commands
6519
6520 (defun gnus-summary-select-article-buffer ()
6521   "Reconfigure windows to show article buffer."
6522   (interactive)
6523   (if (not (gnus-buffer-live-p gnus-article-buffer))
6524       (error "There is no article buffer for this summary buffer")
6525     (gnus-configure-windows 'article)
6526     (select-window (get-buffer-window gnus-article-buffer))))
6527
6528 (defun gnus-summary-universal-argument (arg)
6529   "Perform any operation on all articles that are process/prefixed."
6530   (interactive "P")
6531   (let ((articles (gnus-summary-work-articles arg))
6532         func article)
6533     (if (eq
6534          (setq
6535           func
6536           (key-binding
6537            (read-key-sequence
6538             (substitute-command-keys
6539              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6540          'undefined)
6541         (gnus-error 1 "Undefined key")
6542       (save-excursion
6543         (while articles
6544           (gnus-summary-goto-subject (setq article (pop articles)))
6545           (let (gnus-newsgroup-processable)
6546             (command-execute func))
6547           (gnus-summary-remove-process-mark article)))))
6548   (gnus-summary-position-point))
6549
6550 (defun gnus-summary-toggle-truncation (&optional arg)
6551   "Toggle truncation of summary lines.
6552 With ARG, turn line truncation on if ARG is positive."
6553   (interactive "P")
6554   (setq truncate-lines
6555         (if (null arg) (not truncate-lines)
6556           (> (prefix-numeric-value arg) 0)))
6557   (redraw-display))
6558
6559 (defun gnus-summary-find-for-reselect ()
6560   "Return the number of an article to stay on across a reselect.
6561 The current article is considered, then following articles, then previous
6562 articles.  An article is sought which is not cancelled and isn't a temporary
6563 insertion from another group.  If there's no such then return a dummy 0."
6564   (let (found)
6565     (dolist (rev '(nil t))
6566       (unless found      ; don't demand the reverse list if we don't need it
6567         (let ((data (gnus-data-find-list
6568                      (gnus-summary-article-number) (gnus-data-list rev))))
6569           (while (and data (not found))
6570             (if (and (< 0 (gnus-data-number (car data)))
6571                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6572                 (setq found (gnus-data-number (car data))))
6573             (setq data (cdr data))))))
6574     (or found 0)))
6575
6576 (defun gnus-summary-reselect-current-group (&optional all rescan)
6577   "Exit and then reselect the current newsgroup.
6578 The prefix argument ALL means to select all articles."
6579   (interactive "P")
6580   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6581     (error "Ephemeral groups can't be reselected"))
6582   (let ((current-subject (gnus-summary-find-for-reselect))
6583         (group gnus-newsgroup-name))
6584     (setq gnus-newsgroup-begin nil)
6585     (gnus-summary-exit nil 'leave-hidden)
6586     ;; We have to adjust the point of group mode buffer because
6587     ;; point was moved to the next unread newsgroup by exiting.
6588     (gnus-summary-jump-to-group group)
6589     (when rescan
6590       (save-excursion
6591         (save-window-excursion
6592           ;; Don't show group contents.
6593           (set-window-start (selected-window) (point-max))
6594           (gnus-group-get-new-news-this-group 1))))
6595     (gnus-group-read-group all t)
6596     (gnus-summary-goto-subject current-subject nil t)))
6597
6598 (defun gnus-summary-rescan-group (&optional all)
6599   "Exit the newsgroup, ask for new articles, and select the newsgroup."
6600   (interactive "P")
6601   (gnus-summary-reselect-current-group all t))
6602
6603 (defun gnus-summary-update-info (&optional non-destructive)
6604   (save-excursion
6605     (let ((group gnus-newsgroup-name))
6606       (when group
6607         (when gnus-newsgroup-kill-headers
6608           (setq gnus-newsgroup-killed
6609                 (gnus-compress-sequence
6610                  (gnus-sorted-union
6611                   (gnus-list-range-intersection
6612                    gnus-newsgroup-unselected gnus-newsgroup-killed)
6613                   gnus-newsgroup-unreads)
6614                  t)))
6615         (unless (listp (cdr gnus-newsgroup-killed))
6616           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
6617         (let ((headers gnus-newsgroup-headers))
6618           ;; Set the new ranges of read articles.
6619           (with-current-buffer gnus-group-buffer
6620             (gnus-undo-force-boundary))
6621           (gnus-update-read-articles
6622            group (gnus-sorted-union
6623                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
6624           ;; Set the current article marks.
6625           (let ((gnus-newsgroup-scored
6626                  (if (and (not gnus-save-score)
6627                           (not non-destructive))
6628                      nil
6629                    gnus-newsgroup-scored)))
6630             (save-excursion
6631               (gnus-update-marks)))
6632           ;; Do the cross-ref thing.
6633           (when gnus-use-cross-reference
6634             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
6635           ;; Do not switch windows but change the buffer to work.
6636           (set-buffer gnus-group-buffer)
6637           (unless (gnus-ephemeral-group-p group)
6638             (gnus-group-update-group group)))))))
6639
6640 (defun gnus-summary-save-newsrc (&optional force)
6641   "Save the current number of read/marked articles in the dribble buffer.
6642 The dribble buffer will then be saved.
6643 If FORCE (the prefix), also save the .newsrc file(s)."
6644   (interactive "P")
6645   (gnus-summary-update-info t)
6646   (if force
6647       (gnus-save-newsrc-file)
6648     (gnus-dribble-save)))
6649
6650 (defun gnus-summary-exit (&optional temporary leave-hidden)
6651   "Exit reading current newsgroup, and then return to group selection mode.
6652 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
6653   (interactive)
6654   (gnus-set-global-variables)
6655   (gnus-kill-save-kill-buffer)
6656   (gnus-async-halt-prefetch)
6657   (let* ((group gnus-newsgroup-name)
6658          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
6659          (gnus-group-is-exiting-p t)
6660          (mode major-mode)
6661          (group-point nil)
6662          (buf (current-buffer)))
6663     (unless quit-config
6664       ;; Do adaptive scoring, and possibly save score files.
6665       (when gnus-newsgroup-adaptive
6666         (gnus-score-adaptive))
6667       (when gnus-use-scoring
6668         (gnus-score-save)))
6669     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
6670     ;; If we have several article buffers, we kill them at exit.
6671     (unless gnus-single-article-buffer
6672       (gnus-kill-buffer gnus-original-article-buffer)
6673       (setq gnus-article-current nil))
6674     (when gnus-use-cache
6675       (gnus-cache-possibly-remove-articles)
6676       (gnus-cache-save-buffers))
6677     (gnus-async-prefetch-remove-group group)
6678     (when gnus-suppress-duplicates
6679       (gnus-dup-enter-articles))
6680     (when gnus-use-trees
6681       (gnus-tree-close group))
6682     (when gnus-use-cache
6683       (gnus-cache-write-active))
6684     ;; Remove entries for this group.
6685     (nnmail-purge-split-history (gnus-group-real-name group))
6686     ;; Make all changes in this group permanent.
6687     (unless quit-config
6688       (gnus-run-hooks 'gnus-exit-group-hook)
6689       (gnus-summary-update-info))
6690     (gnus-close-group group)
6691     ;; Make sure where we were, and go to next newsgroup.
6692     (set-buffer gnus-group-buffer)
6693     (unless quit-config
6694       (gnus-group-jump-to-group group))
6695     (gnus-run-hooks 'gnus-summary-exit-hook)
6696     (unless (or quit-config
6697                 ;; If this group has disappeared from the summary
6698                 ;; buffer, don't skip forwards.
6699                 (not (string= group (gnus-group-group-name))))
6700       (gnus-group-next-unread-group 1))
6701     (setq group-point (point))
6702     (if temporary
6703         nil                             ;Nothing to do.
6704       ;; If we have several article buffers, we kill them at exit.
6705       (unless gnus-single-article-buffer
6706         (gnus-kill-buffer gnus-article-buffer)
6707         (gnus-kill-buffer gnus-original-article-buffer)
6708         (setq gnus-article-current nil))
6709       (set-buffer buf)
6710       (if (not gnus-kill-summary-on-exit)
6711           (progn
6712             (gnus-deaden-summary)
6713             (setq mode nil))
6714         ;; We set all buffer-local variables to nil.  It is unclear why
6715         ;; this is needed, but if we don't, buffer-local variables are
6716         ;; not garbage-collected, it seems.  This would the lead to en
6717         ;; ever-growing Emacs.
6718         (gnus-summary-clear-local-variables)
6719         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6720           (gnus-summary-clear-local-variables))
6721         (when (get-buffer gnus-article-buffer)
6722           (bury-buffer gnus-article-buffer))
6723         ;; Return to group mode buffer.
6724         (when (eq mode 'gnus-summary-mode)
6725           (gnus-kill-buffer buf)))
6726       (setq gnus-current-select-method gnus-select-method)
6727       (set-buffer gnus-group-buffer)
6728       (if quit-config
6729           (gnus-handle-ephemeral-exit quit-config)
6730         (goto-char group-point)
6731         ;; If gnus-group-buffer is already displayed, make sure we also move
6732         ;; the cursor in the window that displays it.
6733         (let ((win (get-buffer-window (current-buffer) 0)))
6734           (if win (set-window-point win (point))))
6735         (unless leave-hidden
6736           (gnus-configure-windows 'group 'force))
6737         (unless (pos-visible-in-window-p)
6738           (forward-line (/ (static-if (featurep 'xemacs)
6739                                (window-displayed-height)
6740                              (1- (window-height)))
6741                            -2))
6742           (set-window-start (selected-window) (point))
6743           (goto-char group-point)))
6744       ;; Clear the current group name.
6745       (unless quit-config
6746         (setq gnus-newsgroup-name nil)))))
6747
6748 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
6749 (defun gnus-summary-exit-no-update (&optional no-questions)
6750   "Quit reading current newsgroup without updating read article info."
6751   (interactive)
6752   (let* ((group gnus-newsgroup-name)
6753          (gnus-group-is-exiting-p t)
6754          (gnus-group-is-exiting-without-update-p t)
6755          (quit-config (gnus-group-quit-config group)))
6756     (when (or no-questions
6757               gnus-expert-user
6758               (gnus-y-or-n-p "Discard changes to this group and exit? "))
6759       (gnus-async-halt-prefetch)
6760       (run-hooks 'gnus-summary-prepare-exit-hook)
6761       ;; If we have several article buffers, we kill them at exit.
6762       (unless gnus-single-article-buffer
6763         (gnus-kill-buffer gnus-article-buffer)
6764         (gnus-kill-buffer gnus-original-article-buffer)
6765         (setq gnus-article-current nil))
6766       (if (not gnus-kill-summary-on-exit)
6767           (gnus-deaden-summary)
6768         (gnus-close-group group)
6769         (gnus-summary-clear-local-variables)
6770         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
6771           (gnus-summary-clear-local-variables))
6772         (gnus-kill-buffer gnus-summary-buffer))
6773       (unless gnus-single-article-buffer
6774         (setq gnus-article-current nil))
6775       (when gnus-use-trees
6776         (gnus-tree-close group))
6777       (gnus-async-prefetch-remove-group group)
6778       (when (get-buffer gnus-article-buffer)
6779         (bury-buffer gnus-article-buffer))
6780       ;; Return to the group buffer.
6781       (gnus-configure-windows 'group 'force)
6782       ;; Clear the current group name.
6783       (setq gnus-newsgroup-name nil)
6784       (unless (gnus-ephemeral-group-p group)
6785         (gnus-group-update-group group))
6786       (when (equal (gnus-group-group-name) group)
6787         (gnus-group-next-unread-group 1))
6788       (when quit-config
6789         (gnus-handle-ephemeral-exit quit-config)))))
6790
6791 (defun gnus-handle-ephemeral-exit (quit-config)
6792   "Handle movement when leaving an ephemeral group.
6793 The state which existed when entering the ephemeral is reset."
6794   (if (not (buffer-name (car quit-config)))
6795       (gnus-configure-windows 'group 'force)
6796     (set-buffer (car quit-config))
6797     (cond ((eq major-mode 'gnus-summary-mode)
6798            (gnus-set-global-variables))
6799           ((eq major-mode 'gnus-article-mode)
6800            (save-excursion
6801              ;; The `gnus-summary-buffer' variable may point
6802              ;; to the old summary buffer when using a single
6803              ;; article buffer.
6804              (unless (gnus-buffer-live-p gnus-summary-buffer)
6805                (set-buffer gnus-group-buffer))
6806              (set-buffer gnus-summary-buffer)
6807              (gnus-set-global-variables))))
6808     (if (or (eq (cdr quit-config) 'article)
6809             (eq (cdr quit-config) 'pick))
6810         (progn
6811           ;; The current article may be from the ephemeral group
6812           ;; thus it is best that we reload this article
6813           ;;
6814           ;; If we're exiting from a large digest, this can be
6815           ;; extremely slow.  So, it's better not to reload it. -- jh.
6816           ;;(gnus-summary-show-article)
6817           (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
6818               (gnus-configure-windows 'pick 'force)
6819             (gnus-configure-windows (cdr quit-config) 'force)))
6820       (gnus-configure-windows (cdr quit-config) 'force))
6821     (when (eq major-mode 'gnus-summary-mode)
6822       (gnus-summary-next-subject 1 nil t)
6823       (gnus-summary-recenter)
6824       (gnus-summary-position-point))))
6825
6826 (defun gnus-summary-preview-mime-message ()
6827   "MIME decode and play this message."
6828   (interactive)
6829   (let ((gnus-break-pages nil)
6830         (gnus-show-mime t))
6831     (gnus-summary-select-article gnus-show-all-headers t))
6832   (let ((w (get-buffer-window gnus-article-buffer)))
6833     (when w
6834       (select-window (get-buffer-window gnus-article-buffer)))))
6835
6836 ;;; Dead summaries.
6837
6838 (defvar gnus-dead-summary-mode-map nil)
6839
6840 (unless gnus-dead-summary-mode-map
6841   (setq gnus-dead-summary-mode-map (make-keymap))
6842   (suppress-keymap gnus-dead-summary-mode-map)
6843   (substitute-key-definition
6844    'undefined 'gnus-summary-wake-up-the-dead gnus-dead-summary-mode-map)
6845   (dolist (key '("\C-d" "\r" "\177" [delete]))
6846     (define-key gnus-dead-summary-mode-map
6847       key 'gnus-summary-wake-up-the-dead))
6848   (dolist (key '("q" "Q"))
6849     (define-key gnus-dead-summary-mode-map key 'bury-buffer)))
6850
6851 (defvar gnus-dead-summary-mode nil
6852   "Minor mode for Gnus summary buffers.")
6853
6854 (defun gnus-dead-summary-mode (&optional arg)
6855   "Minor mode for Gnus summary buffers."
6856   (interactive "P")
6857   (when (eq major-mode 'gnus-summary-mode)
6858     (make-local-variable 'gnus-dead-summary-mode)
6859     (setq gnus-dead-summary-mode
6860           (if (null arg) (not gnus-dead-summary-mode)
6861             (> (prefix-numeric-value arg) 0)))
6862     (when gnus-dead-summary-mode
6863       (add-minor-mode
6864        'gnus-dead-summary-mode " Dead" gnus-dead-summary-mode-map))))
6865
6866 (defun gnus-deaden-summary ()
6867   "Make the current summary buffer into a dead summary buffer."
6868   ;; Kill any previous dead summary buffer.
6869   (when (and gnus-dead-summary
6870              (buffer-name gnus-dead-summary))
6871     (with-current-buffer gnus-dead-summary
6872       (when gnus-dead-summary-mode
6873         (kill-buffer (current-buffer)))))
6874   ;; Make this the current dead summary.
6875   (setq gnus-dead-summary (current-buffer))
6876   (gnus-dead-summary-mode 1)
6877   (let ((name (buffer-name)))
6878     (when (string-match "Summary" name)
6879       (rename-buffer
6880        (concat (substring name 0 (match-beginning 0)) "Dead "
6881                (substring name (match-beginning 0)))
6882        t)
6883       (bury-buffer))))
6884
6885 (defun gnus-kill-or-deaden-summary (buffer)
6886   "Kill or deaden the summary BUFFER."
6887   (save-excursion
6888     (when (and (buffer-name buffer)
6889                (not gnus-single-article-buffer))
6890       (with-current-buffer buffer
6891         (gnus-kill-buffer gnus-article-buffer)
6892         (gnus-kill-buffer gnus-original-article-buffer)))
6893     (cond
6894      ;; Kill the buffer.
6895      (gnus-kill-summary-on-exit
6896       (when (and gnus-use-trees
6897                  (gnus-buffer-exists-p buffer))
6898         (save-excursion
6899           (set-buffer buffer)
6900           (gnus-tree-close gnus-newsgroup-name)))
6901       (gnus-kill-buffer buffer))
6902      ;; Deaden the buffer.
6903      ((gnus-buffer-exists-p buffer)
6904       (save-excursion
6905         (set-buffer buffer)
6906         (gnus-deaden-summary))))))
6907
6908 (defun gnus-summary-wake-up-the-dead (&rest args)
6909   "Wake up the dead summary buffer."
6910   (interactive)
6911   (gnus-dead-summary-mode -1)
6912   (let ((name (buffer-name)))
6913     (when (string-match "Dead " name)
6914       (rename-buffer
6915        (concat (substring name 0 (match-beginning 0))
6916                (substring name (match-end 0)))
6917        t)))
6918   (gnus-message 3 "This dead summary is now alive again"))
6919
6920 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
6921 (defun gnus-summary-fetch-faq (&optional faq-dir)
6922   "Fetch the FAQ for the current group.
6923 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
6924 in."
6925   (interactive
6926    (list
6927     (when current-prefix-arg
6928       (completing-read
6929        "FAQ dir: " (and (listp gnus-group-faq-directory)
6930                         (mapcar 'list
6931                                 gnus-group-faq-directory))))))
6932   (let (gnus-faq-buffer)
6933     (when (setq gnus-faq-buffer
6934                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
6935       (gnus-configure-windows 'summary-faq))))
6936
6937 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
6938 (defun gnus-summary-describe-group (&optional force)
6939   "Describe the current newsgroup."
6940   (interactive "P")
6941   (gnus-group-describe-group force gnus-newsgroup-name))
6942
6943 (defun gnus-summary-describe-briefly ()
6944   "Describe summary mode commands briefly."
6945   (interactive)
6946   (gnus-message 6 (substitute-command-keys "\\<gnus-summary-mode-map>\\[gnus-summary-next-page]:Select  \\[gnus-summary-next-unread-article]:Forward  \\[gnus-summary-prev-unread-article]:Backward  \\[gnus-summary-exit]:Exit  \\[gnus-info-find-node]:Run Info        \\[gnus-summary-describe-briefly]:This help")))
6947
6948 ;; Walking around group mode buffer from summary mode.
6949
6950 (defun gnus-summary-next-group (&optional no-article target-group backward)
6951   "Exit current newsgroup and then select next unread newsgroup.
6952 If prefix argument NO-ARTICLE is non-nil, no article is selected
6953 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
6954 previous group instead."
6955   (interactive "P")
6956   ;; Stop pre-fetching.
6957   (gnus-async-halt-prefetch)
6958   (let ((current-group gnus-newsgroup-name)
6959         (current-buffer (current-buffer))
6960         entered)
6961     ;; First we semi-exit this group to update Xrefs and all variables.
6962     ;; We can't do a real exit, because the window conf must remain
6963     ;; the same in case the user is prompted for info, and we don't
6964     ;; want the window conf to change before that...
6965     (gnus-summary-exit t)
6966     (while (not entered)
6967       ;; Then we find what group we are supposed to enter.
6968       (set-buffer gnus-group-buffer)
6969       (gnus-group-jump-to-group current-group)
6970       (setq target-group
6971             (or target-group
6972                 (if (eq gnus-keep-same-level 'best)
6973                     (gnus-summary-best-group gnus-newsgroup-name)
6974                   (gnus-summary-search-group backward gnus-keep-same-level))))
6975       (if (not target-group)
6976           ;; There are no further groups, so we return to the group
6977           ;; buffer.
6978           (progn
6979             (gnus-message 5 "Returning to the group buffer")
6980             (setq entered t)
6981             (when (gnus-buffer-live-p current-buffer)
6982               (set-buffer current-buffer)
6983               (gnus-summary-exit))
6984             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
6985         ;; We try to enter the target group.
6986         (gnus-group-jump-to-group target-group)
6987         (let ((unreads (gnus-group-group-unread)))
6988           (if (and (or (eq t unreads)
6989                        (and unreads (not (zerop unreads))))
6990                    (gnus-summary-read-group
6991                     target-group nil no-article
6992                     (and (buffer-name current-buffer) current-buffer)
6993                     nil backward))
6994               (setq entered t)
6995             (setq current-group target-group
6996                   target-group nil)))))))
6997
6998 (defun gnus-summary-prev-group (&optional no-article)
6999   "Exit current newsgroup and then select previous unread newsgroup.
7000 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7001   (interactive "P")
7002   (gnus-summary-next-group no-article nil t))
7003
7004 ;; Walking around summary lines.
7005
7006 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7007   "Go to the first subject satisfying any non-nil constraint.
7008 If UNREAD is non-nil, the article should be unread.
7009 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7010 If UNSEEN is non-nil, the article should be unseen.
7011 Returns the article selected or nil if there are no matching articles."
7012   (interactive "P")
7013   (cond
7014    ;; Empty summary.
7015    ((null gnus-newsgroup-data)
7016     (gnus-message 3 "No articles in the group")
7017     nil)
7018    ;; Pick the first article.
7019    ((not (or unread undownloaded unseen))
7020     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7021     (gnus-data-number (car gnus-newsgroup-data)))
7022    ;; Find the first unread article.
7023    (t
7024     (let ((data gnus-newsgroup-data))
7025       (while (and data
7026                   (let ((num (gnus-data-number (car data))))
7027                     (or (memq num gnus-newsgroup-unfetched)
7028                         (not (or (and unread
7029                                       (memq num gnus-newsgroup-unreads))
7030                                  (and undownloaded
7031                                       (memq num gnus-newsgroup-undownloaded))
7032                                  (and unseen
7033                                       (memq num gnus-newsgroup-unseen)))))))
7034         (setq data (cdr data)))
7035       (prog1
7036           (if data
7037               (progn
7038                 (goto-char (gnus-data-pos (car data)))
7039                 (gnus-data-number (car data)))
7040             (gnus-message 3 "No more%s articles"
7041                           (let* ((r (when unread " unread"))
7042                                  (d (when undownloaded " undownloaded"))
7043                                  (s (when unseen " unseen"))
7044                                  (l (delq nil (list r d s))))
7045                             (cond ((= 3 (length l))
7046                                    (concat r "," d ", or" s))
7047                                   ((= 2 (length l))
7048                                    (concat (car l) ", or" (cadr l)))
7049                                   ((= 1 (length l))
7050                                    (car l))
7051                                   (t
7052                                    ""))))
7053             nil
7054             )
7055         (gnus-summary-position-point))))))
7056
7057 (defun gnus-summary-next-subject (n &optional unread dont-display)
7058   "Go to next N'th summary line.
7059 If N is negative, go to the previous N'th subject line.
7060 If UNREAD is non-nil, only unread articles are selected.
7061 The difference between N and the actual number of steps taken is
7062 returned."
7063   (interactive "p")
7064   (let ((backward (< n 0))
7065         (n (abs n)))
7066     (while (and (> n 0)
7067                 (if backward
7068                     (gnus-summary-find-prev unread)
7069                   (gnus-summary-find-next unread)))
7070       (unless (zerop (setq n (1- n)))
7071         (gnus-summary-show-thread)))
7072     (when (/= 0 n)
7073       (gnus-message 7 "No more%s articles"
7074                     (if unread " unread" "")))
7075     (unless dont-display
7076       (gnus-summary-recenter)
7077       (gnus-summary-position-point))
7078     n))
7079
7080 (defun gnus-summary-next-unread-subject (n)
7081   "Go to next N'th unread summary line."
7082   (interactive "p")
7083   (gnus-summary-next-subject n t))
7084
7085 (defun gnus-summary-prev-subject (n &optional unread)
7086   "Go to previous N'th summary line.
7087 If optional argument UNREAD is non-nil, only unread article is selected."
7088   (interactive "p")
7089   (gnus-summary-next-subject (- n) unread))
7090
7091 (defun gnus-summary-prev-unread-subject (n)
7092   "Go to previous N'th unread summary line."
7093   (interactive "p")
7094   (gnus-summary-next-subject (- n) t))
7095
7096 (defun gnus-summary-goto-subjects (articles)
7097   "Insert the subject header for ARTICLES in the current buffer."
7098   (save-excursion
7099     (dolist (article articles)
7100       (gnus-summary-goto-subject article t)))
7101   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7102   (gnus-summary-position-point))
7103
7104 (defun gnus-summary-goto-subject (article &optional force silent)
7105   "Go the subject line of ARTICLE.
7106 If FORCE, also allow jumping to articles not currently shown."
7107   (interactive "nArticle number: ")
7108   (unless (numberp article)
7109     (error "Article %s is not a number" article))
7110   (let ((b (point))
7111         (data (gnus-data-find article)))
7112     ;; We read in the article if we have to.
7113     (and (not data)
7114          force
7115          (gnus-summary-insert-subject
7116           article
7117           (if (or (numberp force) (vectorp force)) force)
7118           t)
7119          (setq data (gnus-data-find article)))
7120     (goto-char b)
7121     (if (not data)
7122         (progn
7123           (unless silent
7124             (gnus-message 3 "Can't find article %d" article))
7125           nil)
7126       (let ((pt (gnus-data-pos data)))
7127         (goto-char pt)
7128         (gnus-summary-set-article-display-arrow pt))
7129       (gnus-summary-position-point)
7130       article)))
7131
7132 ;; Walking around summary lines with displaying articles.
7133
7134 (defun gnus-summary-expand-window (&optional arg)
7135   "Make the summary buffer take up the entire Emacs frame.
7136 Given a prefix, will force an `article' buffer configuration."
7137   (interactive "P")
7138   (if arg
7139       (gnus-configure-windows 'article 'force)
7140     (gnus-configure-windows 'summary 'force)))
7141
7142 (defun gnus-summary-display-article (article &optional all-header)
7143   "Display ARTICLE in article buffer."
7144   (when (gnus-buffer-live-p gnus-article-buffer)
7145     (with-current-buffer gnus-article-buffer
7146       (set-buffer-multibyte t)))
7147   (gnus-set-global-variables)
7148   (when (gnus-buffer-live-p gnus-article-buffer)
7149     (with-current-buffer gnus-article-buffer
7150       (setq gnus-article-charset gnus-newsgroup-charset)
7151       (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7152       (set-buffer-multibyte t)))
7153   (if (null article)
7154       nil
7155     (prog1
7156         (if gnus-summary-display-article-function
7157             (funcall gnus-summary-display-article-function article all-header)
7158           (gnus-article-prepare article all-header))
7159       (with-current-buffer gnus-article-buffer
7160         (set (make-local-variable 'gnus-summary-search-article-matched-data)
7161              nil))
7162       (gnus-run-hooks 'gnus-select-article-hook)
7163       (when (and gnus-current-article
7164                  (not (zerop gnus-current-article)))
7165         (gnus-summary-goto-subject gnus-current-article))
7166       (gnus-summary-recenter)
7167       (when (and gnus-use-trees gnus-show-threads)
7168         (gnus-possibly-generate-tree article)
7169         (gnus-highlight-selected-tree article))
7170       ;; Successfully display article.
7171       (gnus-article-set-window-start
7172        (cdr (assq article gnus-newsgroup-bookmarks))))))
7173
7174 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7175   "Select the current article.
7176 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7177 non-nil, the article will be re-fetched even if it already present in
7178 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7179 be displayed."
7180   ;; Make sure we are in the summary buffer to work around bbdb bug.
7181   (unless (eq major-mode 'gnus-summary-mode)
7182     (set-buffer gnus-summary-buffer))
7183   (let ((article (or article (gnus-summary-article-number)))
7184         (all-headers (not (not all-headers))) ;Must be T or NIL.
7185         gnus-summary-display-article-function)
7186     (and (not pseudo)
7187          (gnus-summary-article-pseudo-p article)
7188          (error "This is a pseudo-article"))
7189     (save-excursion
7190       (set-buffer gnus-summary-buffer)
7191       (if (or (and gnus-single-article-buffer
7192                    (or (null gnus-current-article)
7193                        (null gnus-article-current)
7194                        (null (get-buffer gnus-article-buffer))
7195                        (not (eq article (cdr gnus-article-current)))
7196                        (not (equal (car gnus-article-current)
7197                                    gnus-newsgroup-name))))
7198               (and (not gnus-single-article-buffer)
7199                    (or (null gnus-current-article)
7200                        (not (eq gnus-current-article article))))
7201               force)
7202           ;; The requested article is different from the current article.
7203           (progn
7204             (gnus-summary-display-article article all-headers)
7205             (gnus-article-set-window-start
7206              (cdr (assq article gnus-newsgroup-bookmarks)))
7207             article)
7208         'old))))
7209
7210 (defun gnus-summary-force-verify-and-decrypt ()
7211   "Display buttons for signed/encrypted parts and verify/decrypt them."
7212   (interactive)
7213   (let ((mm-verify-option 'known)
7214         (mm-decrypt-option 'known)
7215         (gnus-article-emulate-mime t)
7216         (gnus-buttonized-mime-types (append (list "multipart/signed"
7217                                                   "multipart/encrypted")
7218                                             gnus-buttonized-mime-types)))
7219     (gnus-summary-select-article nil 'force)))
7220
7221 (defun gnus-summary-set-current-mark (&optional current-mark)
7222   "Obsolete function."
7223   nil)
7224
7225 (defun gnus-summary-next-article (&optional unread subject backward push)
7226   "Select the next article.
7227 If UNREAD, only unread articles are selected.
7228 If SUBJECT, only articles with SUBJECT are selected.
7229 If BACKWARD, the previous article is selected instead of the next."
7230   (interactive "P")
7231   (cond
7232    ;; Is there such an article?
7233    ((and (gnus-summary-search-forward unread subject backward)
7234          (or (gnus-summary-display-article (gnus-summary-article-number))
7235              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7236     (gnus-summary-position-point))
7237    ;; If not, we try the first unread, if that is wanted.
7238    ((and subject
7239          gnus-auto-select-same
7240          (gnus-summary-first-unread-article))
7241     (gnus-summary-position-point)
7242     (gnus-message 6 "Wrapped"))
7243    ;; Try to get next/previous article not displayed in this group.
7244    ((and gnus-auto-extend-newsgroup
7245          (not unread) (not subject))
7246     (gnus-summary-goto-article
7247      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7248      nil (count-lines (point-min) (point))))
7249    ;; Go to next/previous group.
7250    (t
7251     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7252       (gnus-summary-jump-to-group gnus-newsgroup-name))
7253     (let ((cmd last-command-char)
7254           (point
7255            (with-current-buffer gnus-group-buffer
7256              (point)))
7257           (group
7258            (if (eq gnus-keep-same-level 'best)
7259                (gnus-summary-best-group gnus-newsgroup-name)
7260              (gnus-summary-search-group backward gnus-keep-same-level))))
7261       ;; For some reason, the group window gets selected.  We change
7262       ;; it back.
7263       (select-window (get-buffer-window (current-buffer)))
7264       ;; Select next unread newsgroup automagically.
7265       (cond
7266        ((or (not gnus-auto-select-next)
7267             (not cmd))
7268         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7269        ((or (eq gnus-auto-select-next 'quietly)
7270             (and (eq gnus-auto-select-next 'slightly-quietly)
7271                  push)
7272             (and (eq gnus-auto-select-next 'almost-quietly)
7273                  (gnus-summary-last-article-p)))
7274         ;; Select quietly.
7275         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7276             (gnus-summary-exit)
7277           (gnus-message 7 "No more%s articles (%s)..."
7278                         (if unread " unread" "")
7279                         (if group (concat "selecting " group)
7280                           "exiting"))
7281           (gnus-summary-next-group nil group backward)))
7282        (t
7283         (when (gnus-key-press-event-p last-input-event)
7284           (gnus-summary-walk-group-buffer
7285            gnus-newsgroup-name cmd unread backward point))))))))
7286
7287 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7288   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7289                       (?\C-p (gnus-group-prev-unread-group 1))))
7290         (cursor-in-echo-area t)
7291         keve key group ended prompt)
7292     (save-excursion
7293       (set-buffer gnus-group-buffer)
7294       (goto-char start)
7295       (setq group
7296             (if (eq gnus-keep-same-level 'best)
7297                 (gnus-summary-best-group gnus-newsgroup-name)
7298               (gnus-summary-search-group backward gnus-keep-same-level))))
7299     (while (not ended)
7300       (setq prompt
7301             (format
7302              "No more%s articles%s " (if unread " unread" "")
7303              (if (and group
7304                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7305                  (format " (Type %s for %s [%s])"
7306                          (single-key-description cmd)
7307                          (gnus-group-decoded-name group)
7308                          (gnus-group-unread group))
7309                (format " (Type %s to exit %s)"
7310                        (single-key-description cmd)
7311                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7312       ;; Confirm auto selection.
7313       (setq key (car (setq keve (gnus-read-event-char prompt)))
7314             ended t)
7315       (cond
7316        ((assq key keystrokes)
7317         (let ((obuf (current-buffer)))
7318           (switch-to-buffer gnus-group-buffer)
7319           (when group
7320             (gnus-group-jump-to-group group))
7321           (eval (cadr (assq key keystrokes)))
7322           (setq group (gnus-group-group-name))
7323           (switch-to-buffer obuf))
7324         (setq ended nil))
7325        ((equal key cmd)
7326         (if (or (not group)
7327                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7328             (gnus-summary-exit)
7329           (gnus-summary-next-group nil group backward)))
7330        (t
7331         (push (cdr keve) unread-command-events))))))
7332
7333 (defun gnus-summary-next-unread-article ()
7334   "Select unread article after current one."
7335   (interactive)
7336   (gnus-summary-next-article
7337    (or (not (eq gnus-summary-goto-unread 'never))
7338        (gnus-summary-last-article-p (gnus-summary-article-number)))
7339    (and gnus-auto-select-same
7340         (gnus-summary-article-subject))))
7341
7342 (defun gnus-summary-prev-article (&optional unread subject)
7343   "Select the article after the current one.
7344 If UNREAD is non-nil, only unread articles are selected."
7345   (interactive "P")
7346   (gnus-summary-next-article unread subject t))
7347
7348 (defun gnus-summary-prev-unread-article ()
7349   "Select unread article before current one."
7350   (interactive)
7351   (gnus-summary-prev-article
7352    (or (not (eq gnus-summary-goto-unread 'never))
7353        (gnus-summary-first-article-p (gnus-summary-article-number)))
7354    (and gnus-auto-select-same
7355         (gnus-summary-article-subject))))
7356
7357 (defun gnus-summary-next-page (&optional lines circular stop)
7358   "Show next page of the selected article.
7359 If at the end of the current article, select the next article.
7360 LINES says how many lines should be scrolled up.
7361
7362 If CIRCULAR is non-nil, go to the start of the article instead of
7363 selecting the next article when reaching the end of the current
7364 article.
7365
7366 If STOP is non-nil, just stop when reaching the end of the message.
7367
7368 Also see the variable `gnus-article-skip-boring'."
7369   (interactive "P")
7370   (setq gnus-summary-buffer (current-buffer))
7371   (gnus-set-global-variables)
7372   (let ((article (gnus-summary-article-number))
7373         (article-window (get-buffer-window gnus-article-buffer t))
7374         endp)
7375     ;; If the buffer is empty, we have no article.
7376     (unless article
7377       (error "No article to select"))
7378     (gnus-configure-windows 'article)
7379     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7380         (if (and (eq gnus-summary-goto-unread 'never)
7381                  (not (gnus-summary-last-article-p article)))
7382             (gnus-summary-next-article)
7383           (gnus-summary-next-unread-article))
7384       (if (or (null gnus-current-article)
7385               (null gnus-article-current)
7386               (/= article (cdr gnus-article-current))
7387               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7388           ;; Selected subject is different from current article's.
7389           (gnus-summary-display-article article)
7390         (when article-window
7391           (gnus-eval-in-buffer-window gnus-article-buffer
7392             (setq endp (or (gnus-article-next-page lines)
7393                            (gnus-article-only-boring-p))))
7394           (when endp
7395             (cond (stop
7396                    (gnus-message 3 "End of message"))
7397                   (circular
7398                    (gnus-summary-beginning-of-article))
7399                   (lines
7400                    (gnus-message 3 "End of message"))
7401                   ((null lines)
7402                    (if (and (eq gnus-summary-goto-unread 'never)
7403                             (not (gnus-summary-last-article-p article)))
7404                        (gnus-summary-next-article)
7405                      (gnus-summary-next-unread-article))))))))
7406     (gnus-summary-recenter)
7407     (gnus-summary-position-point)))
7408
7409 (defun gnus-summary-prev-page (&optional lines move)
7410   "Show previous page of selected article.
7411 Argument LINES specifies lines to be scrolled down.
7412 If MOVE, move to the previous unread article if point is at
7413 the beginning of the buffer."
7414   (interactive "P")
7415   (let ((article (gnus-summary-article-number))
7416         (article-window (get-buffer-window gnus-article-buffer t))
7417         endp)
7418     (gnus-configure-windows 'article)
7419     (if (or (null gnus-current-article)
7420             (null gnus-article-current)
7421             (/= article (cdr gnus-article-current))
7422             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7423         ;; Selected subject is different from current article's.
7424         (gnus-summary-display-article article)
7425       (gnus-summary-recenter)
7426       (when article-window
7427         (gnus-eval-in-buffer-window gnus-article-buffer
7428           (setq endp (gnus-article-prev-page lines)))
7429         (when (and move endp)
7430           (cond (lines
7431                  (gnus-message 3 "Beginning of message"))
7432                 ((null lines)
7433                  (if (and (eq gnus-summary-goto-unread 'never)
7434                           (not (gnus-summary-first-article-p article)))
7435                      (gnus-summary-prev-article)
7436                    (gnus-summary-prev-unread-article))))))))
7437   (gnus-summary-position-point))
7438
7439 (defun gnus-summary-prev-page-or-article (&optional lines)
7440   "Show previous page of selected article.
7441 Argument LINES specifies lines to be scrolled down.
7442 If at the beginning of the article, go to the next article."
7443   (interactive "P")
7444   (gnus-summary-prev-page lines t))
7445
7446 (defun gnus-summary-scroll-up (lines)
7447   "Scroll up (or down) one line current article.
7448 Argument LINES specifies lines to be scrolled up (or down if negative)."
7449   (interactive "p")
7450   (gnus-configure-windows 'article)
7451   (gnus-summary-show-thread)
7452   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7453     (gnus-eval-in-buffer-window gnus-article-buffer
7454       (cond ((> lines 0)
7455              (when (gnus-article-next-page lines)
7456                (gnus-message 3 "End of message")))
7457             ((< lines 0)
7458              (gnus-article-prev-page (- lines))))))
7459   (gnus-summary-recenter)
7460   (gnus-summary-position-point))
7461
7462 (defun gnus-summary-scroll-down (lines)
7463   "Scroll down (or up) one line current article.
7464 Argument LINES specifies lines to be scrolled down (or up if negative)."
7465   (interactive "p")
7466   (gnus-summary-scroll-up (- lines)))
7467
7468 (defun gnus-summary-next-same-subject ()
7469   "Select next article which has the same subject as current one."
7470   (interactive)
7471   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7472
7473 (defun gnus-summary-prev-same-subject ()
7474   "Select previous article which has the same subject as current one."
7475   (interactive)
7476   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7477
7478 (defun gnus-summary-next-unread-same-subject ()
7479   "Select next unread article which has the same subject as current one."
7480   (interactive)
7481   (gnus-summary-next-article t (gnus-summary-article-subject)))
7482
7483 (defun gnus-summary-prev-unread-same-subject ()
7484   "Select previous unread article which has the same subject as current one."
7485   (interactive)
7486   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7487
7488 (defun gnus-summary-first-unread-article ()
7489   "Select the first unread article.
7490 Return nil if there are no unread articles."
7491   (interactive)
7492   (prog1
7493       (when (gnus-summary-first-subject t)
7494         (gnus-summary-show-thread)
7495         (gnus-summary-first-subject t)
7496         (gnus-summary-display-article (gnus-summary-article-number)))
7497     (gnus-summary-position-point)))
7498
7499 (defun gnus-summary-first-unread-subject ()
7500   "Place the point on the subject line of the first unread article.
7501 Return nil if there are no unread articles."
7502   (interactive)
7503   (prog1
7504       (when (gnus-summary-first-subject t)
7505         (gnus-summary-show-thread)
7506         (gnus-summary-first-subject t))
7507     (gnus-summary-position-point)))
7508
7509 (defun gnus-summary-first-unseen-subject ()
7510   "Place the point on the subject line of the first unseen article.
7511 Return nil if there are no unseen articles."
7512   (interactive)
7513   (prog1
7514       (when (gnus-summary-first-subject nil nil t)
7515         (gnus-summary-show-thread)
7516         (gnus-summary-first-subject nil nil t))
7517     (gnus-summary-position-point)))
7518
7519 (defun gnus-summary-first-unseen-or-unread-subject ()
7520   "Place the point on the subject line of the first unseen article or,
7521 if all article have been seen, on the subject line of the first unread
7522 article."
7523   (interactive)
7524   (prog1
7525       (unless (when (gnus-summary-first-subject nil nil t)
7526                 (gnus-summary-show-thread)
7527                 (gnus-summary-first-subject nil nil t))
7528         (when (gnus-summary-first-subject t)
7529           (gnus-summary-show-thread)
7530           (gnus-summary-first-subject t)))
7531     (gnus-summary-position-point)))
7532
7533 (defun gnus-summary-first-article ()
7534   "Select the first article.
7535 Return nil if there are no articles."
7536   (interactive)
7537   (prog1
7538       (when (gnus-summary-first-subject)
7539         (gnus-summary-show-thread)
7540         (gnus-summary-first-subject)
7541         (gnus-summary-display-article (gnus-summary-article-number)))
7542     (gnus-summary-position-point)))
7543
7544 (defun gnus-summary-best-unread-article (&optional arg)
7545   "Select the unread article with the highest score.
7546 If given a prefix argument, select the next unread article that has a
7547 score higher than the default score."
7548   (interactive "P")
7549   (let ((article (if arg
7550                      (gnus-summary-better-unread-subject)
7551                    (gnus-summary-best-unread-subject))))
7552     (if article
7553         (gnus-summary-goto-article article)
7554       (error "No unread articles"))))
7555
7556 (defun gnus-summary-best-unread-subject ()
7557   "Select the unread subject with the highest score."
7558   (interactive)
7559   (let ((best -1000000)
7560         (data gnus-newsgroup-data)
7561         article score)
7562     (while data
7563       (and (gnus-data-unread-p (car data))
7564            (> (setq score
7565                     (gnus-summary-article-score (gnus-data-number (car data))))
7566               best)
7567            (setq best score
7568                  article (gnus-data-number (car data))))
7569       (setq data (cdr data)))
7570     (when article
7571       (gnus-summary-goto-subject article))
7572     (gnus-summary-position-point)
7573     article))
7574
7575 (defun gnus-summary-better-unread-subject ()
7576   "Select the first unread subject that has a score over the default score."
7577   (interactive)
7578   (let ((data gnus-newsgroup-data)
7579         article score)
7580     (while (and (setq article (gnus-data-number (car data)))
7581                 (or (gnus-data-read-p (car data))
7582                     (not (> (gnus-summary-article-score article)
7583                             gnus-summary-default-score))))
7584       (setq data (cdr data)))
7585     (when article
7586       (gnus-summary-goto-subject article))
7587     (gnus-summary-position-point)
7588     article))
7589
7590 (defun gnus-summary-last-subject ()
7591   "Go to the last displayed subject line in the group."
7592   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7593     (when article
7594       (gnus-summary-goto-subject article))))
7595
7596 (defun gnus-summary-goto-article (article &optional all-headers force)
7597   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7598 If ALL-HEADERS is non-nil, no header lines are hidden.
7599 If FORCE, go to the article even if it isn't displayed.  If FORCE
7600 is a number, it is the line the article is to be displayed on."
7601   (interactive
7602    (list
7603     (completing-read
7604      "Article number or Message-ID: "
7605      (mapcar (lambda (number) (list (int-to-string number)))
7606              gnus-newsgroup-limit))
7607     current-prefix-arg
7608     t))
7609   (prog1
7610       (if (and (stringp article)
7611                (string-match "@\\|%40" article))
7612           (gnus-summary-refer-article article)
7613         (when (stringp article)
7614           (setq article (string-to-number article)))
7615         (if (gnus-summary-goto-subject article force)
7616             (gnus-summary-display-article article all-headers)
7617           (gnus-message 4 "Couldn't go to article %s" article) nil))
7618     (gnus-summary-position-point)))
7619
7620 (defun gnus-summary-goto-last-article ()
7621   "Go to the previously read article."
7622   (interactive)
7623   (prog1
7624       (when gnus-last-article
7625         (gnus-summary-goto-article gnus-last-article nil t))
7626     (gnus-summary-position-point)))
7627
7628 (defun gnus-summary-pop-article (number)
7629   "Pop one article off the history and go to the previous.
7630 NUMBER articles will be popped off."
7631   (interactive "p")
7632   (let (to)
7633     (setq gnus-newsgroup-history
7634           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
7635     (if to
7636         (gnus-summary-goto-article (car to) nil t)
7637       (error "Article history empty")))
7638   (gnus-summary-position-point))
7639
7640 ;; Summary commands and functions for limiting the summary buffer.
7641
7642 (defun gnus-summary-limit-to-articles (n)
7643   "Limit the summary buffer to the next N articles.
7644 If not given a prefix, use the process marked articles instead."
7645   (interactive "P")
7646   (prog1
7647       (let ((articles (gnus-summary-work-articles n)))
7648         (setq gnus-newsgroup-processable nil)
7649         (gnus-summary-limit articles))
7650     (gnus-summary-position-point)))
7651
7652 (defun gnus-summary-pop-limit (&optional total)
7653   "Restore the previous limit.
7654 If given a prefix, remove all limits."
7655   (interactive "P")
7656   (when total
7657     (setq gnus-newsgroup-limits
7658           (list (mapcar (lambda (h) (mail-header-number h))
7659                         gnus-newsgroup-headers))))
7660   (unless gnus-newsgroup-limits
7661     (error "No limit to pop"))
7662   (prog1
7663       (gnus-summary-limit nil 'pop)
7664     (gnus-summary-position-point)))
7665
7666 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
7667   "Limit the summary buffer to articles that have subjects that match a regexp.
7668 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
7669   (interactive
7670    (list (read-string (if current-prefix-arg
7671                           "Exclude subject (regexp): "
7672                         "Limit to subject (regexp): "))
7673          nil current-prefix-arg))
7674   (unless header
7675     (setq header "subject"))
7676   (when (not (equal "" subject))
7677     (prog1
7678         (let ((articles (gnus-summary-find-matching
7679                          (or header "subject") subject 'all nil nil
7680                          not-matching)))
7681           (unless articles
7682             (error "Found no matches for \"%s\"" subject))
7683           (gnus-summary-limit articles))
7684       (gnus-summary-position-point))))
7685
7686 (defun gnus-summary-limit-to-author (from &optional not-matching)
7687   "Limit the summary buffer to articles that have authors that match a regexp.
7688 If NOT-MATCHING, excluding articles that have authors that match a regexp."
7689   (interactive
7690    (list (read-string (if current-prefix-arg
7691                           "Exclude author (regexp): "
7692                         "Limit to author (regexp): "))
7693          current-prefix-arg))
7694   (gnus-summary-limit-to-subject from "from" not-matching))
7695
7696 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
7697   "Limit the summary buffer to articles with the given RECIPIENT.
7698
7699 If NOT-MATCHING, exclude RECIPIENT.
7700
7701 To and Cc headers are checked.  You need to include them in
7702 `nnmail-extra-headers'."
7703   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
7704   (interactive
7705    (list (read-string (format "%s recipient (regexp): "
7706                               (if current-prefix-arg "Exclude" "Limit to")))
7707          current-prefix-arg))
7708   (when (not (equal "" recipient))
7709     (prog1 (let* ((to
7710                    (if (memq 'To nnmail-extra-headers)
7711                        (gnus-summary-find-matching
7712                         (cons 'extra 'To) recipient 'all nil nil
7713                         not-matching)
7714                      (gnus-message
7715                       1 "`To' isn't present in `nnmail-extra-headers'")
7716                      (sit-for 1)
7717                      nil))
7718                   (cc
7719                    (if (memq 'Cc nnmail-extra-headers)
7720                        (gnus-summary-find-matching
7721                         (cons 'extra 'Cc) recipient 'all nil nil
7722                         not-matching)
7723                      (gnus-message
7724                       1 "`Cc' isn't present in `nnmail-extra-headers'")
7725                      (sit-for 1)
7726                      nil))
7727                   (articles
7728                    (if not-matching
7729                        ;; We need the numbers that are in both lists:
7730                        (mapcar (lambda (a)
7731                                  (and (memq a to) a))
7732                                cc)
7733                      (nconc to cc))))
7734              (unless articles
7735                (error "Found no matches for \"%s\"" recipient))
7736              (gnus-summary-limit articles))
7737       (gnus-summary-position-point))))
7738
7739 (defun gnus-summary-limit-to-age (age &optional younger-p)
7740   "Limit the summary buffer to articles that are older than (or equal) AGE days.
7741 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
7742 articles that are younger than AGE days."
7743   (interactive
7744    (let ((younger current-prefix-arg)
7745          (days-got nil)
7746          days)
7747      (while (not days-got)
7748        (setq days (if younger
7749                       (read-string "Limit to articles younger than (in days, older when negative): ")
7750                     (read-string
7751                      "Limit to articles older than (in days, younger when negative): ")))
7752        (when (> (length days) 0)
7753          (setq days (read days)))
7754        (if (numberp days)
7755            (progn
7756              (setq days-got t)
7757              (when (< days 0)
7758                (setq younger (not younger))
7759                (setq days (* days -1))))
7760          (message "Please enter a number.")
7761          (sleep-for 1)))
7762      (list days younger)))
7763   (prog1
7764       (let ((data gnus-newsgroup-data)
7765             (cutoff (days-to-time age))
7766             articles d date is-younger)
7767         (while (setq d (pop data))
7768           (when (and (vectorp (gnus-data-header d))
7769                      (setq date (mail-header-date (gnus-data-header d))))
7770             (setq is-younger (time-less-p
7771                               (time-since (condition-case ()
7772                                               (date-to-time date)
7773                                             (error '(0 0))))
7774                               cutoff))
7775             (when (if younger-p
7776                       is-younger
7777                     (not is-younger))
7778               (push (gnus-data-number d) articles))))
7779         (gnus-summary-limit (nreverse articles)))
7780     (gnus-summary-position-point)))
7781
7782 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
7783   "Limit the summary buffer to articles that match an 'extra' header."
7784   (interactive
7785    (let ((header
7786           (intern
7787            (gnus-completing-read-with-default
7788             (symbol-name (car gnus-extra-headers))
7789             (if current-prefix-arg
7790                 "Exclude extra header:"
7791               "Limit extra header:")
7792             (mapcar (lambda (x)
7793                       (cons (symbol-name x) x))
7794                     gnus-extra-headers)
7795             nil
7796             t))))
7797      (list header
7798            (read-string (format "%s header %s (regexp): "
7799                                 (if current-prefix-arg "Exclude" "Limit to")
7800                                 header))
7801            current-prefix-arg)))
7802   (when (not (equal "" regexp))
7803     (prog1
7804         (let ((articles (gnus-summary-find-matching
7805                          (cons 'extra header) regexp 'all nil nil
7806                          not-matching)))
7807           (unless articles
7808             (error "Found no matches for \"%s\"" regexp))
7809           (gnus-summary-limit articles))
7810       (gnus-summary-position-point))))
7811
7812 (defun gnus-summary-limit-to-display-predicate ()
7813   "Limit the summary buffer to the predicated in the `display' group parameter."
7814   (interactive)
7815   (unless gnus-newsgroup-display
7816     (error "There is no `display' group parameter"))
7817   (let (articles)
7818     (dolist (number gnus-newsgroup-articles)
7819       (when (funcall gnus-newsgroup-display)
7820         (push number articles)))
7821     (gnus-summary-limit articles))
7822   (gnus-summary-position-point))
7823
7824 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7825 (make-obsolete
7826  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
7827
7828 (defun gnus-summary-limit-to-unread (&optional all)
7829   "Limit the summary buffer to articles that are not marked as read.
7830 If ALL is non-nil, limit strictly to unread articles."
7831   (interactive "P")
7832   (if all
7833       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
7834     (gnus-summary-limit-to-marks
7835      ;; Concat all the marks that say that an article is read and have
7836      ;; those removed.
7837      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
7838            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
7839            gnus-low-score-mark gnus-expirable-mark
7840            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
7841            gnus-duplicate-mark gnus-souped-mark)
7842      'reverse)))
7843
7844 (defun gnus-summary-limit-to-replied (&optional unreplied)
7845   "Limit the summary buffer to replied articles.
7846 If UNREPLIED (the prefix), limit to unreplied articles."
7847   (interactive "P")
7848   (if unreplied
7849       (gnus-summary-limit
7850        (gnus-set-difference gnus-newsgroup-articles
7851         gnus-newsgroup-replied))
7852     (gnus-summary-limit gnus-newsgroup-replied))
7853   (gnus-summary-position-point))
7854
7855 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
7856 (make-obsolete 'gnus-summary-delete-marked-with
7857                'gnus-summary-limit-exclude-marks)
7858
7859 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
7860   "Exclude articles that are marked with MARKS (e.g. \"DK\").
7861 If REVERSE, limit the summary buffer to articles that are marked
7862 with MARKS.  MARKS can either be a string of marks or a list of marks.
7863 Returns how many articles were removed."
7864   (interactive "sMarks: ")
7865   (gnus-summary-limit-to-marks marks t))
7866
7867 (defun gnus-summary-limit-to-marks (marks &optional reverse)
7868   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
7869 If REVERSE (the prefix), limit the summary buffer to articles that are
7870 not marked with MARKS.  MARKS can either be a string of marks or a
7871 list of marks.
7872 Returns how many articles were removed."
7873   (interactive "sMarks: \nP")
7874   (prog1
7875       (let ((data gnus-newsgroup-data)
7876             (marks (if (listp marks) marks
7877                      (append marks nil))) ; Transform to list.
7878             articles)
7879         (while data
7880           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
7881                   (memq (gnus-data-mark (car data)) marks))
7882             (push (gnus-data-number (car data)) articles))
7883           (setq data (cdr data)))
7884         (gnus-summary-limit articles))
7885     (gnus-summary-position-point)))
7886
7887 (defun gnus-summary-limit-to-score (score)
7888   "Limit to articles with score at or above SCORE."
7889   (interactive "NLimit to articles with score of at least: ")
7890   (let ((data gnus-newsgroup-data)
7891         articles)
7892     (while data
7893       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
7894                 score)
7895         (push (gnus-data-number (car data)) articles))
7896       (setq data (cdr data)))
7897     (prog1
7898         (gnus-summary-limit articles)
7899       (gnus-summary-position-point))))
7900
7901 (defun gnus-summary-limit-to-unseen ()
7902   "Limit to unseen articles."
7903   (interactive)
7904   (prog1
7905       (gnus-summary-limit gnus-newsgroup-unseen)
7906     (gnus-summary-position-point)))
7907
7908 (defun gnus-summary-limit-include-thread (id)
7909   "Display all the hidden articles that is in the thread with ID in it.
7910 When called interactively, ID is the Message-ID of the current
7911 article."
7912   (interactive (list (mail-header-id (gnus-summary-article-header))))
7913   (let ((articles (gnus-articles-in-thread
7914                    (gnus-id-to-thread (gnus-root-id id)))))
7915     (prog1
7916         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7917       (gnus-summary-limit-include-matching-articles
7918        "subject"
7919        (regexp-quote (gnus-simplify-subject-re
7920                       (mail-header-subject (gnus-id-to-header id)))))
7921       (gnus-summary-position-point))))
7922
7923 (defun gnus-summary-limit-include-matching-articles (header regexp)
7924   "Display all the hidden articles that have HEADERs that match REGEXP."
7925   (interactive (list (read-string "Match on header: ")
7926                      (read-string "Regexp: ")))
7927   (let ((articles (gnus-find-matching-articles header regexp)))
7928     (prog1
7929         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
7930       (gnus-summary-position-point))))
7931
7932 (defun gnus-summary-insert-dormant-articles ()
7933   "Insert all the dormant articles for this group into the current buffer."
7934   (interactive)
7935   (let ((gnus-verbose (max 6 gnus-verbose)))
7936     (if (not gnus-newsgroup-dormant)
7937         (gnus-message 3 "No cached articles for this group")
7938       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
7939
7940 (defun gnus-summary-limit-include-dormant ()
7941   "Display all the hidden articles that are marked as dormant.
7942 Note that this command only works on a subset of the articles currently
7943 fetched for this group."
7944   (interactive)
7945   (unless gnus-newsgroup-dormant
7946     (error "There are no dormant articles in this group"))
7947   (prog1
7948       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
7949     (gnus-summary-position-point)))
7950
7951 (defun gnus-summary-limit-exclude-dormant ()
7952   "Hide all dormant articles."
7953   (interactive)
7954   (prog1
7955       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
7956     (gnus-summary-position-point)))
7957
7958 (defun gnus-summary-limit-exclude-childless-dormant ()
7959   "Hide all dormant articles that have no children."
7960   (interactive)
7961   (let ((data (gnus-data-list t))
7962         articles d children)
7963     ;; Find all articles that are either not dormant or have
7964     ;; children.
7965     (while (setq d (pop data))
7966       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
7967                 (and (setq children
7968                            (gnus-article-children (gnus-data-number d)))
7969                      (let (found)
7970                        (while children
7971                          (when (memq (car children) articles)
7972                            (setq children nil
7973                                  found t))
7974                          (pop children))
7975                        found)))
7976         (push (gnus-data-number d) articles)))
7977     ;; Do the limiting.
7978     (prog1
7979         (gnus-summary-limit articles)
7980       (gnus-summary-position-point))))
7981
7982 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
7983   "Mark all unread excluded articles as read.
7984 If ALL, mark even excluded ticked and dormants as read."
7985   (interactive "P")
7986   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
7987   (let ((articles (gnus-sorted-ndifference
7988                    (sort
7989                     (mapcar (lambda (h) (mail-header-number h))
7990                             gnus-newsgroup-headers)
7991                     '<)
7992                    gnus-newsgroup-limit))
7993         article)
7994     (setq gnus-newsgroup-unreads
7995           (gnus-sorted-intersection gnus-newsgroup-unreads
7996                                     gnus-newsgroup-limit))
7997     (if all
7998         (setq gnus-newsgroup-dormant nil
7999               gnus-newsgroup-marked nil
8000               gnus-newsgroup-reads
8001               (nconc
8002                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8003                gnus-newsgroup-reads))
8004       (while (setq article (pop articles))
8005         (unless (or (memq article gnus-newsgroup-dormant)
8006                     (memq article gnus-newsgroup-marked))
8007           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8008
8009 (defun gnus-summary-limit (articles &optional pop)
8010   (if pop
8011       ;; We pop the previous limit off the stack and use that.
8012       (setq articles (car gnus-newsgroup-limits)
8013             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8014     ;; We use the new limit, so we push the old limit on the stack.
8015     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8016   ;; Set the limit.
8017   (setq gnus-newsgroup-limit articles)
8018   (let ((total (length gnus-newsgroup-data))
8019         (data (gnus-data-find-list (gnus-summary-article-number)))
8020         (gnus-summary-mark-below nil)   ; Inhibit this.
8021         found)
8022     ;; This will do all the work of generating the new summary buffer
8023     ;; according to the new limit.
8024     (gnus-summary-prepare)
8025     ;; Hide any threads, possibly.
8026     (gnus-summary-maybe-hide-threads)
8027     ;; Try to return to the article you were at, or one in the
8028     ;; neighborhood.
8029     (when data
8030       ;; We try to find some article after the current one.
8031       (while data
8032         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8033           (setq data nil
8034                 found t))
8035         (setq data (cdr data))))
8036     (unless found
8037       ;; If there is no data, that means that we were after the last
8038       ;; article.  The same goes when we can't find any articles
8039       ;; after the current one.
8040       (goto-char (point-max))
8041       (gnus-summary-find-prev))
8042     (gnus-set-mode-line 'summary)
8043     ;; We return how many articles were removed from the summary
8044     ;; buffer as a result of the new limit.
8045     (- total (length gnus-newsgroup-data))))
8046
8047 (defsubst gnus-invisible-cut-children (threads)
8048   (let ((num 0))
8049     (while threads
8050       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8051         (incf num))
8052       (pop threads))
8053     (< num 2)))
8054
8055 (defsubst gnus-cut-thread (thread)
8056   "Go forwards in the thread until we find an article that we want to display."
8057   (when (or (eq gnus-fetch-old-headers 'some)
8058             (eq gnus-fetch-old-headers 'invisible)
8059             (numberp gnus-fetch-old-headers)
8060             (eq gnus-build-sparse-threads 'some)
8061             (eq gnus-build-sparse-threads 'more))
8062     ;; Deal with old-fetched headers and sparse threads.
8063     (while (and
8064             thread
8065             (or
8066              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8067              (gnus-summary-article-ancient-p
8068               (mail-header-number (car thread))))
8069             (if (or (<= (length (cdr thread)) 1)
8070                     (eq gnus-fetch-old-headers 'invisible))
8071                 (setq gnus-newsgroup-limit
8072                       (delq (mail-header-number (car thread))
8073                             gnus-newsgroup-limit)
8074                       thread (cadr thread))
8075               (when (gnus-invisible-cut-children (cdr thread))
8076                 (let ((th (cdr thread)))
8077                   (while th
8078                     (if (memq (mail-header-number (caar th))
8079                               gnus-newsgroup-limit)
8080                         (setq thread (car th)
8081                               th nil)
8082                       (setq th (cdr th))))))))))
8083   thread)
8084
8085 (defun gnus-cut-threads (threads)
8086   "Cut off all uninteresting articles from the beginning of THREADS."
8087   (when (or (eq gnus-fetch-old-headers 'some)
8088             (eq gnus-fetch-old-headers 'invisible)
8089             (numberp gnus-fetch-old-headers)
8090             (eq gnus-build-sparse-threads 'some)
8091             (eq gnus-build-sparse-threads 'more))
8092     (let ((th threads))
8093       (while th
8094         (setcar th (gnus-cut-thread (car th)))
8095         (setq th (cdr th)))))
8096   ;; Remove nixed out threads.
8097   (delq nil threads))
8098
8099 (defun gnus-summary-initial-limit (&optional show-if-empty)
8100   "Figure out what the initial limit is supposed to be on group entry.
8101 This entails weeding out unwanted dormants, low-scored articles,
8102 fetch-old-headers verbiage, and so on."
8103   ;; Most groups have nothing to remove.
8104   (if (or gnus-inhibit-limiting
8105           (and (null gnus-newsgroup-dormant)
8106                (eq gnus-newsgroup-display 'gnus-not-ignore)
8107                (not (eq gnus-fetch-old-headers 'some))
8108                (not (numberp gnus-fetch-old-headers))
8109                (not (eq gnus-fetch-old-headers 'invisible))
8110                (null gnus-summary-expunge-below)
8111                (not (eq gnus-build-sparse-threads 'some))
8112                (not (eq gnus-build-sparse-threads 'more))
8113                (null gnus-thread-expunge-below)
8114                (not gnus-use-nocem)))
8115       ()                                ; Do nothing.
8116     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8117     (setq gnus-newsgroup-limit nil)
8118     (mapatoms
8119      (lambda (node)
8120        (unless (car (symbol-value node))
8121          ;; These threads have no parents -- they are roots.
8122          (let ((nodes (cdr (symbol-value node)))
8123                thread)
8124            (while nodes
8125              (if (and gnus-thread-expunge-below
8126                       (< (gnus-thread-total-score (car nodes))
8127                          gnus-thread-expunge-below))
8128                  (gnus-expunge-thread (pop nodes))
8129                (setq thread (pop nodes))
8130                (gnus-summary-limit-children thread))))))
8131      gnus-newsgroup-dependencies)
8132     ;; If this limitation resulted in an empty group, we might
8133     ;; pop the previous limit and use it instead.
8134     (when (and (not gnus-newsgroup-limit)
8135                show-if-empty)
8136       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8137     gnus-newsgroup-limit))
8138
8139 (defun gnus-summary-limit-children (thread)
8140   "Return 1 if this subthread is visible and 0 if it is not."
8141   ;; First we get the number of visible children to this thread.  This
8142   ;; is done by recursing down the thread using this function, so this
8143   ;; will really go down to a leaf article first, before slowly
8144   ;; working its way up towards the root.
8145   (when thread
8146     (let* ((max-lisp-eval-depth 5000)
8147            (children
8148            (if (cdr thread)
8149                (apply '+ (mapcar 'gnus-summary-limit-children
8150                                  (cdr thread)))
8151              0))
8152           (number (mail-header-number (car thread)))
8153           score)
8154       (if (and
8155            (not (memq number gnus-newsgroup-marked))
8156            (or
8157             ;; If this article is dormant and has absolutely no visible
8158             ;; children, then this article isn't visible.
8159             (and (memq number gnus-newsgroup-dormant)
8160                  (zerop children))
8161             ;; If this is "fetch-old-headered" and there is no
8162             ;; visible children, then we don't want this article.
8163             (and (or (eq gnus-fetch-old-headers 'some)
8164                      (numberp gnus-fetch-old-headers))
8165                  (gnus-summary-article-ancient-p number)
8166                  (zerop children))
8167             ;; If this is "fetch-old-headered" and `invisible', then
8168             ;; we don't want this article.
8169             (and (eq gnus-fetch-old-headers 'invisible)
8170                  (gnus-summary-article-ancient-p number))
8171             ;; If this is a sparsely inserted article with no children,
8172             ;; we don't want it.
8173             (and (eq gnus-build-sparse-threads 'some)
8174                  (gnus-summary-article-sparse-p number)
8175                  (zerop children))
8176             ;; If we use expunging, and this article is really
8177             ;; low-scored, then we don't want this article.
8178             (when (and gnus-summary-expunge-below
8179                        (< (setq score
8180                                 (or (cdr (assq number gnus-newsgroup-scored))
8181                                     gnus-summary-default-score))
8182                           gnus-summary-expunge-below))
8183               ;; We increase the expunge-tally here, but that has
8184               ;; nothing to do with the limits, really.
8185               (incf gnus-newsgroup-expunged-tally)
8186               ;; We also mark as read here, if that's wanted.
8187               (when (and gnus-summary-mark-below
8188                          (< score gnus-summary-mark-below))
8189                 (setq gnus-newsgroup-unreads
8190                       (delq number gnus-newsgroup-unreads))
8191                 (if gnus-newsgroup-auto-expire
8192                     (push number gnus-newsgroup-expirable)
8193                   (push (cons number gnus-low-score-mark)
8194                         gnus-newsgroup-reads)))
8195               t)
8196             ;; Do the `display' group parameter.
8197             (and gnus-newsgroup-display
8198                  (not (funcall gnus-newsgroup-display)))
8199             ;; Check NoCeM things.
8200             (when (and gnus-use-nocem
8201                        (gnus-nocem-unwanted-article-p
8202                         (mail-header-id (car thread))))
8203               (setq gnus-newsgroup-unreads
8204                     (delq number gnus-newsgroup-unreads))
8205               t)))
8206           ;; Nope, invisible article.
8207           0
8208         ;; Ok, this article is to be visible, so we add it to the limit
8209         ;; and return 1.
8210         (push number gnus-newsgroup-limit)
8211         1))))
8212
8213 (defun gnus-expunge-thread (thread)
8214   "Mark all articles in THREAD as read."
8215   (let* ((number (mail-header-number (car thread))))
8216     (incf gnus-newsgroup-expunged-tally)
8217     ;; We also mark as read here, if that's wanted.
8218     (setq gnus-newsgroup-unreads
8219           (delq number gnus-newsgroup-unreads))
8220     (if gnus-newsgroup-auto-expire
8221         (push number gnus-newsgroup-expirable)
8222       (push (cons number gnus-low-score-mark)
8223             gnus-newsgroup-reads)))
8224   ;; Go recursively through all subthreads.
8225   (mapcar 'gnus-expunge-thread (cdr thread)))
8226
8227 ;; Summary article oriented commands
8228
8229 (defun gnus-summary-refer-parent-article (n)
8230   "Refer parent article N times.
8231 If N is negative, go to ancestor -N instead.
8232 The difference between N and the number of articles fetched is returned."
8233   (interactive "p")
8234   (let ((skip 1)
8235         error header ref)
8236     (when (not (natnump n))
8237       (setq skip (abs n)
8238             n 1))
8239     (while (and (> n 0)
8240                 (not error))
8241       (setq header (gnus-summary-article-header))
8242       (if (and (eq (mail-header-number header)
8243                    (cdr gnus-article-current))
8244                (equal gnus-newsgroup-name
8245                       (car gnus-article-current)))
8246           ;; If we try to find the parent of the currently
8247           ;; displayed article, then we take a look at the actual
8248           ;; References header, since this is slightly more
8249           ;; reliable than the References field we got from the
8250           ;; server.
8251           (save-excursion
8252             (set-buffer gnus-original-article-buffer)
8253             (nnheader-narrow-to-headers)
8254             (unless (setq ref (message-fetch-field "references"))
8255               (when (setq ref (message-fetch-field "in-reply-to"))
8256                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8257             (widen))
8258         (setq ref
8259               ;; It's not the current article, so we take a bet on
8260               ;; the value we got from the server.
8261               (mail-header-references header)))
8262       (if (and ref
8263                (not (equal ref "")))
8264           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8265             (gnus-message 1 "Couldn't find parent"))
8266         (gnus-message 1 "No references in article %d"
8267                       (gnus-summary-article-number))
8268         (setq error t))
8269       (decf n))
8270     (gnus-summary-position-point)
8271     n))
8272
8273 (defun gnus-summary-refer-references ()
8274   "Fetch all articles mentioned in the References header.
8275 Return the number of articles fetched."
8276   (interactive)
8277   (let ((ref (mail-header-references (gnus-summary-article-header)))
8278         (current (gnus-summary-article-number))
8279         (n 0))
8280     (if (or (not ref)
8281             (equal ref ""))
8282         (error "No References in the current article")
8283       ;; For each Message-ID in the References header...
8284       (while (string-match "<[^>]*>" ref)
8285         (incf n)
8286         ;; ... fetch that article.
8287         (gnus-summary-refer-article
8288          (prog1 (match-string 0 ref)
8289            (setq ref (substring ref (match-end 0))))))
8290       (gnus-summary-goto-subject current)
8291       (gnus-summary-position-point)
8292       n)))
8293
8294 (defun gnus-summary-refer-thread (&optional limit)
8295   "Fetch all articles in the current thread.
8296 If LIMIT (the numerical prefix), fetch that many old headers instead
8297 of what's specified by the `gnus-refer-thread-limit' variable."
8298   (interactive "P")
8299   (let ((id (mail-header-id (gnus-summary-article-header)))
8300         (limit (if limit (prefix-numeric-value limit)
8301                  gnus-refer-thread-limit)))
8302     (unless (eq gnus-fetch-old-headers 'invisible)
8303       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8304       ;; Retrieve the headers and read them in.
8305       (if (eq (if (numberp limit)
8306                   (gnus-retrieve-headers
8307                    (list (min
8308                           (+ (mail-header-number
8309                               (gnus-summary-article-header))
8310                              limit)
8311                           gnus-newsgroup-end))
8312                    gnus-newsgroup-name (* limit 2))
8313                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8314                 ;; headers.
8315                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8316                                        gnus-newsgroup-name limit))
8317               'nov)
8318           (gnus-build-all-threads)
8319         (error "Can't fetch thread from back ends that don't support NOV"))
8320       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8321     (gnus-summary-limit-include-thread id)))
8322
8323 (defun gnus-summary-refer-article (message-id)
8324   "Fetch an article specified by MESSAGE-ID."
8325   (interactive "sMessage-ID: ")
8326   (when (and (stringp message-id)
8327              (not (zerop (length message-id))))
8328     (setq message-id (gnus-replace-in-string message-id " " ""))
8329     ;; Construct the correct Message-ID if necessary.
8330     ;; Suggested by tale@pawl.rpi.edu.
8331     (unless (string-match "^<" message-id)
8332       (setq message-id (concat "<" message-id)))
8333     (unless (string-match ">$" message-id)
8334       (setq message-id (concat message-id ">")))
8335     ;; People often post MIDs from URLs, so unhex it:
8336     (unless (string-match "@" message-id)
8337       (setq message-id (gnus-url-unhex-string message-id)))
8338     (let* ((header (gnus-id-to-header message-id))
8339            (sparse (and header
8340                         (gnus-summary-article-sparse-p
8341                          (mail-header-number header))
8342                         (memq (mail-header-number header)
8343                               gnus-newsgroup-limit)))
8344            number)
8345       (cond
8346        ;; If the article is present in the buffer we just go to it.
8347        ((and header
8348              (or (not (gnus-summary-article-sparse-p
8349                        (mail-header-number header)))
8350                  sparse))
8351         (prog1
8352             (gnus-summary-goto-article
8353              (mail-header-number header) nil t)
8354           (when sparse
8355             (gnus-summary-update-article (mail-header-number header)))))
8356        (t
8357         ;; We fetch the article.
8358         (catch 'found
8359           (dolist (gnus-override-method (gnus-refer-article-methods))
8360             (when (and (gnus-check-server gnus-override-method)
8361                        ;; Fetch the header,
8362                        (setq number (gnus-summary-insert-subject message-id)))
8363               ;; and display the article.
8364               (gnus-summary-select-article nil nil nil number)
8365               (throw 'found t)))
8366           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8367
8368 (defun gnus-refer-article-methods ()
8369   "Return a list of referable methods."
8370   (cond
8371    ;; No method, so we default to current and native.
8372    ((null gnus-refer-article-method)
8373     (list gnus-current-select-method gnus-select-method))
8374    ;; Current.
8375    ((eq 'current gnus-refer-article-method)
8376     (list gnus-current-select-method))
8377    ;; List of select methods.
8378    ((not (and (symbolp (car gnus-refer-article-method))
8379               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8380     (let (out)
8381       (dolist (method gnus-refer-article-method)
8382         (push (if (eq 'current method)
8383                   gnus-current-select-method
8384                 method)
8385               out))
8386       (nreverse out)))
8387    ;; One single select method.
8388    (t
8389     (list gnus-refer-article-method))))
8390
8391 (defun gnus-summary-edit-parameters ()
8392   "Edit the group parameters of the current group."
8393   (interactive)
8394   (gnus-group-edit-group gnus-newsgroup-name 'params))
8395
8396 (defun gnus-summary-customize-parameters ()
8397   "Customize the group parameters of the current group."
8398   (interactive)
8399   (gnus-group-customize gnus-newsgroup-name))
8400
8401 (defun gnus-summary-enter-digest-group (&optional force)
8402   "Enter an nndoc group based on the current article.
8403 If FORCE, force a digest interpretation.  If not, try
8404 to guess what the document format is."
8405   (interactive "P")
8406   (let ((conf gnus-current-window-configuration))
8407     (save-window-excursion
8408       (save-excursion
8409         (let (gnus-article-prepare-hook
8410               gnus-display-mime-function
8411               gnus-break-pages)
8412           (gnus-summary-select-article))))
8413     (setq gnus-current-window-configuration conf)
8414     (let* ((name (format "%s-%d"
8415                          (gnus-group-prefixed-name
8416                           gnus-newsgroup-name (list 'nndoc ""))
8417                          (with-current-buffer gnus-summary-buffer
8418                            gnus-current-article)))
8419            (ogroup gnus-newsgroup-name)
8420            (params (append (gnus-info-params (gnus-get-info ogroup))
8421                            (list (cons 'to-group ogroup))
8422                            (list (cons 'parent-group ogroup))
8423                            (list (cons 'save-article-group ogroup))))
8424            (case-fold-search t)
8425            (buf (current-buffer))
8426            dig to-address)
8427       (save-excursion
8428         (set-buffer gnus-original-article-buffer)
8429         ;; Have the digest group inherit the main mail address of
8430         ;; the parent article.
8431         (when (setq to-address (or (gnus-fetch-field "reply-to")
8432                                    (gnus-fetch-field "from")))
8433           (setq params (append
8434                         (list (cons 'to-address
8435                                     (funcall gnus-decode-encoded-word-function
8436                                              to-address))))))
8437         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8438         (insert-buffer-substring gnus-original-article-buffer)
8439         ;; Remove lines that may lead nndoc to misinterpret the
8440         ;; document type.
8441         (narrow-to-region
8442          (goto-char (point-min))
8443          (or (search-forward "\n\n" nil t) (point)))
8444         (goto-char (point-min))
8445         (delete-matching-lines "^Path:\\|^From ")
8446         (widen))
8447       (unwind-protect
8448           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8449                     (gnus-newsgroup-ephemeral-ignored-charsets
8450                      gnus-newsgroup-ignored-charsets))
8451                 (gnus-group-read-ephemeral-group
8452                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8453                               (nndoc-article-type
8454                                ,(if force 'mbox 'guess)))
8455                  t nil nil nil
8456                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8457                                                         "ADAPT")))))
8458               ;; Make all postings to this group go to the parent group.
8459               (nconc (gnus-info-params (gnus-get-info name))
8460                      params)
8461             ;; Couldn't select this doc group.
8462             (switch-to-buffer buf)
8463             (gnus-set-global-variables)
8464             (gnus-configure-windows 'summary)
8465             (gnus-message 3 "Article couldn't be entered?"))
8466         (kill-buffer dig)))))
8467
8468 (defun gnus-summary-read-document (n)
8469   "Open a new group based on the current article(s).
8470 This will allow you to read digests and other similar
8471 documents as newsgroups.
8472 Obeys the standard process/prefix convention."
8473   (interactive "P")
8474   (let* ((ogroup gnus-newsgroup-name)
8475          (params (append (gnus-info-params (gnus-get-info ogroup))
8476                          (list (cons 'to-group ogroup))))
8477          group egroup groups vgroup)
8478     (dolist (article (gnus-summary-work-articles n))
8479       (setq group (format "%s-%d" gnus-newsgroup-name article))
8480       (gnus-summary-remove-process-mark article)
8481       (when (gnus-summary-display-article article)
8482         (save-excursion
8483           (with-temp-buffer
8484             (insert-buffer-substring gnus-original-article-buffer)
8485             ;; Remove some headers that may lead nndoc to make
8486             ;; the wrong guess.
8487             (message-narrow-to-head)
8488             (goto-char (point-min))
8489             (delete-matching-lines "^Path:\\|^From ")
8490             (widen)
8491             (if (setq egroup
8492                       (gnus-group-read-ephemeral-group
8493                        group `(nndoc ,group (nndoc-address ,(current-buffer))
8494                                      (nndoc-article-type guess))
8495                        t nil t))
8496                 (progn
8497                   ;; Make all postings to this group go to the parent group.
8498                   (nconc (gnus-info-params (gnus-get-info egroup))
8499                          params)
8500                   (push egroup groups))
8501               ;; Couldn't select this doc group.
8502               (gnus-error 3 "Article couldn't be entered"))))))
8503     ;; Now we have selected all the documents.
8504     (cond
8505      ((not groups)
8506       (error "None of the articles could be interpreted as documents"))
8507      ((gnus-group-read-ephemeral-group
8508        (setq vgroup (format
8509                      "nnvirtual:%s-%s" gnus-newsgroup-name
8510                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
8511        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
8512        t
8513        (cons (current-buffer) 'summary)))
8514      (t
8515       (error "Couldn't select virtual nndoc group")))))
8516
8517 (defun gnus-summary-isearch-article (&optional regexp-p)
8518   "Do incremental search forward on the current article.
8519 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
8520   (interactive "P")
8521   (let* ((gnus-inhibit-treatment t)
8522          (old (gnus-summary-select-article)))
8523     (gnus-configure-windows 'article)
8524     (gnus-eval-in-buffer-window gnus-article-buffer
8525       (save-restriction
8526         (widen)
8527         (when (eq 'old old)
8528           (gnus-article-show-all-headers))
8529         (goto-char (point-min))
8530         (isearch-forward regexp-p)))))
8531
8532 (defun gnus-summary-search-article-forward (regexp &optional backward)
8533   "Search for an article containing REGEXP forward.
8534 If BACKWARD, search backward instead."
8535   (interactive
8536    (list (read-string
8537           (format "Search article %s (regexp%s): "
8538                   (if current-prefix-arg "backward" "forward")
8539                   (if gnus-last-search-regexp
8540                       (concat ", default " gnus-last-search-regexp)
8541                     "")))
8542          current-prefix-arg))
8543   (if (string-equal regexp "")
8544       (setq regexp (or gnus-last-search-regexp ""))
8545     (setq gnus-last-search-regexp regexp)
8546     (setq gnus-article-before-search gnus-current-article))
8547   ;; Intentionally set gnus-last-article.
8548   (setq gnus-last-article gnus-article-before-search)
8549   (let ((gnus-last-article gnus-last-article))
8550     (if (gnus-summary-search-article regexp backward)
8551         (gnus-summary-show-thread)
8552       (signal 'search-failed (list regexp)))))
8553
8554 (defun gnus-summary-search-article-backward (regexp)
8555   "Search for an article containing REGEXP backward."
8556   (interactive
8557    (list (read-string
8558           (format "Search article backward (regexp%s): "
8559                   (if gnus-last-search-regexp
8560                       (concat ", default " gnus-last-search-regexp)
8561                     "")))))
8562   (gnus-summary-search-article-forward regexp 'backward))
8563
8564 (eval-when-compile
8565   (defmacro gnus-summary-search-article-position-point (regexp backward)
8566     "Dehighlight the last matched text and goto the beginning position."
8567     (` (if (and gnus-summary-search-article-matched-data
8568                 (let ((text (caddr gnus-summary-search-article-matched-data))
8569                       (inhibit-read-only t)
8570                       buffer-read-only)
8571                   (delete-region
8572                    (goto-char (car gnus-summary-search-article-matched-data))
8573                    (cadr gnus-summary-search-article-matched-data))
8574                   (insert text)
8575                   (string-match (, regexp) text)))
8576            (if (, backward) (beginning-of-line) (end-of-line))
8577          (goto-char (if (, backward) (point-max) (point-min))))))
8578
8579   (defmacro gnus-summary-search-article-highlight-goto-x-face (opoint)
8580     "Place point where X-Face image is displayed."
8581     (if (featurep 'xemacs)
8582         (` (let ((end (if (search-forward "\n\n" nil t)
8583                           (goto-char (1- (point)))
8584                         (point-min)))
8585                  extent)
8586              (or (search-backward "\n\n" nil t) (goto-char (point-min)))
8587              (unless (and (re-search-forward "^From:" end t)
8588                           (setq extent (extent-at (point)))
8589                           (extent-begin-glyph extent))
8590                (goto-char (, opoint)))))
8591       (` (let ((end (if (search-forward "\n\n" nil t)
8592                         (goto-char (1- (point)))
8593                       (point-min)))
8594                (start (or (search-backward "\n\n" nil t) (point-min))))
8595            (goto-char
8596             (or (text-property-any start end 'x-face-image t);; x-face-e21
8597                 (text-property-any start end 'x-face-mule-bitmap-image t)
8598                 (, opoint)))))))
8599
8600   (defmacro gnus-summary-search-article-highlight-matched-text
8601     (backward treated x-face)
8602     "Highlight matched text in the function `gnus-summary-search-article'."
8603     (` (let ((start (set-marker (make-marker) (match-beginning 0)))
8604              (end (set-marker (make-marker) (match-end 0)))
8605              (inhibit-read-only t)
8606              buffer-read-only)
8607          (unless treated
8608            (let ((,@
8609                   (let ((items (mapcar 'car gnus-treatment-function-alist)))
8610                     (mapcar
8611                      (lambda (item) (setq items (delq item items)))
8612                      '(gnus-treat-buttonize
8613                        gnus-treat-fill-article
8614                        gnus-treat-fill-long-lines
8615                        gnus-treat-emphasize
8616                        gnus-treat-highlight-headers
8617                        gnus-treat-highlight-citation
8618                        gnus-treat-highlight-signature
8619                        gnus-treat-overstrike
8620                        gnus-treat-display-x-face
8621                        gnus-treat-buttonize-head
8622                        gnus-treat-decode-article-as-default-mime-charset))
8623                     (static-if (featurep 'xemacs)
8624                         items
8625                       (cons '(x-face-mule-delete-x-face-field
8626                               (quote never))
8627                             items))))
8628                  (gnus-treat-display-x-face
8629                   (when (, x-face) gnus-treat-display-x-face)))
8630              (gnus-article-prepare-mime-display)))
8631          (goto-char (if (, backward) start end))
8632          (when (, x-face)
8633            (gnus-summary-search-article-highlight-goto-x-face (point)))
8634          (setq gnus-summary-search-article-matched-data
8635                (list start end (buffer-substring start end)))
8636          (unless (eq start end);; matched text has been deleted. :-<
8637            (put-text-property start end 'face
8638                               (or (find-face 'isearch)
8639                                   'secondary-selection))))))
8640   )
8641
8642 (defun gnus-summary-search-article (regexp &optional backward)
8643   "Search for an article containing REGEXP.
8644 Optional argument BACKWARD means do search for backward.
8645 `gnus-select-article-hook' is not called during the search."
8646   ;; We have to require this here to make sure that the following
8647   ;; dynamic binding isn't shadowed by autoloading.
8648   (require 'gnus-async)
8649   (require 'gnus-art)
8650   (let ((gnus-select-article-hook nil)  ;Disable hook.
8651         (gnus-article-prepare-hook nil)
8652         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
8653         (gnus-use-article-prefetch nil)
8654         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
8655         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
8656         (gnus-visual nil)
8657         (gnus-keep-backlog nil)
8658         (gnus-break-pages nil)
8659         (gnus-summary-display-arrow nil)
8660         (gnus-updated-mode-lines nil)
8661         (gnus-auto-center-summary nil)
8662         (sum (current-buffer))
8663         (found nil)
8664         point treated)
8665     (gnus-save-hidden-threads
8666       (static-if (featurep 'xemacs)
8667           (let ((gnus-inhibit-treatment t))
8668             (setq treated (eq 'old (gnus-summary-select-article)))
8669             (when (and treated
8670                        (not (and (gnus-buffer-live-p gnus-article-buffer)
8671                                  (window-live-p (get-buffer-window
8672                                                  gnus-article-buffer t)))))
8673               (gnus-summary-select-article nil t)
8674               (setq treated nil)))
8675         (let ((gnus-inhibit-treatment t)
8676               (x-face-mule-delete-x-face-field 'never))
8677           (setq treated (eq 'old (gnus-summary-select-article)))
8678           (when (and treated
8679                      (not
8680                       (and (gnus-buffer-live-p gnus-article-buffer)
8681                            (window-live-p (get-buffer-window
8682                                            gnus-article-buffer t))
8683                            (or (not (string-match "^\\^X-Face:" regexp))
8684                                (with-current-buffer gnus-article-buffer
8685                                  gnus-summary-search-article-matched-data)))))
8686             (gnus-summary-select-article nil t)
8687             (setq treated nil))))
8688       (set-buffer gnus-article-buffer)
8689       (widen)
8690       (if treated
8691           (progn
8692             (gnus-article-show-all-headers)
8693             (gnus-summary-search-article-position-point regexp backward))
8694         (goto-char (if backward (point-max) (point-min))))
8695       (while (not found)
8696         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
8697         (if (if backward
8698                 (re-search-backward regexp nil t)
8699               (re-search-forward regexp nil t))
8700             ;; We found the regexp.
8701             (progn
8702               (gnus-summary-search-article-highlight-matched-text
8703                backward treated (string-match "^\\^X-Face:" regexp))
8704               (setq found 'found)
8705               (forward-line
8706                (/ (- 2 (window-height
8707                         (get-buffer-window gnus-article-buffer t)))
8708                   2))
8709               (set-window-start
8710                (get-buffer-window (current-buffer))
8711                (point))
8712               (set-buffer sum)
8713               (setq point (point)))
8714           ;; We didn't find it, so we go to the next article.
8715           (set-buffer sum)
8716           (setq found 'not)
8717           (while (eq found 'not)
8718             (if (not (if backward (gnus-summary-find-prev)
8719                        (gnus-summary-find-next)))
8720                 ;; No more articles.
8721                 (setq found t)
8722               ;; Select the next article and adjust point.
8723               (unless (gnus-summary-article-sparse-p
8724                        (gnus-summary-article-number))
8725                 (setq found nil)
8726                 (let ((gnus-inhibit-treatment t))
8727                   (gnus-summary-select-article))
8728                 (setq treated nil)
8729                 (set-buffer gnus-article-buffer)
8730                 (widen)
8731                 (goto-char (if backward (point-max) (point-min))))))))
8732       (gnus-message 7 ""))
8733     ;; Return whether we found the regexp.
8734     (when (eq found 'found)
8735       (goto-char point)
8736       (gnus-summary-show-thread)
8737       (gnus-summary-goto-subject gnus-current-article)
8738       (gnus-summary-position-point)
8739       t)))
8740
8741 (defun gnus-find-matching-articles (header regexp)
8742   "Return a list of all articles that match REGEXP on HEADER.
8743 This search includes all articles in the current group that Gnus has
8744 fetched headers for, whether they are displayed or not."
8745   (let ((articles nil)
8746         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
8747         (case-fold-search t))
8748     (dolist (header gnus-newsgroup-headers)
8749       (when (string-match regexp (funcall func header))
8750         (push (mail-header-number header) articles)))
8751     (nreverse articles)))
8752
8753 (defun gnus-summary-find-matching (header regexp &optional backward unread
8754                                           not-case-fold not-matching)
8755   "Return a list of all articles that match REGEXP on HEADER.
8756 The search stars on the current article and goes forwards unless
8757 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
8758 If UNREAD is non-nil, only unread articles will
8759 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
8760 in the comparisons. If NOT-MATCHING, return a list of all articles that
8761 not match REGEXP on HEADER."
8762   (let ((case-fold-search (not not-case-fold))
8763         articles d func)
8764     (if (consp header)
8765         (if (eq (car header) 'extra)
8766             (setq func
8767                   `(lambda (h)
8768                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
8769                          "")))
8770           (error "%s is an invalid header" header))
8771       (unless (fboundp (intern (concat "mail-header-" header)))
8772         (error "%s is not a valid header" header))
8773       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
8774     (dolist (d (if (eq backward 'all)
8775                    gnus-newsgroup-data
8776                  (gnus-data-find-list
8777                   (gnus-summary-article-number)
8778                   (gnus-data-list backward))))
8779       (when (and (or (not unread)       ; We want all articles...
8780                      (gnus-data-unread-p d)) ; Or just unreads.
8781                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
8782                  (if not-matching
8783                      (not (string-match
8784                            regexp
8785                            (funcall func (gnus-data-header d))))
8786                    (string-match regexp
8787                                  (funcall func (gnus-data-header d)))))
8788         (push (gnus-data-number d) articles))) ; Success!
8789     (nreverse articles)))
8790
8791 (defun gnus-summary-execute-command (header regexp command &optional backward)
8792   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
8793 If HEADER is an empty string (or nil), the match is done on the entire
8794 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
8795   (interactive
8796    (list (let ((completion-ignore-case t))
8797            (completing-read
8798             "Header name: "
8799             (mapcar (lambda (header) (list (format "%s" header)))
8800                     (append
8801                      '("Number" "Subject" "From" "Lines" "Date"
8802                        "Message-ID" "Xref" "References" "Body")
8803                      gnus-extra-headers))
8804             nil 'require-match))
8805          (read-string "Regexp: ")
8806          (read-key-sequence "Command: ")
8807          current-prefix-arg))
8808   (when (equal header "Body")
8809     (setq header ""))
8810   ;; Hidden thread subtrees must be searched as well.
8811   (gnus-summary-show-all-threads)
8812   ;; We don't want to change current point nor window configuration.
8813   (save-excursion
8814     (save-window-excursion
8815       (let (gnus-visual
8816             gnus-treat-strip-trailing-blank-lines
8817             gnus-treat-strip-leading-blank-lines
8818             gnus-treat-strip-multiple-blank-lines
8819             gnus-treat-hide-boring-headers
8820             gnus-treat-fold-newsgroups
8821             gnus-article-prepare-hook)
8822         (gnus-message 6 "Executing %s..." (key-description command))
8823         ;; We'd like to execute COMMAND interactively so as to give arguments.
8824         (gnus-execute header regexp
8825                       `(call-interactively ',(key-binding command))
8826                       backward)
8827         (gnus-message 6 "Executing %s...done" (key-description command))))))
8828
8829 (defun gnus-summary-beginning-of-article ()
8830   "Scroll the article back to the beginning."
8831   (interactive)
8832   (gnus-summary-select-article)
8833   (gnus-configure-windows 'article)
8834   (gnus-eval-in-buffer-window gnus-article-buffer
8835     (widen)
8836     (goto-char (point-min))
8837     (when gnus-break-pages
8838       (gnus-narrow-to-page))))
8839
8840 (defun gnus-summary-end-of-article ()
8841   "Scroll to the end of the article."
8842   (interactive)
8843   (gnus-summary-select-article)
8844   (gnus-configure-windows 'article)
8845   (gnus-eval-in-buffer-window gnus-article-buffer
8846     (widen)
8847     (goto-char (point-max))
8848     (recenter -3)
8849     (when gnus-break-pages
8850       (when (re-search-backward page-delimiter nil t)
8851         (narrow-to-region (match-end 0) (point-max)))
8852       (gnus-narrow-to-page))))
8853
8854 (defun gnus-summary-print-truncate-and-quote (string &optional len)
8855   "Truncate to LEN and quote all \"(\"'s in STRING."
8856   (gnus-replace-in-string (if (and len (> (length string) len))
8857                               (substring string 0 len)
8858                             string)
8859                           "[()]" "\\\\\\&"))
8860
8861 (defun gnus-summary-print-article (&optional filename n)
8862   "Generate and print a PostScript image of the process-marked (mail) articles.
8863
8864 If used interactively, print the current article if none are
8865 process-marked.  With prefix arg, prompt the user for the name of the
8866 file to save in.
8867
8868 When used from Lisp, accept two optional args FILENAME and N.  N means
8869 to print the next N articles.  If N is negative, print the N previous
8870 articles.  If N is nil and articles have been marked with the process
8871 mark, print these instead.
8872
8873 If the optional first argument FILENAME is nil, send the image to the
8874 printer.  If FILENAME is a string, save the PostScript image in a file with
8875 that name.  If FILENAME is a number, prompt the user for the name of the file
8876 to save in."
8877   (interactive (list (ps-print-preprint current-prefix-arg)))
8878   (dolist (article (gnus-summary-work-articles n))
8879     (gnus-summary-select-article nil nil 'pseudo article)
8880     (gnus-eval-in-buffer-window gnus-article-buffer
8881       (gnus-print-buffer))
8882     (gnus-summary-remove-process-mark article))
8883   (ps-despool filename))
8884
8885 (defun gnus-print-buffer ()
8886   (let ((buffer (generate-new-buffer " *print*")))
8887     (unwind-protect
8888         (progn
8889           (copy-to-buffer buffer (point-min) (point-max))
8890           (set-buffer buffer)
8891           (gnus-remove-text-with-property 'gnus-decoration)
8892           (when (gnus-visual-p 'article-highlight 'highlight)
8893             ;; Copy-to-buffer doesn't copy overlay.  So redo
8894             ;; highlight.
8895             (let ((gnus-article-buffer buffer))
8896               (gnus-article-highlight-citation t)
8897               (gnus-article-highlight-signature)
8898               (gnus-article-emphasize)
8899               (gnus-article-delete-invisible-text)))
8900           (let ((ps-left-header
8901                  (list
8902                   (concat "("
8903                           (gnus-summary-print-truncate-and-quote
8904                            (mail-header-subject gnus-current-headers)
8905                            66) ")")
8906                   (concat "("
8907                           (gnus-summary-print-truncate-and-quote
8908                            (mail-header-from gnus-current-headers)
8909                            45) ")")))
8910                 (ps-right-header
8911                  (list
8912                   "/pagenumberstring load"
8913                   (concat "("
8914                           (mail-header-date gnus-current-headers) ")"))))
8915             (gnus-run-hooks 'gnus-ps-print-hook)
8916             (save-excursion
8917               (if window-system
8918                   (ps-spool-buffer-with-faces)
8919                 (ps-spool-buffer)))))
8920       (kill-buffer buffer))))
8921
8922 (defun gnus-summary-show-article (&optional arg)
8923   "Force redisplaying of the current article.
8924 If ARG (the prefix) is a number, show the article with the charset
8925 defined in `gnus-summary-show-article-charset-alist', or the charset
8926 input.
8927 If ARG (the prefix) is non-nil and not a number, show the raw article
8928 without any article massaging functions being run.  Normally, the key
8929 strokes are `C-u g'."
8930   (interactive "P")
8931   (cond
8932    ((numberp arg)
8933     (gnus-summary-show-article t)
8934     (let* ((gnus-newsgroup-charset
8935             (or (cdr (assq arg gnus-summary-show-article-charset-alist))
8936                 (mm-read-coding-system
8937                  "View as charset: " ;; actually it is coding system.
8938                  (with-current-buffer gnus-article-buffer
8939                    (mm-detect-coding-region (point) (point-max))))))
8940            (default-mime-charset gnus-newsgroup-charset)
8941            (gnus-newsgroup-ignored-charsets 'gnus-all))
8942       (gnus-summary-select-article nil 'force)
8943       (let ((deps gnus-newsgroup-dependencies)
8944             head header lines)
8945         (save-excursion
8946           (set-buffer gnus-original-article-buffer)
8947           (save-restriction
8948             (message-narrow-to-head)
8949             (setq head (buffer-string))
8950             (goto-char (point-min))
8951             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
8952               (goto-char (point-max))
8953               (widen)
8954               (setq lines (1- (count-lines (point) (point-max))))))
8955           (with-temp-buffer
8956             (insert (format "211 %d Article retrieved.\n"
8957                             (cdr gnus-article-current)))
8958             (insert head)
8959             (if lines (insert (format "Lines: %d\n" lines)))
8960             (insert ".\n")
8961             (let ((nntp-server-buffer (current-buffer)))
8962               (setq header (car (gnus-get-newsgroup-headers deps t))))))
8963         (gnus-data-set-header
8964          (gnus-data-find (cdr gnus-article-current))
8965          header)
8966         (gnus-summary-update-article-line
8967          (cdr gnus-article-current) header)
8968         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
8969           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
8970    ((not arg)
8971     ;; Select the article the normal way.
8972     (gnus-summary-select-article nil 'force))
8973    (t
8974     ;; We have to require this here to make sure that the following
8975     ;; dynamic binding isn't shadowed by autoloading.
8976     (require 'gnus-async)
8977     (require 'gnus-art)
8978     ;; Bind the article treatment functions to nil.
8979     (let ((gnus-have-all-headers t)
8980           gnus-article-prepare-hook
8981           gnus-article-decode-hook
8982           gnus-break-pages
8983           gnus-show-mime
8984           (gnus-inhibit-treatment t))
8985       (gnus-summary-select-article nil 'force))))
8986   (gnus-summary-goto-subject gnus-current-article)
8987   (gnus-summary-position-point))
8988
8989 (defun gnus-summary-show-raw-article ()
8990   "Show the raw article without any article massaging functions being run."
8991   (interactive)
8992   (gnus-summary-show-article t))
8993
8994 (defun gnus-summary-verbose-headers (&optional arg)
8995   "Toggle permanent full header display.
8996 If ARG is a positive number, turn header display on.
8997 If ARG is a negative number, turn header display off."
8998   (interactive "P")
8999   (setq gnus-show-all-headers
9000         (cond ((or (not (numberp arg))
9001                    (zerop arg))
9002                (not gnus-show-all-headers))
9003               ((natnump arg)
9004                t)))
9005   (gnus-summary-show-article))
9006
9007 (defun gnus-summary-toggle-header (&optional arg)
9008   "Show the headers if they are hidden, or hide them if they are shown.
9009 If ARG is a positive number, show the entire header.
9010 If ARG is a negative number, hide the unwanted header lines."
9011   (interactive "P")
9012   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9013                      (get-buffer-window gnus-article-buffer t))))
9014     (with-current-buffer gnus-article-buffer
9015       (widen)
9016       (article-narrow-to-head)
9017       (let* ((buffer-read-only nil)
9018              (inhibit-point-motion-hooks t)
9019              (hidden (if (numberp arg)
9020                          (>= arg 0)
9021                        (or (not (looking-at "[^ \t\n]+:"))
9022                            (gnus-article-hidden-text-p 'headers))))
9023              s e)
9024         (delete-region (point-min) (point-max))
9025         (with-current-buffer gnus-original-article-buffer
9026           (goto-char (setq s (point-min)))
9027           (setq e (if (search-forward "\n\n" nil t)
9028                       (1- (point))
9029                     (point-max))))
9030         (insert-buffer-substring gnus-original-article-buffer s e)
9031         ;; In T-gnus, gnus-article-decode-hook doesn't contain
9032         ;; article-decode-encoded-words by default.
9033         (article-decode-encoded-words)
9034         (run-hooks 'gnus-article-decode-hook)
9035         (if hidden
9036             (let ((gnus-treat-hide-headers nil)
9037                   (gnus-treat-hide-boring-headers nil))
9038               (gnus-delete-wash-type 'headers)
9039               (gnus-treat-article 'head))
9040           (gnus-treat-article 'head))
9041         (widen)
9042         (if window
9043             (set-window-start window (goto-char (point-min))))
9044         (if gnus-break-pages
9045             (gnus-narrow-to-page)
9046           (when (gnus-visual-p 'page-marker)
9047             (let ((buffer-read-only nil))
9048               (gnus-remove-text-with-property 'gnus-prev)
9049               (gnus-remove-text-with-property 'gnus-next))))
9050         (gnus-set-mode-line 'article)))))
9051
9052 (defun gnus-summary-show-all-headers ()
9053   "Make all header lines visible."
9054   (interactive)
9055   (gnus-summary-toggle-header 1))
9056
9057 (defun gnus-summary-toggle-mime (&optional arg)
9058   "Toggle MIME processing.
9059 If ARG is a positive number, turn MIME processing on."
9060   (interactive "P")
9061   (setq gnus-show-mime
9062         (if (null arg)
9063             (not gnus-show-mime)
9064           (> (prefix-numeric-value arg) 0)))
9065   (gnus-summary-select-article t 'force))
9066
9067 (defun gnus-summary-caesar-message (&optional arg)
9068   "Caesar rotate the current article by 13.
9069 The numerical prefix specifies how many places to rotate each letter
9070 forward."
9071   (interactive "P")
9072   (gnus-summary-select-article)
9073   (let ((mail-header-separator ""))
9074     (gnus-eval-in-buffer-window gnus-article-buffer
9075       (save-restriction
9076         (widen)
9077         (let ((start (window-start))
9078               buffer-read-only)
9079           (message-caesar-buffer-body arg)
9080           (set-window-start (get-buffer-window (current-buffer)) start)))))
9081   ;; Create buttons and stuff...
9082   (gnus-treat-article nil))
9083
9084 (defun gnus-summary-idna-message (&optional arg)
9085   "Decode IDNA encoded domain names in the current articles.
9086 IDNA encoded domain names looks like `xn--bar'.  If a string
9087 remain unencoded after running this function, it is likely an
9088 invalid IDNA string (`xn--bar' is invalid).
9089
9090 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9091 installed for this command to work."
9092   (interactive "P")
9093   (if (not (and (condition-case nil (require 'idna)
9094                   (file-error))
9095                 (mm-coding-system-p 'utf-8)
9096                 (executable-find (symbol-value 'idna-program))))
9097       (gnus-message
9098        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9099     (gnus-summary-select-article)
9100     (let ((mail-header-separator ""))
9101       (gnus-eval-in-buffer-window gnus-article-buffer
9102         (save-restriction
9103           (widen)
9104           (let ((start (window-start))
9105                 buffer-read-only)
9106             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9107               (replace-match (idna-to-unicode (match-string 1))))
9108             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9109
9110 (autoload 'unmorse-region "morse"
9111   "Convert morse coded text in region to ordinary ASCII text."
9112   t)
9113
9114 (defun gnus-summary-morse-message (&optional arg)
9115   "Morse decode the current article."
9116   (interactive "P")
9117   (gnus-summary-select-article)
9118   (let ((mail-header-separator ""))
9119     (gnus-eval-in-buffer-window gnus-article-buffer
9120       (save-excursion
9121         (save-restriction
9122           (widen)
9123           (let ((pos (window-start))
9124                 buffer-read-only)
9125             (goto-char (point-min))
9126             (when (message-goto-body)
9127               (gnus-narrow-to-body))
9128             (goto-char (point-min))
9129             (while (search-forward "·" (point-max) t)
9130               (replace-match "."))
9131             (unmorse-region (point-min) (point-max))
9132             (widen)
9133             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9134
9135 (defun gnus-summary-stop-page-breaking ()
9136   "Stop page breaking in the current article."
9137   (interactive)
9138   (gnus-summary-select-article)
9139   (gnus-eval-in-buffer-window gnus-article-buffer
9140     (widen)
9141     (when (gnus-visual-p 'page-marker)
9142       (let ((buffer-read-only nil))
9143         (gnus-remove-text-with-property 'gnus-prev)
9144         (gnus-remove-text-with-property 'gnus-next))
9145       (setq gnus-page-broken nil))))
9146
9147 (defun gnus-summary-move-article (&optional n to-newsgroup
9148                                             select-method action)
9149   "Move the current article to a different newsgroup.
9150 If N is a positive number, move the N next articles.
9151 If N is a negative number, move the N previous articles.
9152 If N is nil and any articles have been marked with the process mark,
9153 move those articles instead.
9154 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9155 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9156 re-spool using this method.
9157
9158 When called interactively with TO-NEWSGROUP being nil, the value of
9159 the variable `gnus-move-split-methods' is used for finding a default
9160 for the target newsgroup.
9161
9162 For this function to work, both the current newsgroup and the
9163 newsgroup that you want to move to have to support the `request-move'
9164 and `request-accept' functions.
9165
9166 ACTION can be either `move' (the default), `crosspost' or `copy'."
9167   (interactive "P")
9168   (unless action
9169     (setq action 'move))
9170   ;; Check whether the source group supports the required functions.
9171   (cond ((and (eq action 'move)
9172               (not (gnus-check-backend-function
9173                     'request-move-article gnus-newsgroup-name)))
9174          (error "The current group does not support article moving"))
9175         ((and (eq action 'crosspost)
9176               (not (gnus-check-backend-function
9177                     'request-replace-article gnus-newsgroup-name)))
9178          (error "The current group does not support article editing")))
9179   (let ((articles (gnus-summary-work-articles n))
9180         (prefix (if (gnus-check-backend-function
9181                      'request-move-article gnus-newsgroup-name)
9182                     (funcall gnus-move-group-prefix-function
9183                              gnus-newsgroup-name)
9184                   ""))
9185         (names '((move "Move" "Moving")
9186                  (copy "Copy" "Copying")
9187                  (crosspost "Crosspost" "Crossposting")))
9188         (copy-buf (save-excursion
9189                     (nnheader-set-temp-buffer " *copy article*")))
9190         art-group to-method new-xref article to-groups articles-to-update-marks)
9191     (unless (assq action names)
9192       (error "Unknown action %s" action))
9193     ;; Read the newsgroup name.
9194     (when (and (not to-newsgroup)
9195                (not select-method))
9196       (if (and gnus-move-split-methods
9197                (not
9198                 (and (memq gnus-current-article articles)
9199                      (gnus-buffer-live-p gnus-original-article-buffer))))
9200           ;; When `gnus-move-split-methods' is non-nil, we have to
9201           ;; select an article to give `gnus-read-move-group-name' an
9202           ;; opportunity to suggest an appropriate default.  However,
9203           ;; we needn't render or mark the article.
9204           (let ((gnus-display-mime-function nil)
9205                 (gnus-article-prepare-hook nil)
9206                 (gnus-mark-article-hook nil))
9207             (gnus-summary-select-article nil nil nil (car articles))))
9208       (setq to-newsgroup
9209             (gnus-read-move-group-name
9210              (cadr (assq action names))
9211              (symbol-value (intern (format "gnus-current-%s-group" action)))
9212              articles prefix))
9213       (set (intern (format "gnus-current-%s-group" action)) to-newsgroup))
9214     (setq to-method (or select-method
9215                         (gnus-server-to-method
9216                          (gnus-group-method to-newsgroup))))
9217     ;; Check the method we are to move this article to...
9218     (unless (gnus-check-backend-function
9219              'request-accept-article (car to-method))
9220       (error "%s does not support article copying" (car to-method)))
9221     (unless (gnus-check-server to-method)
9222       (error "Can't open server %s" (car to-method)))
9223     (gnus-message 6 "%s to %s: %s..."
9224                   (caddr (assq action names))
9225                   (or (car select-method) to-newsgroup) articles)
9226     (while articles
9227       (setq article (pop articles))
9228       (setq
9229        art-group
9230        (cond
9231         ;; Move the article.
9232         ((eq action 'move)
9233          ;; Remove this article from future suppression.
9234          (gnus-dup-unsuppress-article article)
9235          (let* ((from-method (gnus-find-method-for-group
9236                               gnus-newsgroup-name))
9237                 (to-method (gnus-find-method-for-group
9238                             to-newsgroup))
9239                 (move-is-internal (gnus-method-equal from-method to-method)))
9240          (gnus-request-move-article
9241           article                       ; Article to move
9242           gnus-newsgroup-name           ; From newsgroup
9243           (nth 1 (gnus-find-method-for-group
9244                   gnus-newsgroup-name)) ; Server
9245           (list 'gnus-request-accept-article
9246                 to-newsgroup (list 'quote select-method)
9247                 (not articles) t)       ; Accept form
9248           (not articles)                ; Only save nov last time
9249           move-is-internal)))           ; is this move internal?
9250         ;; Copy the article.
9251         ((eq action 'copy)
9252          (save-excursion
9253            (set-buffer copy-buf)
9254            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9255              (save-restriction
9256                (nnheader-narrow-to-headers)
9257                (dolist (hdr gnus-copy-article-ignored-headers)
9258                  (message-remove-header hdr t)))
9259              (gnus-request-accept-article
9260               to-newsgroup select-method (not articles) t))))
9261         ;; Crosspost the article.
9262         ((eq action 'crosspost)
9263          (let ((xref (message-tokenize-header
9264                       (mail-header-xref (gnus-summary-article-header article))
9265                       " ")))
9266            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9267                                   ":" (number-to-string article)))
9268            (unless xref
9269              (setq xref (list (system-name))))
9270            (setq new-xref
9271                  (concat
9272                   (mapconcat 'identity
9273                              (delete "Xref:" (delete new-xref xref))
9274                              " ")
9275                   " " new-xref))
9276            (save-excursion
9277              (set-buffer copy-buf)
9278              ;; First put the article in the destination group.
9279              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9280              (when (consp (setq art-group
9281                                 (gnus-request-accept-article
9282                                  to-newsgroup select-method (not articles))))
9283                (setq new-xref (concat new-xref " " (car art-group)
9284                                       ":"
9285                                       (number-to-string (cdr art-group))))
9286                ;; Now we have the new Xrefs header, so we insert
9287                ;; it and replace the new article.
9288                (nnheader-replace-header "Xref" new-xref)
9289                (gnus-request-replace-article
9290                 (cdr art-group) to-newsgroup (current-buffer))
9291                art-group))))))
9292       (cond
9293        ((not art-group)
9294         (gnus-message 1 "Couldn't %s article %s: %s"
9295                       (cadr (assq action names)) article
9296                       (nnheader-get-report (car to-method))))
9297        ((eq art-group 'junk)
9298         (when (eq action 'move)
9299           (gnus-summary-mark-article article gnus-canceled-mark)
9300           (gnus-message 4 "Deleted article %s" article)
9301           ;; run the delete hook
9302           (run-hook-with-args 'gnus-summary-article-delete-hook
9303                               action
9304                               (gnus-data-header
9305                                (assoc article (gnus-data-list nil)))
9306                               gnus-newsgroup-name nil
9307                               select-method)))
9308        (t
9309         (let* ((pto-group (gnus-group-prefixed-name
9310                            (car art-group) to-method))
9311                (info (gnus-get-info pto-group))
9312                (to-group (gnus-info-group info))
9313                to-marks)
9314           ;; Update the group that has been moved to.
9315           (when (and info
9316                      (memq action '(move copy)))
9317             (unless (member to-group to-groups)
9318               (push to-group to-groups))
9319
9320             (unless (memq article gnus-newsgroup-unreads)
9321               (push 'read to-marks)
9322               (gnus-info-set-read
9323                info (gnus-add-to-range (gnus-info-read info)
9324                                        (list (cdr art-group)))))
9325
9326             ;; See whether the article is to be put in the cache.
9327             (let ((marks (if (gnus-group-auto-expirable-p to-group)
9328                              gnus-article-mark-lists
9329                            (delete '(expirable . expire)
9330                                    (copy-sequence gnus-article-mark-lists))))
9331                   (to-article (cdr art-group)))
9332
9333               ;; Enter the article into the cache in the new group,
9334               ;; if that is required.
9335               (when gnus-use-cache
9336                 (gnus-cache-possibly-enter-article
9337                  to-group to-article
9338                  (let ((header (copy-sequence
9339                                 (gnus-summary-article-header article))))
9340                    (mail-header-set-number header to-article)
9341                    header)
9342                  (memq article gnus-newsgroup-marked)
9343                  (memq article gnus-newsgroup-dormant)
9344                  (memq article gnus-newsgroup-unreads)))
9345
9346               (when gnus-preserve-marks
9347                 ;; Copy any marks over to the new group.
9348                 (when (and (equal to-group gnus-newsgroup-name)
9349                            (not (memq article gnus-newsgroup-unreads)))
9350                   ;; Mark this article as read in this group.
9351                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9352                   (setcdr (gnus-active to-group) to-article)
9353                   (setcdr gnus-newsgroup-active to-article))
9354
9355                 (while marks
9356                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9357                     (when (memq article (symbol-value
9358                                          (intern (format "gnus-newsgroup-%s"
9359                                                          (caar marks)))))
9360                       (push (cdar marks) to-marks)
9361                       ;; If the other group is the same as this group,
9362                       ;; then we have to add the mark to the list.
9363                       (when (equal to-group gnus-newsgroup-name)
9364                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9365                              (cons to-article
9366                                    (symbol-value
9367                                     (intern (format "gnus-newsgroup-%s"
9368                                                     (caar marks)))))))
9369                       ;; Copy the marks to other group.
9370                       (gnus-add-marked-articles
9371                        to-group (cdar marks) (list to-article) info)))
9372                   (setq marks (cdr marks)))
9373
9374                 (gnus-request-set-mark
9375                  to-group (list (list (list to-article) 'add to-marks))))
9376
9377               (gnus-dribble-enter
9378                (concat "(gnus-group-set-info '"
9379                        (gnus-prin1-to-string (gnus-get-info to-group))
9380                        ")"))))
9381
9382           ;; Update the Xref header in this article to point to
9383           ;; the new crossposted article we have just created.
9384           (when (eq action 'crosspost)
9385             (save-excursion
9386               (set-buffer copy-buf)
9387               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9388               (nnheader-replace-header "Xref" new-xref)
9389               (gnus-request-replace-article
9390                article gnus-newsgroup-name (current-buffer))))
9391
9392           ;; run the move/copy/crosspost/respool hook
9393           (run-hook-with-args 'gnus-summary-article-move-hook
9394                               action
9395                               (gnus-data-header
9396                                (assoc article (gnus-data-list nil)))
9397                               gnus-newsgroup-name
9398                               to-newsgroup
9399                               select-method))
9400
9401         ;;;!!!Why is this necessary?
9402         (set-buffer gnus-summary-buffer)
9403         
9404         (gnus-summary-goto-subject article)
9405         (when (eq action 'move)
9406           (gnus-summary-mark-article article gnus-canceled-mark))))
9407       (push article articles-to-update-marks))
9408
9409     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9410     ;; Re-activate all groups that have been moved to.
9411     (save-excursion
9412       (set-buffer gnus-group-buffer)
9413       (let ((gnus-group-marked to-groups))
9414         (gnus-group-get-new-news-this-group nil t)))
9415     
9416     (gnus-kill-buffer copy-buf)
9417     (gnus-summary-position-point)
9418     (gnus-set-mode-line 'summary)))
9419
9420 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9421   "Copy the current article to some other group.
9422 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9423 When called interactively, if TO-NEWSGROUP is nil, use the value of
9424 the variable `gnus-move-split-methods' for finding a default target
9425 newsgroup.
9426 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9427 re-spool using this method."
9428   (interactive "P")
9429   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9430
9431 (defun gnus-summary-crosspost-article (&optional n)
9432   "Crosspost the current article to some other group."
9433   (interactive "P")
9434   (gnus-summary-move-article n nil nil 'crosspost))
9435
9436 (defcustom gnus-summary-respool-default-method nil
9437   "Default method type for respooling an article.
9438 If nil, use to the current newsgroup method."
9439   :type 'symbol
9440   :group 'gnus-summary-mail)
9441
9442 (defcustom gnus-summary-display-while-building nil
9443   "If non-nil, show and update the summary buffer as it's being built.
9444 If the value is t, update the buffer after every line is inserted.  If
9445 the value is an integer (N), update the display every N lines."
9446   :version "22.1"
9447   :group 'gnus-thread
9448   :type '(choice (const :tag "off" nil)
9449                  number
9450                  (const :tag "frequently" t)))
9451
9452 (defun gnus-summary-respool-article (&optional n method)
9453   "Respool the current article.
9454 The article will be squeezed through the mail spooling process again,
9455 which means that it will be put in some mail newsgroup or other
9456 depending on `nnmail-split-methods'.
9457 If N is a positive number, respool the N next articles.
9458 If N is a negative number, respool the N previous articles.
9459 If N is nil and any articles have been marked with the process mark,
9460 respool those articles instead.
9461
9462 Respooling can be done both from mail groups and \"real\" newsgroups.
9463 In the former case, the articles in question will be moved from the
9464 current group into whatever groups they are destined to.  In the
9465 latter case, they will be copied into the relevant groups."
9466   (interactive
9467    (list current-prefix-arg
9468          (let* ((methods (gnus-methods-using 'respool))
9469                 (methname
9470                  (symbol-name (or gnus-summary-respool-default-method
9471                                   (car (gnus-find-method-for-group
9472                                         gnus-newsgroup-name)))))
9473                 (method
9474                  (gnus-completing-read-with-default
9475                   methname "What backend do you want to use when respooling?"
9476                   methods nil t nil 'gnus-mail-method-history))
9477                 ms)
9478            (cond
9479             ((zerop (length (setq ms (gnus-servers-using-backend
9480                                       (intern method)))))
9481              (list (intern method) ""))
9482             ((= 1 (length ms))
9483              (car ms))
9484             (t
9485              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9486                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9487                            ms-alist))))))))
9488   (unless method
9489     (error "No method given for respooling"))
9490   (if (assoc (symbol-name
9491               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9492              (gnus-methods-using 'respool))
9493       (gnus-summary-move-article n nil method)
9494     (gnus-summary-copy-article n nil method)))
9495
9496 (defun gnus-summary-import-article (file &optional edit)
9497   "Import an arbitrary file into a mail newsgroup."
9498   (interactive "fImport file: \nP")
9499   (let ((group gnus-newsgroup-name)
9500         (now (current-time))
9501         atts lines group-art)
9502     (unless (gnus-check-backend-function 'request-accept-article group)
9503       (error "%s does not support article importing" group))
9504     (or (file-readable-p file)
9505         (not (file-regular-p file))
9506         (error "Can't read %s" file))
9507     (save-excursion
9508       (set-buffer (gnus-get-buffer-create " *import file*"))
9509       (erase-buffer)
9510       (nnheader-insert-file-contents file)
9511       (goto-char (point-min))
9512       (if (nnheader-article-p)
9513           (save-restriction
9514             (goto-char (point-min))
9515             (search-forward "\n\n" nil t)
9516             (narrow-to-region (point-min) (1- (point)))
9517             (goto-char (point-min))
9518             (unless (re-search-forward "^date:" nil t)
9519               (goto-char (point-max))
9520               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9521         ;; This doesn't look like an article, so we fudge some headers.
9522         (setq atts (file-attributes file)
9523               lines (count-lines (point-min) (point-max)))
9524         (insert "From: " (read-string "From: ") "\n"
9525                 "Subject: " (read-string "Subject: ") "\n"
9526                 "Date: " (message-make-date (nth 5 atts)) "\n"
9527                 "Message-ID: " (message-make-message-id) "\n"
9528                 "Lines: " (int-to-string lines) "\n"
9529                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9530       (setq group-art (gnus-request-accept-article group nil t))
9531       (kill-buffer (current-buffer)))
9532     (setq gnus-newsgroup-active (gnus-activate-group group))
9533     (forward-line 1)
9534     (gnus-summary-goto-article (cdr group-art) nil t)
9535     (when edit
9536       (gnus-summary-edit-article))))
9537
9538 (defun gnus-summary-create-article ()
9539   "Create an article in a mail newsgroup."
9540   (interactive)
9541   (let ((group gnus-newsgroup-name)
9542         (now (current-time))
9543         group-art)
9544     (unless (gnus-check-backend-function 'request-accept-article group)
9545       (error "%s does not support article importing" group))
9546     (save-excursion
9547       (set-buffer (gnus-get-buffer-create " *import file*"))
9548       (erase-buffer)
9549       (goto-char (point-min))
9550       ;; This doesn't look like an article, so we fudge some headers.
9551       (insert "From: " (read-string "From: ") "\n"
9552               "Subject: " (read-string "Subject: ") "\n"
9553               "Date: " (message-make-date now) "\n"
9554               "Message-ID: " (message-make-message-id) "\n")
9555       (setq group-art (gnus-request-accept-article group nil t))
9556       (kill-buffer (current-buffer)))
9557     (setq gnus-newsgroup-active (gnus-activate-group group))
9558     (forward-line 1)
9559     (gnus-summary-goto-article (cdr group-art) nil t)
9560     (gnus-summary-edit-article)))
9561
9562 (defun gnus-summary-article-posted-p ()
9563   "Say whether the current (mail) article is available from news as well.
9564 This will be the case if the article has both been mailed and posted."
9565   (interactive)
9566   (let ((id (mail-header-references (gnus-summary-article-header)))
9567         (gnus-override-method (car (gnus-refer-article-methods))))
9568     (if (gnus-request-head id "")
9569         (gnus-message 2 "The current message was found on %s"
9570                       gnus-override-method)
9571       (gnus-message 2 "The current message couldn't be found on %s"
9572                     gnus-override-method)
9573       nil)))
9574
9575 (defun gnus-summary-expire-articles (&optional now)
9576   "Expire all articles that are marked as expirable in the current group."
9577   (interactive)
9578   (when (and (not gnus-group-is-exiting-without-update-p)
9579              (gnus-check-backend-function
9580               'request-expire-articles gnus-newsgroup-name))
9581     ;; This backend supports expiry.
9582     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
9583            (expirable (if total
9584                           (progn
9585                             ;; We need to update the info for
9586                             ;; this group for `gnus-list-of-read-articles'
9587                             ;; to give us the right answer.
9588                             (gnus-run-hooks 'gnus-exit-group-hook)
9589                             (gnus-summary-update-info)
9590                             (gnus-list-of-read-articles gnus-newsgroup-name))
9591                         (setq gnus-newsgroup-expirable
9592                               (sort gnus-newsgroup-expirable '<))))
9593            (expiry-wait (if now 'immediate
9594                           (gnus-group-find-parameter
9595                            gnus-newsgroup-name 'expiry-wait)))
9596            (nnmail-expiry-target
9597             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
9598                 nnmail-expiry-target))
9599            es)
9600       (when expirable
9601         ;; There are expirable articles in this group, so we run them
9602         ;; through the expiry process.
9603         (gnus-message 6 "Expiring articles...")
9604         (unless (gnus-check-group gnus-newsgroup-name)
9605           (error "Can't open server for %s" gnus-newsgroup-name))
9606         ;; The list of articles that weren't expired is returned.
9607         (save-excursion
9608           (if expiry-wait
9609               (let ((nnmail-expiry-wait-function nil)
9610                     (nnmail-expiry-wait expiry-wait))
9611                 (setq es (gnus-request-expire-articles
9612                           expirable gnus-newsgroup-name)))
9613             (setq es (gnus-request-expire-articles
9614                       expirable gnus-newsgroup-name)))
9615           (unless total
9616             (setq gnus-newsgroup-expirable es))
9617           ;; We go through the old list of expirable, and mark all
9618           ;; really expired articles as nonexistent.
9619           (unless (eq es expirable)     ;If nothing was expired, we don't mark.
9620             (let ((gnus-use-cache nil))
9621               (dolist (article expirable)
9622                 (when (and (not (memq article es))
9623                            (gnus-data-find article))
9624                   (gnus-summary-mark-article article gnus-canceled-mark)
9625                   (run-hook-with-args 'gnus-summary-article-expire-hook
9626                                       'delete
9627                                       (gnus-data-header
9628                                        (assoc article (gnus-data-list nil)))
9629                                       gnus-newsgroup-name
9630                                       nil
9631                                       nil))))))
9632         (gnus-message 6 "Expiring articles...done")))))
9633
9634 (defun gnus-summary-expire-articles-now ()
9635   "Expunge all expirable articles in the current group.
9636 This means that *all* articles that are marked as expirable will be
9637 deleted forever, right now."
9638   (interactive)
9639   (or gnus-expert-user
9640       (gnus-yes-or-no-p
9641        "Are you really, really, really sure you want to delete all these messages? ")
9642       (error "Phew!"))
9643   (gnus-summary-expire-articles t))
9644
9645 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
9646 (defun gnus-summary-delete-article (&optional n)
9647   "Delete the N next (mail) articles.
9648 This command actually deletes articles.  This is not a marking
9649 command.  The article will disappear forever from your life, never to
9650 return.
9651
9652 If N is negative, delete backwards.
9653 If N is nil and articles have been marked with the process mark,
9654 delete these instead.
9655
9656 If `gnus-novice-user' is non-nil you will be asked for
9657 confirmation before the articles are deleted."
9658   (interactive "P")
9659   (unless (gnus-check-backend-function 'request-expire-articles
9660                                        gnus-newsgroup-name)
9661     (error "The current newsgroup does not support article deletion"))
9662   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
9663     (error "Couldn't open server"))
9664   ;; Compute the list of articles to delete.
9665   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
9666         (nnmail-expiry-target 'delete)
9667         not-deleted)
9668     (if (and gnus-novice-user
9669              (not (gnus-yes-or-no-p
9670                    (format "Do you really want to delete %s forever? "
9671                            (if (> (length articles) 1)
9672                                (format "these %s articles" (length articles))
9673                              "this article")))))
9674         ()
9675       ;; Delete the articles.
9676       (setq not-deleted (gnus-request-expire-articles
9677                          articles gnus-newsgroup-name 'force))
9678       (while articles
9679         (gnus-summary-remove-process-mark (car articles))
9680         ;; The backend might not have been able to delete the article
9681         ;; after all.
9682         (unless (memq (car articles) not-deleted)
9683           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
9684         (let* ((article (car articles))
9685                (ghead  (gnus-data-header
9686                                     (assoc article (gnus-data-list nil)))))
9687           (run-hook-with-args 'gnus-summary-article-delete-hook
9688                               'delete ghead gnus-newsgroup-name nil
9689                               nil))
9690         (setq articles (cdr articles)))
9691       (when not-deleted
9692         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
9693     (gnus-summary-position-point)
9694     (gnus-set-mode-line 'summary)
9695     not-deleted))
9696
9697 (defun gnus-summary-edit-article (&optional force)
9698   "Edit the current article.
9699 This will have permanent effect only in mail groups.
9700 If FORCE is non-nil, allow editing of articles even in read-only
9701 groups."
9702   (interactive "P")
9703   (save-excursion
9704     (set-buffer gnus-summary-buffer)
9705     (let ((mail-parse-charset gnus-newsgroup-charset)
9706           (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
9707       (gnus-set-global-variables)
9708       (when (and (not force)
9709                  (gnus-group-read-only-p))
9710         (error "The current newsgroup does not support article editing"))
9711       (gnus-summary-show-article t)
9712       (gnus-article-edit-article
9713        'ignore
9714        `(lambda (no-highlight)
9715           (let ((mail-parse-charset ',gnus-newsgroup-charset)
9716                 (message-options message-options)
9717                 (message-options-set-recipient)
9718                 (mail-parse-ignored-charsets
9719                  ',gnus-newsgroup-ignored-charsets))
9720             (gnus-summary-edit-article-done
9721              ,(or (mail-header-references gnus-current-headers) "")
9722              ,(gnus-group-read-only-p) ,gnus-summary-buffer no-highlight)))))))
9723
9724 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
9725
9726 (defun gnus-summary-edit-article-done (&optional references read-only buffer
9727                                                  no-highlight)
9728   "Make edits to the current article permanent."
9729   (interactive)
9730   (save-excursion
9731     ;; The buffer restriction contains the entire article if it exists.
9732     (when (article-goto-body)
9733       (let ((lines (count-lines (point) (point-max)))
9734             (length (- (point-max) (point)))
9735             (case-fold-search t)
9736             (body (copy-marker (point))))
9737         (goto-char (point-min))
9738         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
9739           (delete-region (match-beginning 1) (match-end 1))
9740           (insert (number-to-string length)))
9741         (goto-char (point-min))
9742         (when (re-search-forward
9743                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
9744           (delete-region (match-beginning 1) (match-end 1))
9745           (insert (number-to-string length)))
9746         (goto-char (point-min))
9747         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
9748           (delete-region (match-beginning 1) (match-end 1))
9749           (insert (number-to-string lines))))))
9750   ;; Replace the article.
9751   (let ((buf (current-buffer)))
9752     (with-temp-buffer
9753       (insert-buffer-substring buf)
9754
9755       (if (and (not read-only)
9756                (not (gnus-request-replace-article
9757                      (cdr gnus-article-current) (car gnus-article-current)
9758                      (current-buffer) t)))
9759           (error "Couldn't replace article")
9760         ;; Update the summary buffer.
9761         (if (and references
9762                  (equal (message-tokenize-header references " ")
9763                         (message-tokenize-header
9764                          (or (message-fetch-field "references") "") " ")))
9765             ;; We only have to update this line.
9766             (save-excursion
9767               (save-restriction
9768                 (message-narrow-to-head)
9769                 (let ((head (buffer-string))
9770                       header)
9771                   (with-temp-buffer
9772                     (insert (format "211 %d Article retrieved.\n"
9773                                     (cdr gnus-article-current)))
9774                     (insert head)
9775                     (insert ".\n")
9776                     (let ((nntp-server-buffer (current-buffer)))
9777                       (setq header (car (gnus-get-newsgroup-headers
9778                                          nil t))))
9779                     (save-excursion
9780                       (set-buffer gnus-summary-buffer)
9781                       (gnus-data-set-header
9782                        (gnus-data-find (cdr gnus-article-current))
9783                        header)
9784                       (gnus-summary-update-article-line
9785                        (cdr gnus-article-current) header)
9786                       (if (gnus-summary-goto-subject
9787                            (cdr gnus-article-current) nil t)
9788                           (gnus-summary-update-secondary-mark
9789                            (cdr gnus-article-current))))))))
9790           ;; Update threads.
9791           (set-buffer (or buffer gnus-summary-buffer))
9792           (gnus-summary-update-article (cdr gnus-article-current))
9793           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9794               (gnus-summary-update-secondary-mark
9795                (cdr gnus-article-current))))
9796         ;; Prettify the article buffer again.
9797         (unless no-highlight
9798           (save-excursion
9799             (set-buffer gnus-article-buffer)
9800             ;;;!!! Fix this -- article should be rehighlighted.
9801             ;;;(gnus-run-hooks 'gnus-article-display-hook)
9802             (set-buffer gnus-original-article-buffer)
9803             (gnus-request-article
9804              (cdr gnus-article-current)
9805              (car gnus-article-current) (current-buffer))))
9806         ;; Prettify the summary buffer line.
9807         (when (gnus-visual-p 'summary-highlight 'highlight)
9808           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
9809
9810 (defun gnus-summary-edit-wash (key)
9811   "Perform editing command KEY in the article buffer."
9812   (interactive
9813    (list
9814     (progn
9815       (message "%s" (concat (this-command-keys) "- "))
9816       (read-char))))
9817   (message "")
9818   (gnus-summary-edit-article)
9819   (execute-kbd-macro (concat (this-command-keys) key))
9820   (gnus-article-edit-done))
9821
9822 ;;; Respooling
9823
9824 (defun gnus-summary-respool-query (&optional silent trace)
9825   "Query where the respool algorithm would put this article."
9826   (interactive)
9827   (let (gnus-mark-article-hook)
9828     (gnus-summary-select-article)
9829     (save-excursion
9830       (set-buffer gnus-original-article-buffer)
9831       (let ((groups (nnmail-article-group 'identity trace)))
9832         (unless silent
9833           (if groups
9834               (message "This message would go to %s"
9835                        (mapconcat 'car groups ", "))
9836             (message "This message would go to no groups"))
9837           groups)))))
9838
9839 (defun gnus-summary-respool-trace ()
9840   "Trace where the respool algorithm would put this article.
9841 Display a buffer showing all fancy splitting patterns which matched."
9842   (interactive)
9843   (gnus-summary-respool-query nil t))
9844
9845 ;; Summary marking commands.
9846
9847 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
9848   "Mark articles which has the same subject as read, and then select the next.
9849 If UNMARK is positive, remove any kind of mark.
9850 If UNMARK is negative, tick articles."
9851   (interactive "P")
9852   (when unmark
9853     (setq unmark (prefix-numeric-value unmark)))
9854   (let ((count
9855          (gnus-summary-mark-same-subject
9856           (gnus-summary-article-subject) unmark)))
9857     ;; Select next unread article.  If auto-select-same mode, should
9858     ;; select the first unread article.
9859     (gnus-summary-next-article t (and gnus-auto-select-same
9860                                       (gnus-summary-article-subject)))
9861     (gnus-message 7 "%d article%s marked as %s"
9862                   count (if (= count 1) " is" "s are")
9863                   (if unmark "unread" "read"))))
9864
9865 (defun gnus-summary-kill-same-subject (&optional unmark)
9866   "Mark articles which has the same subject as read.
9867 If UNMARK is positive, remove any kind of mark.
9868 If UNMARK is negative, tick articles."
9869   (interactive "P")
9870   (when unmark
9871     (setq unmark (prefix-numeric-value unmark)))
9872   (let ((count
9873          (gnus-summary-mark-same-subject
9874           (gnus-summary-article-subject) unmark)))
9875     ;; If marked as read, go to next unread subject.
9876     (when (null unmark)
9877       ;; Go to next unread subject.
9878       (gnus-summary-next-subject 1 t))
9879     (gnus-message 7 "%d articles are marked as %s"
9880                   count (if unmark "unread" "read"))))
9881
9882 (defun gnus-summary-mark-same-subject (subject &optional unmark)
9883   "Mark articles with same SUBJECT as read, and return marked number.
9884 If optional argument UNMARK is positive, remove any kinds of marks.
9885 If optional argument UNMARK is negative, mark articles as unread instead."
9886   (let ((count 1))
9887     (save-excursion
9888       (cond
9889        ((null unmark)                   ; Mark as read.
9890         (while (and
9891                 (progn
9892                   (gnus-summary-mark-article-as-read gnus-killed-mark)
9893                   (gnus-summary-show-thread) t)
9894                 (gnus-summary-find-subject subject))
9895           (setq count (1+ count))))
9896        ((> unmark 0)                    ; Tick.
9897         (while (and
9898                 (progn
9899                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
9900                   (gnus-summary-show-thread) t)
9901                 (gnus-summary-find-subject subject))
9902           (setq count (1+ count))))
9903        (t                               ; Mark as unread.
9904         (while (and
9905                 (progn
9906                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
9907                   (gnus-summary-show-thread) t)
9908                 (gnus-summary-find-subject subject))
9909           (setq count (1+ count)))))
9910       (gnus-set-mode-line 'summary)
9911       ;; Return the number of marked articles.
9912       count)))
9913
9914 (defun gnus-summary-mark-as-processable (n &optional unmark)
9915   "Set the process mark on the next N articles.
9916 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
9917 the process mark instead.  The difference between N and the actual
9918 number of articles marked is returned."
9919   (interactive "P")
9920   (if (and (null n) (gnus-region-active-p))
9921       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
9922     (setq n (prefix-numeric-value n))
9923     (let ((backward (< n 0))
9924           (n (abs n)))
9925       (while (and
9926               (> n 0)
9927               (if unmark
9928                   (gnus-summary-remove-process-mark
9929                    (gnus-summary-article-number))
9930                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
9931               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
9932         (setq n (1- n)))
9933       (when (/= 0 n)
9934         (gnus-message 7 "No more articles"))
9935       (gnus-summary-recenter)
9936       (gnus-summary-position-point)
9937       n)))
9938
9939 (defun gnus-summary-unmark-as-processable (n)
9940   "Remove the process mark from the next N articles.
9941 If N is negative, unmark backward instead.  The difference between N and
9942 the actual number of articles unmarked is returned."
9943   (interactive "P")
9944   (gnus-summary-mark-as-processable n t))
9945
9946 (defun gnus-summary-unmark-all-processable ()
9947   "Remove the process mark from all articles."
9948   (interactive)
9949   (save-excursion
9950     (while gnus-newsgroup-processable
9951       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
9952   (gnus-summary-position-point))
9953
9954 (defun gnus-summary-add-mark (article type)
9955   "Mark ARTICLE with a mark of TYPE."
9956   (let ((vtype (car (assq type gnus-article-mark-lists)))
9957         var)
9958     (if (not vtype)
9959         (error "No such mark type: %s" type)
9960       (setq var (intern (format "gnus-newsgroup-%s" type)))
9961       (set var (cons article (symbol-value var)))
9962       (if (memq type '(processable cached replied forwarded recent saved))
9963           (gnus-summary-update-secondary-mark article)
9964         ;;; !!! This is bogus.  We should find out what primary
9965         ;;; !!! mark we want to set.
9966         (gnus-summary-update-mark gnus-del-mark 'unread)))))
9967
9968 (defun gnus-summary-mark-as-expirable (n)
9969   "Mark N articles forward as expirable.
9970 If N is negative, mark backward instead.  The difference between N and
9971 the actual number of articles marked is returned."
9972   (interactive "p")
9973   (gnus-summary-mark-forward n gnus-expirable-mark))
9974
9975 (defun gnus-summary-mark-as-spam (n)
9976   "Mark N articles forward as spam.
9977 If N is negative, mark backward instead.  The difference between N and
9978 the actual number of articles marked is returned."
9979   (interactive "p")
9980   (gnus-summary-mark-forward n gnus-spam-mark))
9981
9982 (defun gnus-summary-mark-article-as-replied (article)
9983   "Mark ARTICLE as replied to and update the summary line.
9984 ARTICLE can also be a list of articles."
9985   (interactive (list (gnus-summary-article-number)))
9986   (let ((articles (if (listp article) article (list article))))
9987     (dolist (article articles)
9988       (unless (numberp article)
9989         (error "%s is not a number" article))
9990       (push article gnus-newsgroup-replied)
9991       (let ((buffer-read-only nil))
9992         (when (gnus-summary-goto-subject article nil t)
9993           (gnus-summary-update-secondary-mark article))))))
9994
9995 (defun gnus-summary-mark-article-as-forwarded (article)
9996   "Mark ARTICLE as forwarded and update the summary line.
9997 ARTICLE can also be a list of articles."
9998   (let ((articles (if (listp article) article (list article))))
9999     (dolist (article articles)
10000       (push article gnus-newsgroup-forwarded)
10001       (let ((buffer-read-only nil))
10002         (when (gnus-summary-goto-subject article nil t)
10003           (gnus-summary-update-secondary-mark article))))))
10004
10005 (defun gnus-summary-set-bookmark (article)
10006   "Set a bookmark in current article."
10007   (interactive (list (gnus-summary-article-number)))
10008   (when (or (not (get-buffer gnus-article-buffer))
10009             (not gnus-current-article)
10010             (not gnus-article-current)
10011             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10012     (error "No current article selected"))
10013   ;; Remove old bookmark, if one exists.
10014   (gnus-pull article gnus-newsgroup-bookmarks)
10015   ;; Set the new bookmark, which is on the form
10016   ;; (article-number . line-number-in-body).
10017   (push
10018    (cons article
10019          (with-current-buffer gnus-article-buffer
10020            (count-lines
10021             (min (point)
10022                  (save-excursion
10023                    (article-goto-body)
10024                    (point)))
10025             (point))))
10026    gnus-newsgroup-bookmarks)
10027   (gnus-message 6 "A bookmark has been added to the current article."))
10028
10029 (defun gnus-summary-remove-bookmark (article)
10030   "Remove the bookmark from the current article."
10031   (interactive (list (gnus-summary-article-number)))
10032   ;; Remove old bookmark, if one exists.
10033   (if (not (assq article gnus-newsgroup-bookmarks))
10034       (gnus-message 6 "No bookmark in current article.")
10035     (gnus-pull article gnus-newsgroup-bookmarks)
10036     (gnus-message 6 "Removed bookmark.")))
10037
10038 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10039 (defun gnus-summary-mark-as-dormant (n)
10040   "Mark N articles forward as dormant.
10041 If N is negative, mark backward instead.  The difference between N and
10042 the actual number of articles marked is returned."
10043   (interactive "p")
10044   (gnus-summary-mark-forward n gnus-dormant-mark))
10045
10046 (defun gnus-summary-set-process-mark (article)
10047   "Set the process mark on ARTICLE and update the summary line."
10048   (setq gnus-newsgroup-processable
10049         (cons article
10050               (delq article gnus-newsgroup-processable)))
10051   (when (gnus-summary-goto-subject article)
10052     (gnus-summary-show-thread)
10053     (gnus-summary-goto-subject article)
10054     (gnus-summary-update-secondary-mark article)))
10055
10056 (defun gnus-summary-remove-process-mark (&rest articles)
10057   "Remove the process mark from ARTICLES and update the summary line."
10058   (dolist (article articles)
10059     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10060     (when (gnus-summary-goto-subject article)
10061       (gnus-summary-show-thread)
10062       (gnus-summary-goto-subject article)
10063       (gnus-summary-update-secondary-mark article))))
10064
10065 (defun gnus-summary-set-saved-mark (article)
10066   "Set the process mark on ARTICLE and update the summary line."
10067   (push article gnus-newsgroup-saved)
10068   (when (gnus-summary-goto-subject article)
10069     (gnus-summary-update-secondary-mark article)))
10070
10071 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10072   "Mark N articles as read forwards.
10073 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10074 The difference between N and the actual number of articles marked is
10075 returned.
10076 If NO-EXPIRE, auto-expiry will be inhibited."
10077   (interactive "p")
10078   (gnus-summary-show-thread)
10079   (let ((backward (< n 0))
10080         (gnus-summary-goto-unread
10081          (and gnus-summary-goto-unread
10082               (not (eq gnus-summary-goto-unread 'never))
10083               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10084                                     gnus-ticked-mark gnus-dormant-mark)))))
10085         (n (abs n))
10086         (mark (or mark gnus-del-mark)))
10087     (while (and (> n 0)
10088                 (gnus-summary-mark-article nil mark no-expire)
10089                 (zerop (gnus-summary-next-subject
10090                         (if backward -1 1)
10091                         (and gnus-summary-goto-unread
10092                              (not (eq gnus-summary-goto-unread 'never)))
10093                         t)))
10094       (setq n (1- n)))
10095     (when (/= 0 n)
10096       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10097     (gnus-summary-recenter)
10098     (gnus-summary-position-point)
10099     (gnus-set-mode-line 'summary)
10100     n))
10101
10102 (defun gnus-summary-mark-article-as-read (mark)
10103   "Mark the current article quickly as read with MARK."
10104   (let ((article (gnus-summary-article-number)))
10105     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10106     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10107     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10108     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10109     (push (cons article mark) gnus-newsgroup-reads)
10110     ;; Possibly remove from cache, if that is used.
10111     (when gnus-use-cache
10112       (gnus-cache-enter-remove-article article))
10113     ;; Allow the backend to change the mark.
10114     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10115     ;; Check for auto-expiry.
10116     (when (and gnus-newsgroup-auto-expire
10117                (memq mark gnus-auto-expirable-marks))
10118       (setq mark gnus-expirable-mark)
10119       ;; Let the backend know about the mark change.
10120       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10121       (push article gnus-newsgroup-expirable))
10122     ;; Set the mark in the buffer.
10123     (gnus-summary-update-mark mark 'unread)
10124     t))
10125
10126 (defun gnus-summary-mark-article-as-unread (mark)
10127   "Mark the current article quickly as unread with MARK."
10128   (let* ((article (gnus-summary-article-number))
10129          (old-mark (gnus-summary-article-mark article)))
10130     ;; Allow the backend to change the mark.
10131     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10132     (if (eq mark old-mark)
10133         t
10134       (if (<= article 0)
10135           (progn
10136             (gnus-error 1 "Can't mark negative article numbers")
10137             nil)
10138         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10139         (setq gnus-newsgroup-spam-marked
10140               (delq article gnus-newsgroup-spam-marked))
10141         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10142         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10143         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10144         (cond ((= mark gnus-ticked-mark)
10145                (setq gnus-newsgroup-marked
10146                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10147                                               article)))
10148               ((= mark gnus-spam-mark)
10149                (setq gnus-newsgroup-spam-marked
10150                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10151                                               article)))
10152               ((= mark gnus-dormant-mark)
10153                (setq gnus-newsgroup-dormant
10154                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10155                                               article)))
10156               (t
10157                (setq gnus-newsgroup-unreads
10158                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10159                                               article))))
10160         (gnus-pull article gnus-newsgroup-reads)
10161
10162         ;; See whether the article is to be put in the cache.
10163         (and gnus-use-cache
10164              (vectorp (gnus-summary-article-header article))
10165              (save-excursion
10166                (gnus-cache-possibly-enter-article
10167                 gnus-newsgroup-name article
10168                 (gnus-summary-article-header article)
10169                 (= mark gnus-ticked-mark)
10170                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10171
10172         ;; Fix the mark.
10173         (gnus-summary-update-mark mark 'unread)
10174         t))))
10175
10176 (defun gnus-summary-mark-article (&optional article mark no-expire)
10177   "Mark ARTICLE with MARK.  MARK can be any character.
10178 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10179 `??' (dormant) and `?E' (expirable).
10180 If MARK is nil, then the default character `?r' is used.
10181 If ARTICLE is nil, then the article on the current line will be
10182 marked.
10183 If NO-EXPIRE, auto-expiry will be inhibited."
10184   ;; The mark might be a string.
10185   (when (stringp mark)
10186     (setq mark (aref mark 0)))
10187   ;; If no mark is given, then we check auto-expiring.
10188   (when (null mark)
10189     (setq mark gnus-del-mark))
10190   (when (and (not no-expire)
10191              gnus-newsgroup-auto-expire
10192              (memq mark gnus-auto-expirable-marks))
10193     (setq mark gnus-expirable-mark))
10194   (let ((article (or article (gnus-summary-article-number)))
10195         (old-mark (gnus-summary-article-mark article)))
10196     ;; Allow the backend to change the mark.
10197     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10198     (if (eq mark old-mark)
10199         t
10200       (unless article
10201         (error "No article on current line"))
10202       (if (not (if (or (= mark gnus-unread-mark)
10203                        (= mark gnus-ticked-mark)
10204                        (= mark gnus-spam-mark)
10205                        (= mark gnus-dormant-mark))
10206                    (gnus-mark-article-as-unread article mark)
10207                  (gnus-mark-article-as-read article mark)))
10208           t
10209         ;; See whether the article is to be put in the cache.
10210         (and gnus-use-cache
10211              (not (= mark gnus-canceled-mark))
10212              (vectorp (gnus-summary-article-header article))
10213              (save-excursion
10214                (gnus-cache-possibly-enter-article
10215                 gnus-newsgroup-name article
10216                 (gnus-summary-article-header article)
10217                 (= mark gnus-ticked-mark)
10218                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10219
10220         (when (gnus-summary-goto-subject article nil t)
10221           (let ((buffer-read-only nil))
10222             (gnus-summary-show-thread)
10223             ;; Fix the mark.
10224             (gnus-summary-update-mark mark 'unread)
10225             t))))))
10226
10227 (defun gnus-summary-update-secondary-mark (article)
10228   "Update the secondary (read, process, cache) mark."
10229   (gnus-summary-update-mark
10230    (cond ((memq article gnus-newsgroup-processable)
10231           gnus-process-mark)
10232          ((memq article gnus-newsgroup-cached)
10233           gnus-cached-mark)
10234          ((memq article gnus-newsgroup-replied)
10235           gnus-replied-mark)
10236          ((memq article gnus-newsgroup-forwarded)
10237           gnus-forwarded-mark)
10238          ((memq article gnus-newsgroup-saved)
10239           gnus-saved-mark)
10240          ((memq article gnus-newsgroup-recent)
10241           gnus-recent-mark)
10242          ((memq article gnus-newsgroup-unseen)
10243           gnus-unseen-mark)
10244          (t gnus-no-mark))
10245    'replied)
10246   (when (gnus-visual-p 'summary-highlight 'highlight)
10247     (gnus-run-hooks 'gnus-summary-update-hook))
10248   t)
10249
10250 (defun gnus-summary-update-download-mark (article)
10251   "Update the download mark."
10252   (gnus-summary-update-mark
10253    (cond ((memq article gnus-newsgroup-undownloaded)
10254           gnus-undownloaded-mark)
10255          (gnus-newsgroup-agentized
10256           gnus-downloaded-mark)
10257          (t
10258           gnus-no-mark))
10259    'download)
10260   (gnus-summary-update-line t)
10261   t)
10262
10263 (defun gnus-summary-update-mark (mark type)
10264   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10265         (buffer-read-only nil))
10266     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10267     (when forward
10268       (when (looking-at "\r")
10269         (incf forward))
10270       (when (<= (+ forward (point)) (point-max))
10271         ;; Go to the right position on the line.
10272         (goto-char (+ forward (point)))
10273         ;; Replace the old mark with the new mark.
10274         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10275         ;; Optionally update the marks by some user rule.
10276         (when (eq type 'unread)
10277           (gnus-data-set-mark
10278            (gnus-data-find (gnus-summary-article-number)) mark)
10279           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10280
10281 (defun gnus-mark-article-as-read (article &optional mark)
10282   "Enter ARTICLE in the pertinent lists and remove it from others."
10283   ;; Make the article expirable.
10284   (let ((mark (or mark gnus-del-mark)))
10285     (setq gnus-newsgroup-expirable
10286           (if (= mark gnus-expirable-mark)
10287               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10288             (delq article gnus-newsgroup-expirable)))
10289     ;; Remove from unread and marked lists.
10290     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10291     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10292     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10293     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10294     (push (cons article mark) gnus-newsgroup-reads)
10295     ;; Possibly remove from cache, if that is used.
10296     (when gnus-use-cache
10297       (gnus-cache-enter-remove-article article))
10298     t))
10299
10300 (defun gnus-mark-article-as-unread (article &optional mark)
10301   "Enter ARTICLE in the pertinent lists and remove it from others."
10302   (let ((mark (or mark gnus-ticked-mark)))
10303     (if (<= article 0)
10304         (progn
10305           (gnus-error 1 "Can't mark negative article numbers")
10306           nil)
10307       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10308             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10309             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10310             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10311             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10312
10313       ;; Unsuppress duplicates?
10314       (when gnus-suppress-duplicates
10315         (gnus-dup-unsuppress-article article))
10316
10317       (cond ((= mark gnus-ticked-mark)
10318              (setq gnus-newsgroup-marked
10319                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10320             ((= mark gnus-spam-mark)
10321              (setq gnus-newsgroup-spam-marked
10322                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10323                                             article)))
10324             ((= mark gnus-dormant-mark)
10325              (setq gnus-newsgroup-dormant
10326                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10327             (t
10328              (setq gnus-newsgroup-unreads
10329                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10330       (gnus-pull article gnus-newsgroup-reads)
10331       t)))
10332
10333 (defalias 'gnus-summary-mark-as-unread-forward
10334   'gnus-summary-tick-article-forward)
10335 (make-obsolete 'gnus-summary-mark-as-unread-forward
10336                'gnus-summary-tick-article-forward)
10337 (defun gnus-summary-tick-article-forward (n)
10338   "Tick N articles forwards.
10339 If N is negative, tick backwards instead.
10340 The difference between N and the number of articles ticked is returned."
10341   (interactive "p")
10342   (gnus-summary-mark-forward n gnus-ticked-mark))
10343
10344 (defalias 'gnus-summary-mark-as-unread-backward
10345   'gnus-summary-tick-article-backward)
10346 (make-obsolete 'gnus-summary-mark-as-unread-backward
10347                'gnus-summary-tick-article-backward)
10348 (defun gnus-summary-tick-article-backward (n)
10349   "Tick N articles backwards.
10350 The difference between N and the number of articles ticked is returned."
10351   (interactive "p")
10352   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10353
10354 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10355 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10356 (defun gnus-summary-tick-article (&optional article clear-mark)
10357   "Mark current article as unread.
10358 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10359 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10360   (interactive)
10361   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10362                                        gnus-ticked-mark)))
10363
10364 (defun gnus-summary-mark-as-read-forward (n)
10365   "Mark N articles as read forwards.
10366 If N is negative, mark backwards instead.
10367 The difference between N and the actual number of articles marked is
10368 returned."
10369   (interactive "p")
10370   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10371
10372 (defun gnus-summary-mark-as-read-backward (n)
10373   "Mark the N articles as read backwards.
10374 The difference between N and the actual number of articles marked is
10375 returned."
10376   (interactive "p")
10377   (gnus-summary-mark-forward
10378    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10379
10380 (defun gnus-summary-mark-as-read (&optional article mark)
10381   "Mark current article as read.
10382 ARTICLE specifies the article to be marked as read.
10383 MARK specifies a string to be inserted at the beginning of the line."
10384   (gnus-summary-mark-article article mark))
10385
10386 (defun gnus-summary-clear-mark-forward (n)
10387   "Clear marks from N articles forward.
10388 If N is negative, clear backward instead.
10389 The difference between N and the number of marks cleared is returned."
10390   (interactive "p")
10391   (gnus-summary-mark-forward n gnus-unread-mark))
10392
10393 (defun gnus-summary-clear-mark-backward (n)
10394   "Clear marks from N articles backward.
10395 The difference between N and the number of marks cleared is returned."
10396   (interactive "p")
10397   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10398
10399 (defun gnus-summary-mark-unread-as-read ()
10400   "Intended to be used by `gnus-summary-mark-article-hook'."
10401   (when (memq gnus-current-article gnus-newsgroup-unreads)
10402     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10403
10404 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10405   "Intended to be used by `gnus-summary-mark-article-hook'."
10406   (let ((mark (gnus-summary-article-mark)))
10407     (when (or (gnus-unread-mark-p mark)
10408               (gnus-read-mark-p mark))
10409       (gnus-summary-mark-article gnus-current-article
10410                                  (or new-mark gnus-read-mark)))))
10411
10412 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10413   "Intended to be used by `gnus-summary-mark-article-hook'."
10414   (let ((mark (gnus-summary-article-mark)))
10415     (when (or (gnus-unread-mark-p mark)
10416               (gnus-read-mark-p mark))
10417       (gnus-summary-mark-article (gnus-summary-article-number)
10418                                  (or new-mark gnus-read-mark)))))
10419
10420 (defun gnus-summary-mark-unread-as-ticked ()
10421   "Intended to be used by `gnus-summary-mark-article-hook'."
10422   (when (memq gnus-current-article gnus-newsgroup-unreads)
10423     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10424
10425 (defun gnus-summary-mark-region-as-read (point mark all)
10426   "Mark all unread articles between point and mark as read.
10427 If given a prefix, mark all articles between point and mark as read,
10428 even ticked and dormant ones."
10429   (interactive "r\nP")
10430   (save-excursion
10431     (let (article)
10432       (goto-char point)
10433       (beginning-of-line)
10434       (while (and
10435               (< (point) mark)
10436               (progn
10437                 (when (or all
10438                           (memq (setq article (gnus-summary-article-number))
10439                                 gnus-newsgroup-unreads))
10440                   (gnus-summary-mark-article article gnus-del-mark))
10441                 t)
10442               (gnus-summary-find-next))))))
10443
10444 (defun gnus-summary-mark-below (score mark)
10445   "Mark articles with score less than SCORE with MARK."
10446   (interactive "P\ncMark: ")
10447   (setq score (if score
10448                   (prefix-numeric-value score)
10449                 (or gnus-summary-default-score 0)))
10450   (save-excursion
10451     (set-buffer gnus-summary-buffer)
10452     (goto-char (point-min))
10453     (while
10454         (progn
10455           (and (< (gnus-summary-article-score) score)
10456                (gnus-summary-mark-article nil mark))
10457           (gnus-summary-find-next)))))
10458
10459 (defun gnus-summary-kill-below (&optional score)
10460   "Mark articles with score below SCORE as read."
10461   (interactive "P")
10462   (gnus-summary-mark-below score gnus-killed-mark))
10463
10464 (defun gnus-summary-clear-above (&optional score)
10465   "Clear all marks from articles with score above SCORE."
10466   (interactive "P")
10467   (gnus-summary-mark-above score gnus-unread-mark))
10468
10469 (defun gnus-summary-tick-above (&optional score)
10470   "Tick all articles with score above SCORE."
10471   (interactive "P")
10472   (gnus-summary-mark-above score gnus-ticked-mark))
10473
10474 (defun gnus-summary-mark-above (score mark)
10475   "Mark articles with score over SCORE with MARK."
10476   (interactive "P\ncMark: ")
10477   (setq score (if score
10478                   (prefix-numeric-value score)
10479                 (or gnus-summary-default-score 0)))
10480   (save-excursion
10481     (set-buffer gnus-summary-buffer)
10482     (goto-char (point-min))
10483     (while (and (progn
10484                   (when (> (gnus-summary-article-score) score)
10485                     (gnus-summary-mark-article nil mark))
10486                   t)
10487                 (gnus-summary-find-next)))))
10488
10489 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10490 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10491 (defun gnus-summary-limit-include-expunged (&optional no-error)
10492   "Display all the hidden articles that were expunged for low scores."
10493   (interactive)
10494   (let ((buffer-read-only nil))
10495     (let ((scored gnus-newsgroup-scored)
10496           headers h)
10497       (while scored
10498         (unless (gnus-summary-article-header (caar scored))
10499           (and (setq h (gnus-number-to-header (caar scored)))
10500                (< (cdar scored) gnus-summary-expunge-below)
10501                (push h headers)))
10502         (setq scored (cdr scored)))
10503       (if (not headers)
10504           (when (not no-error)
10505             (error "No expunged articles hidden"))
10506         (goto-char (point-min))
10507         (push gnus-newsgroup-limit gnus-newsgroup-limits)
10508         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
10509         (mapcar (lambda (x) (push (mail-header-number x)
10510                                   gnus-newsgroup-limit))
10511                 headers)
10512         (gnus-summary-prepare-unthreaded (nreverse headers))
10513         (goto-char (point-min))
10514         (gnus-summary-position-point)
10515         t))))
10516
10517 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
10518   "Mark all unread articles in this newsgroup as read.
10519 If prefix argument ALL is non-nil, ticked and dormant articles will
10520 also be marked as read.
10521 If QUIETLY is non-nil, no questions will be asked.
10522
10523 If TO-HERE is non-nil, it should be a point in the buffer.  All
10524 articles before (after, if REVERSE is set) this point will be marked
10525 as read.
10526
10527 Note that this function will only catch up the unread article
10528 in the current summary buffer limitation.
10529
10530 The number of articles marked as read is returned."
10531   (interactive "P")
10532   (prog1
10533       (save-excursion
10534         (when (or quietly
10535                   (not gnus-interactive-catchup) ;Without confirmation?
10536                   gnus-expert-user
10537                   (gnus-y-or-n-p
10538                    (if all
10539                        "Mark absolutely all articles as read? "
10540                      "Mark all unread articles as read? ")))
10541           (if (and not-mark
10542                    (not gnus-newsgroup-adaptive)
10543                    (not gnus-newsgroup-auto-expire)
10544                    (not gnus-suppress-duplicates)
10545                    (or (not gnus-use-cache)
10546                        (eq gnus-use-cache 'passive)))
10547               (progn
10548                 (when all
10549                   (setq gnus-newsgroup-marked nil
10550                         gnus-newsgroup-spam-marked nil
10551                         gnus-newsgroup-dormant nil))
10552                 (setq gnus-newsgroup-unreads
10553                       (gnus-sorted-nunion
10554                        (gnus-intersection gnus-newsgroup-unreads
10555                                           gnus-newsgroup-downloadable)
10556                        gnus-newsgroup-unfetched)))
10557             ;; We actually mark all articles as canceled, which we
10558             ;; have to do when using auto-expiry or adaptive scoring.
10559             (gnus-summary-show-all-threads)
10560             (if (and to-here reverse)
10561                 (progn
10562                   (goto-char to-here)
10563                   (gnus-summary-mark-current-read-and-unread-as-read
10564                    gnus-catchup-mark)
10565                   (while (gnus-summary-find-next (not all))
10566                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
10567               (when (gnus-summary-first-subject (not all))
10568                 (while (and
10569                         (if to-here (< (point) to-here) t)
10570                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
10571                         (gnus-summary-find-next (not all))))))
10572             (gnus-set-mode-line 'summary))
10573           t))
10574     (gnus-summary-position-point)))
10575
10576 (defun gnus-summary-catchup-to-here (&optional all)
10577   "Mark all unticked articles before the current one as read.
10578 If ALL is non-nil, also mark ticked and dormant articles as read."
10579   (interactive "P")
10580   (save-excursion
10581     (gnus-save-hidden-threads
10582       (let ((beg (point)))
10583         ;; We check that there are unread articles.
10584         (when (or all (gnus-summary-find-prev))
10585           (gnus-summary-catchup all t beg)))))
10586   (gnus-summary-position-point))
10587
10588 (defun gnus-summary-catchup-from-here (&optional all)
10589   "Mark all unticked articles after (and including) the current one as read.
10590 If ALL is non-nil, also mark ticked and dormant articles as read."
10591   (interactive "P")
10592   (save-excursion
10593     (gnus-save-hidden-threads
10594       (let ((beg (point)))
10595         ;; We check that there are unread articles.
10596         (when (or all (gnus-summary-find-next))
10597           (gnus-summary-catchup all t beg nil t)))))
10598   (gnus-summary-position-point))
10599
10600 (defun gnus-summary-catchup-all (&optional quietly)
10601   "Mark all articles in this newsgroup as read.
10602 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
10603 instead, which marks only unread articles as read."
10604   (interactive "P")
10605   (gnus-summary-catchup t quietly))
10606
10607 (defun gnus-summary-catchup-and-exit (&optional all quietly)
10608   "Mark all unread articles in this group as read, then exit.
10609 If prefix argument ALL is non-nil, all articles are marked as read.
10610 If QUIETLY is non-nil, no questions will be asked."
10611   (interactive "P")
10612   (when (gnus-summary-catchup all quietly nil 'fast)
10613     ;; Select next newsgroup or exit.
10614     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
10615              (eq gnus-auto-select-next 'quietly))
10616         (gnus-summary-next-group nil)
10617       (gnus-summary-exit))))
10618
10619 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
10620   "Mark all articles in this newsgroup as read, and then exit.
10621 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
10622 instead, which marks only unread articles as read."
10623   (interactive "P")
10624   (gnus-summary-catchup-and-exit t quietly))
10625
10626 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
10627   "Mark all articles in this group as read and select the next group.
10628 If given a prefix, mark all articles, unread as well as ticked, as
10629 read."
10630   (interactive "P")
10631   (save-excursion
10632     (gnus-summary-catchup all))
10633   (gnus-summary-next-group))
10634
10635 ;;;
10636 ;;; with article
10637 ;;;
10638
10639 (defmacro gnus-with-article (article &rest forms)
10640   "Select ARTICLE and perform FORMS in the original article buffer.
10641 Then replace the article with the result."
10642   `(progn
10643      ;; We don't want the article to be marked as read.
10644      (let (gnus-mark-article-hook)
10645        (gnus-summary-select-article t t nil ,article))
10646      (set-buffer gnus-original-article-buffer)
10647      ,@forms
10648      (if (not (gnus-check-backend-function
10649                'request-replace-article (car gnus-article-current)))
10650          (gnus-message 5 "Read-only group; not replacing")
10651        (unless (gnus-request-replace-article
10652                 ,article (car gnus-article-current)
10653                 (current-buffer) t)
10654          (error "Couldn't replace article")))
10655      ;; The cache and backlog have to be flushed somewhat.
10656      (when gnus-keep-backlog
10657        (gnus-backlog-remove-article
10658         (car gnus-article-current) (cdr gnus-article-current)))
10659      (when gnus-use-cache
10660        (gnus-cache-update-article
10661         (car gnus-article-current) (cdr gnus-article-current)))))
10662
10663 (put 'gnus-with-article 'lisp-indent-function 1)
10664 (put 'gnus-with-article 'edebug-form-spec '(form body))
10665
10666 ;; Thread-based commands.
10667
10668 (defun gnus-summary-articles-in-thread (&optional article)
10669   "Return a list of all articles in the current thread.
10670 If ARTICLE is non-nil, return all articles in the thread that starts
10671 with that article."
10672   (let* ((article (or article (gnus-summary-article-number)))
10673          (data (gnus-data-find-list article))
10674          (top-level (gnus-data-level (car data)))
10675          (top-subject
10676           (cond ((null gnus-thread-operation-ignore-subject)
10677                  (gnus-simplify-subject-re
10678                   (mail-header-subject (gnus-data-header (car data)))))
10679                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
10680                  (gnus-simplify-subject-fuzzy
10681                   (mail-header-subject (gnus-data-header (car data)))))
10682                 (t nil)))
10683          (end-point (save-excursion
10684                       (if (gnus-summary-go-to-next-thread)
10685                           (point) (point-max))))
10686          articles)
10687     (while (and data
10688                 (< (gnus-data-pos (car data)) end-point))
10689       (when (or (not top-subject)
10690                 (string= top-subject
10691                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
10692                              (gnus-simplify-subject-fuzzy
10693                               (mail-header-subject
10694                                (gnus-data-header (car data))))
10695                            (gnus-simplify-subject-re
10696                             (mail-header-subject
10697                              (gnus-data-header (car data)))))))
10698         (push (gnus-data-number (car data)) articles))
10699       (unless (and (setq data (cdr data))
10700                    (> (gnus-data-level (car data)) top-level))
10701         (setq data nil)))
10702     ;; Return the list of articles.
10703     (nreverse articles)))
10704
10705 (defun gnus-summary-rethread-current ()
10706   "Rethread the thread the current article is part of."
10707   (interactive)
10708   (let* ((gnus-show-threads t)
10709          (article (gnus-summary-article-number))
10710          (id (mail-header-id (gnus-summary-article-header)))
10711          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
10712     (unless id
10713       (error "No article on the current line"))
10714     (gnus-rebuild-thread id)
10715     (gnus-summary-goto-subject article)))
10716
10717 (defun gnus-summary-reparent-thread ()
10718   "Make the current article child of the marked (or previous) article.
10719
10720 Note that the re-threading will only work if `gnus-thread-ignore-subject'
10721 is non-nil or the Subject: of both articles are the same."
10722   (interactive)
10723   (unless (not (gnus-group-read-only-p))
10724     (error "The current newsgroup does not support article editing"))
10725   (unless (<= (length gnus-newsgroup-processable) 1)
10726     (error "No more than one article may be marked"))
10727   (save-window-excursion
10728     (let ((gnus-article-buffer " *reparent*")
10729           (current-article (gnus-summary-article-number))
10730           ;; First grab the marked article, otherwise one line up.
10731           (parent-article (if (not (null gnus-newsgroup-processable))
10732                               (car gnus-newsgroup-processable)
10733                             (save-excursion
10734                               (if (eq (forward-line -1) 0)
10735                                   (gnus-summary-article-number)
10736                                 (error "Beginning of summary buffer"))))))
10737       (unless (not (eq current-article parent-article))
10738         (error "An article may not be self-referential"))
10739       (let ((message-id (mail-header-id
10740                          (gnus-summary-article-header parent-article))))
10741         (unless (and message-id (not (equal message-id "")))
10742           (error "No message-id in desired parent"))
10743         (gnus-with-article current-article
10744           (save-restriction
10745             (goto-char (point-min))
10746             (message-narrow-to-head)
10747             (if (re-search-forward "^References: " nil t)
10748                 (progn
10749                   (re-search-forward "^[^ \t]" nil t)
10750                   (forward-line -1)
10751                   (end-of-line)
10752                   (insert " " message-id))
10753               (insert "References: " message-id "\n"))))
10754         (set-buffer gnus-summary-buffer)
10755         (gnus-summary-unmark-all-processable)
10756         (gnus-summary-update-article current-article)
10757         (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10758             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
10759         (gnus-summary-rethread-current)
10760         (gnus-message 3 "Article %d is now the child of article %d"
10761                       current-article parent-article)))))
10762
10763 (defun gnus-summary-toggle-threads (&optional arg)
10764   "Toggle showing conversation threads.
10765 If ARG is positive number, turn showing conversation threads on."
10766   (interactive "P")
10767   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
10768     (setq gnus-show-threads
10769           (if (null arg) (not gnus-show-threads)
10770             (> (prefix-numeric-value arg) 0)))
10771     (gnus-summary-prepare)
10772     (gnus-summary-goto-subject current)
10773     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
10774     (gnus-summary-position-point)))
10775
10776 (defun gnus-summary-show-all-threads ()
10777   "Show all threads."
10778   (interactive)
10779   (save-excursion
10780     (let ((buffer-read-only nil))
10781       (subst-char-in-region (point-min) (point-max) ?\^M ?\n t)))
10782   (gnus-summary-position-point))
10783
10784 (defun gnus-summary-show-thread ()
10785   "Show thread subtrees.
10786 Returns nil if no thread was there to be shown."
10787   (interactive)
10788   (let ((buffer-read-only nil)
10789         (orig (point))
10790         (end (point-at-eol))
10791         ;; Leave point at bol
10792         (beg (progn (beginning-of-line) (point))))
10793     (prog1
10794         ;; Any hidden lines here?
10795         (search-forward "\r" end t)
10796       (subst-char-in-region beg end ?\^M ?\n t)
10797       (goto-char orig)
10798       (gnus-summary-position-point))))
10799
10800 (defun gnus-summary-maybe-hide-threads ()
10801   "If requested, hide the threads that should be hidden."
10802   (when (and gnus-show-threads
10803              gnus-thread-hide-subtree)
10804     (gnus-summary-hide-all-threads
10805      (if (or (consp gnus-thread-hide-subtree)
10806              (functionp gnus-thread-hide-subtree))
10807          (gnus-make-predicate gnus-thread-hide-subtree)
10808        nil))))
10809
10810 ;;; Hiding predicates.
10811
10812 (defun gnus-article-unread-p (header)
10813   (memq (mail-header-number header) gnus-newsgroup-unreads))
10814
10815 (defun gnus-article-unseen-p (header)
10816   (memq (mail-header-number header) gnus-newsgroup-unseen))
10817
10818 (defun gnus-map-articles (predicate articles)
10819   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
10820   (apply 'gnus-or (mapcar predicate
10821                           (mapcar 'gnus-summary-article-header articles))))
10822
10823 (defun gnus-summary-hide-all-threads (&optional predicate)
10824   "Hide all thread subtrees.
10825 If PREDICATE is supplied, threads that satisfy this predicate
10826 will not be hidden."
10827   (interactive)
10828   (save-excursion
10829     (goto-char (point-min))
10830     (let ((end nil))
10831       (while (not end)
10832         (when (or (not predicate)
10833                   (gnus-map-articles
10834                    predicate (gnus-summary-article-children)))
10835             (gnus-summary-hide-thread))
10836         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
10837   (gnus-summary-position-point))
10838
10839 (defun gnus-summary-hide-thread ()
10840   "Hide thread subtrees.
10841 If PREDICATE is supplied, threads that satisfy this predicate
10842 will not be hidden.
10843 Returns nil if no threads were there to be hidden."
10844   (interactive)
10845   (let ((buffer-read-only nil)
10846         (start (point))
10847         (article (gnus-summary-article-number)))
10848     (goto-char start)
10849     ;; Go forward until either the buffer ends or the subthread
10850     ;; ends.
10851     (when (and (not (eobp))
10852                (or (zerop (gnus-summary-next-thread 1 t))
10853                    (goto-char (point-max))))
10854       (prog1
10855           (if (and (> (point) start)
10856                    (search-backward "\n" start t))
10857               (progn
10858                 (subst-char-in-region start (point) ?\n ?\^M)
10859                 (gnus-summary-goto-subject article))
10860             (goto-char start)
10861             nil)))))
10862
10863 (defun gnus-summary-go-to-next-thread (&optional previous)
10864   "Go to the same level (or less) next thread.
10865 If PREVIOUS is non-nil, go to previous thread instead.
10866 Return the article number moved to, or nil if moving was impossible."
10867   (let ((level (gnus-summary-thread-level))
10868         (way (if previous -1 1))
10869         (beg (point)))
10870     (forward-line way)
10871     (while (and (not (eobp))
10872                 (< level (gnus-summary-thread-level)))
10873       (forward-line way))
10874     (if (eobp)
10875         (progn
10876           (goto-char beg)
10877           nil)
10878       (setq beg (point))
10879       (prog1
10880           (gnus-summary-article-number)
10881         (goto-char beg)))))
10882
10883 (defun gnus-summary-next-thread (n &optional silent)
10884   "Go to the same level next N'th thread.
10885 If N is negative, search backward instead.
10886 Returns the difference between N and the number of skips actually
10887 done.
10888
10889 If SILENT, don't output messages."
10890   (interactive "p")
10891   (let ((backward (< n 0))
10892         (n (abs n)))
10893     (while (and (> n 0)
10894                 (gnus-summary-go-to-next-thread backward))
10895       (decf n))
10896     (unless silent
10897       (gnus-summary-position-point))
10898     (when (and (not silent) (/= 0 n))
10899       (gnus-message 7 "No more threads"))
10900     n))
10901
10902 (defun gnus-summary-prev-thread (n)
10903   "Go to the same level previous N'th thread.
10904 Returns the difference between N and the number of skips actually
10905 done."
10906   (interactive "p")
10907   (gnus-summary-next-thread (- n)))
10908
10909 (defun gnus-summary-go-down-thread ()
10910   "Go down one level in the current thread."
10911   (let ((children (gnus-summary-article-children)))
10912     (when children
10913       (gnus-summary-goto-subject (car children)))))
10914
10915 (defun gnus-summary-go-up-thread ()
10916   "Go up one level in the current thread."
10917   (let ((parent (gnus-summary-article-parent)))
10918     (when parent
10919       (gnus-summary-goto-subject parent))))
10920
10921 (defun gnus-summary-down-thread (n)
10922   "Go down thread N steps.
10923 If N is negative, go up instead.
10924 Returns the difference between N and how many steps down that were
10925 taken."
10926   (interactive "p")
10927   (let ((up (< n 0))
10928         (n (abs n)))
10929     (while (and (> n 0)
10930                 (if up (gnus-summary-go-up-thread)
10931                   (gnus-summary-go-down-thread)))
10932       (setq n (1- n)))
10933     (gnus-summary-position-point)
10934     (when (/= 0 n)
10935       (gnus-message 7 "Can't go further"))
10936     n))
10937
10938 (defun gnus-summary-up-thread (n)
10939   "Go up thread N steps.
10940 If N is negative, go down instead.
10941 Returns the difference between N and how many steps down that were
10942 taken."
10943   (interactive "p")
10944   (gnus-summary-down-thread (- n)))
10945
10946 (defun gnus-summary-top-thread ()
10947   "Go to the top of the thread."
10948   (interactive)
10949   (while (gnus-summary-go-up-thread))
10950   (gnus-summary-article-number))
10951
10952 (defun gnus-summary-kill-thread (&optional unmark)
10953   "Mark articles under current thread as read.
10954 If the prefix argument is positive, remove any kinds of marks.
10955 If the prefix argument is negative, tick articles instead."
10956   (interactive "P")
10957   (when unmark
10958     (setq unmark (prefix-numeric-value unmark)))
10959   (let ((articles (gnus-summary-articles-in-thread)))
10960     (save-excursion
10961       ;; Expand the thread.
10962       (gnus-summary-show-thread)
10963       ;; Mark all the articles.
10964       (while articles
10965         (gnus-summary-goto-subject (car articles))
10966         (cond ((null unmark)
10967                (gnus-summary-mark-article-as-read gnus-killed-mark))
10968               ((> unmark 0)
10969                (gnus-summary-mark-article-as-unread gnus-unread-mark))
10970               (t
10971                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
10972         (setq articles (cdr articles))))
10973     ;; Hide killed subtrees.
10974     (and (null unmark)
10975          gnus-thread-hide-killed
10976          (gnus-summary-hide-thread))
10977     ;; If marked as read, go to next unread subject.
10978     (when (null unmark)
10979       ;; Go to next unread subject.
10980       (gnus-summary-next-subject 1 t)))
10981   (gnus-set-mode-line 'summary))
10982
10983 ;; Summary sorting commands
10984
10985 (defun gnus-summary-sort-by-number (&optional reverse)
10986   "Sort the summary buffer by article number.
10987 Argument REVERSE means reverse order."
10988   (interactive "P")
10989   (gnus-summary-sort 'number reverse))
10990
10991 (defun gnus-summary-sort-by-random (&optional reverse)
10992   "Randomize the order in the summary buffer.
10993 Argument REVERSE means to randomize in reverse order."
10994   (interactive "P")
10995   (gnus-summary-sort 'random reverse))
10996
10997 (defun gnus-summary-sort-by-author (&optional reverse)
10998   "Sort the summary buffer by author name alphabetically.
10999 If `case-fold-search' is non-nil, case of letters is ignored.
11000 Argument REVERSE means reverse order."
11001   (interactive "P")
11002   (gnus-summary-sort 'author reverse))
11003
11004 (defun gnus-summary-sort-by-recipient (&optional reverse)
11005   "Sort the summary buffer by recipient name alphabetically.
11006 If `case-fold-search' is non-nil, case of letters is ignored.
11007 Argument REVERSE means reverse order."
11008   (interactive "P")
11009   (gnus-summary-sort 'recipient reverse))
11010
11011 (defun gnus-summary-sort-by-subject (&optional reverse)
11012   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11013 If `case-fold-search' is non-nil, case of letters is ignored.
11014 Argument REVERSE means reverse order."
11015   (interactive "P")
11016   (gnus-summary-sort 'subject reverse))
11017
11018 (defun gnus-summary-sort-by-date (&optional reverse)
11019   "Sort the summary buffer by date.
11020 Argument REVERSE means reverse order."
11021   (interactive "P")
11022   (gnus-summary-sort 'date reverse))
11023
11024 (defun gnus-summary-sort-by-score (&optional reverse)
11025   "Sort the summary buffer by score.
11026 Argument REVERSE means reverse order."
11027   (interactive "P")
11028   (gnus-summary-sort 'score reverse))
11029
11030 (defun gnus-summary-sort-by-lines (&optional reverse)
11031   "Sort the summary buffer by the number of lines.
11032 Argument REVERSE means reverse order."
11033   (interactive "P")
11034   (gnus-summary-sort 'lines reverse))
11035
11036 (defun gnus-summary-sort-by-chars (&optional reverse)
11037   "Sort the summary buffer by article length.
11038 Argument REVERSE means reverse order."
11039   (interactive "P")
11040   (gnus-summary-sort 'chars reverse))
11041
11042 (defun gnus-summary-sort-by-original (&optional reverse)
11043   "Sort the summary buffer using the default sorting method.
11044 Argument REVERSE means reverse order."
11045   (interactive "P")
11046   (let* ((buffer-read-only)
11047          (gnus-summary-prepare-hook nil))
11048     ;; We do the sorting by regenerating the threads.
11049     (gnus-summary-prepare)
11050     ;; Hide subthreads if needed.
11051     (gnus-summary-maybe-hide-threads)))
11052
11053 (defun gnus-summary-sort (predicate reverse)
11054   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11055   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11056          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11057          (gnus-thread-sort-functions
11058           (if (not reverse)
11059               thread
11060             `(lambda (t1 t2)
11061                (,thread t2 t1))))
11062          (gnus-sort-gathered-threads-function
11063           gnus-thread-sort-functions)
11064          (gnus-article-sort-functions
11065           (if (not reverse)
11066               article
11067             `(lambda (t1 t2)
11068                (,article t2 t1))))
11069          (buffer-read-only)
11070          (gnus-summary-prepare-hook nil))
11071     ;; We do the sorting by regenerating the threads.
11072     (gnus-summary-prepare)
11073     ;; Hide subthreads if needed.
11074     (gnus-summary-maybe-hide-threads)))
11075
11076 ;; Summary saving commands.
11077
11078 (defun gnus-summary-save-article (&optional n not-saved)
11079   "Save the current article using the default saver function.
11080 If N is a positive number, save the N next articles.
11081 If N is a negative number, save the N previous articles.
11082 If N is nil and any articles have been marked with the process mark,
11083 save those articles instead.
11084 The variable `gnus-default-article-saver' specifies the saver function."
11085   (interactive "P")
11086   (let* ((articles (gnus-summary-work-articles n))
11087          (save-buffer (save-excursion
11088                         (nnheader-set-temp-buffer " *Gnus Save*")))
11089          (num (length articles))
11090          header file)
11091     (dolist (article articles)
11092       (setq header (gnus-summary-article-header article))
11093       (if (not (vectorp header))
11094           ;; This is a pseudo-article.
11095           (if (assq 'name header)
11096               (gnus-copy-file (cdr (assq 'name header)))
11097             (gnus-message 1 "Article %d is unsaveable" article))
11098         ;; This is a real article.
11099         (save-window-excursion
11100           (let ((gnus-display-mime-function nil)
11101                 (gnus-article-prepare-hook nil))
11102             (gnus-summary-select-article t nil nil article)))
11103         (save-excursion
11104           (set-buffer save-buffer)
11105           (erase-buffer)
11106           (insert-buffer-substring gnus-original-article-buffer))
11107         (setq file (gnus-article-save save-buffer file num))
11108         (gnus-summary-remove-process-mark article)
11109         (unless not-saved
11110           (gnus-summary-set-saved-mark article))))
11111     (gnus-kill-buffer save-buffer)
11112     (gnus-summary-position-point)
11113     (gnus-set-mode-line 'summary)
11114     n))
11115
11116 (defun gnus-summary-pipe-output (&optional arg headers)
11117   "Pipe the current article to a subprocess.
11118 If N is a positive number, pipe the N next articles.
11119 If N is a negative number, pipe the N previous articles.
11120 If N is nil and any articles have been marked with the process mark,
11121 pipe those articles instead.
11122 If HEADERS (the symbolic prefix), include the headers, too."
11123   (interactive (gnus-interactive "P\ny"))
11124   (require 'gnus-art)
11125   (let ((gnus-default-article-saver 'gnus-summary-save-in-pipe)
11126         (gnus-save-all-headers (or headers gnus-save-all-headers)))
11127     (gnus-summary-save-article arg t))
11128   (let ((buffer (get-buffer "*Shell Command Output*")))
11129     (when (and buffer
11130                (not (zerop (buffer-size buffer))))
11131       (gnus-configure-windows 'pipe))))
11132
11133 (defun gnus-summary-save-article-mail (&optional arg)
11134   "Append the current article to an mail file.
11135 If N is a positive number, save the N next articles.
11136 If N is a negative number, save the N previous articles.
11137 If N is nil and any articles have been marked with the process mark,
11138 save those articles instead."
11139   (interactive "P")
11140   (require 'gnus-art)
11141   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11142     (gnus-summary-save-article arg)))
11143
11144 (defun gnus-summary-save-article-rmail (&optional arg)
11145   "Append the current article to an rmail file.
11146 If N is a positive number, save the N next articles.
11147 If N is a negative number, save the N previous articles.
11148 If N is nil and any articles have been marked with the process mark,
11149 save those articles instead."
11150   (interactive "P")
11151   (require 'gnus-art)
11152   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11153     (gnus-summary-save-article arg)))
11154
11155 (defun gnus-summary-save-article-file (&optional arg)
11156   "Append the current article to a file.
11157 If N is a positive number, save the N next articles.
11158 If N is a negative number, save the N previous articles.
11159 If N is nil and any articles have been marked with the process mark,
11160 save those articles instead."
11161   (interactive "P")
11162   (require 'gnus-art)
11163   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11164     (gnus-summary-save-article arg)))
11165
11166 (defun gnus-summary-write-article-file (&optional arg)
11167   "Write the current article to a file, deleting the previous file.
11168 If N is a positive number, save the N next articles.
11169 If N is a negative number, save the N previous articles.
11170 If N is nil and any articles have been marked with the process mark,
11171 save those articles instead."
11172   (interactive "P")
11173   (require 'gnus-art)
11174   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11175     (gnus-summary-save-article arg)))
11176
11177 (defun gnus-summary-save-article-body-file (&optional arg)
11178   "Append the current article body to a file.
11179 If N is a positive number, save the N next articles.
11180 If N is a negative number, save the N previous articles.
11181 If N is nil and any articles have been marked with the process mark,
11182 save those articles instead."
11183   (interactive "P")
11184   (require 'gnus-art)
11185   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11186     (gnus-summary-save-article arg)))
11187
11188 (defun gnus-summary-muttprint (&optional arg)
11189   "Print the current article using Muttprint.
11190 If N is a positive number, save the N next articles.
11191 If N is a negative number, save the N previous articles.
11192 If N is nil and any articles have been marked with the process mark,
11193 save those articles instead."
11194   (interactive "P")
11195   (require 'gnus-art)
11196   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11197     (gnus-summary-save-article arg t)))
11198
11199 (defun gnus-summary-pipe-message (program)
11200   "Pipe the current article through PROGRAM."
11201   (interactive "sProgram: ")
11202   (gnus-summary-select-article)
11203   (let ((mail-header-separator ""))
11204     (gnus-eval-in-buffer-window gnus-article-buffer
11205       (save-restriction
11206         (widen)
11207         (let ((start (window-start))
11208               buffer-read-only)
11209           (message-pipe-buffer-body program)
11210           (set-window-start (get-buffer-window (current-buffer)) start))))))
11211
11212 (defun gnus-get-split-value (methods)
11213   "Return a value based on the split METHODS."
11214   (let (split-name method result match)
11215     (when methods
11216       (save-excursion
11217         (set-buffer gnus-original-article-buffer)
11218         (save-restriction
11219           (nnheader-narrow-to-headers)
11220           (while (and methods (not split-name))
11221             (goto-char (point-min))
11222             (setq method (pop methods))
11223             (setq match (car method))
11224             (when (cond
11225                    ((stringp match)
11226                     ;; Regular expression.
11227                     (ignore-errors
11228                       (re-search-forward match nil t)))
11229                    ((functionp match)
11230                     ;; Function.
11231                     (save-restriction
11232                       (widen)
11233                       (setq result (funcall match gnus-newsgroup-name))))
11234                    ((consp match)
11235                     ;; Form.
11236                     (save-restriction
11237                       (widen)
11238                       (setq result (eval match)))))
11239               (setq split-name (cdr method))
11240               (cond ((stringp result)
11241                      (push (expand-file-name
11242                             result gnus-article-save-directory)
11243                            split-name))
11244                     ((consp result)
11245                      (setq split-name (append result split-name)))))))))
11246     (nreverse split-name)))
11247
11248 (defun gnus-valid-move-group-p (group)
11249   (and (boundp group)
11250        (symbol-name group)
11251        (symbol-value group)
11252        (gnus-get-function (gnus-find-method-for-group
11253                            (symbol-name group)) 'request-accept-article t)))
11254
11255 (defun gnus-read-move-group-name (prompt default articles prefix)
11256   "Read a group name."
11257   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11258          (minibuffer-confirm-incomplete nil) ; XEmacs
11259          (prom
11260           (format "%s %s to:"
11261                   prompt
11262                   (if (> (length articles) 1)
11263                       (format "these %d articles" (length articles))
11264                     "this article")))
11265          (to-newsgroup
11266           (cond
11267            ((null split-name)
11268             (gnus-completing-read-with-default
11269              default prom
11270              gnus-active-hashtb
11271              'gnus-valid-move-group-p
11272              nil prefix
11273              'gnus-group-history))
11274            ((= 1 (length split-name))
11275             (gnus-completing-read-with-default
11276              (car split-name) prom
11277              gnus-active-hashtb
11278              'gnus-valid-move-group-p
11279              nil nil
11280              'gnus-group-history))
11281            (t
11282             (gnus-completing-read-with-default
11283              nil prom
11284              (mapcar 'list (nreverse split-name))
11285              nil nil nil
11286              'gnus-group-history))))
11287          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup))))
11288     (when to-newsgroup
11289       (if (or (string= to-newsgroup "")
11290               (string= to-newsgroup prefix))
11291           (setq to-newsgroup default))
11292       (unless to-newsgroup
11293         (error "No group name entered"))
11294       (or (gnus-active to-newsgroup)
11295           (gnus-activate-group to-newsgroup nil nil to-method)
11296           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11297                                      to-newsgroup))
11298               (or (and (gnus-request-create-group to-newsgroup to-method)
11299                        (gnus-activate-group
11300                         to-newsgroup nil nil to-method)
11301                        (gnus-subscribe-group to-newsgroup))
11302                   (error "Couldn't create group %s" to-newsgroup)))
11303           (error "No such group: %s" to-newsgroup)))
11304     to-newsgroup))
11305
11306 (defun gnus-summary-save-parts (type dir n &optional reverse)
11307   "Save parts matching TYPE to DIR.
11308 If REVERSE, save parts that do not match TYPE."
11309   (interactive
11310    (list (read-string "Save parts of type: "
11311                       (or (car gnus-summary-save-parts-type-history)
11312                           gnus-summary-save-parts-default-mime)
11313                       'gnus-summary-save-parts-type-history)
11314          (setq gnus-summary-save-parts-last-directory
11315                (read-file-name "Save to directory: "
11316                                gnus-summary-save-parts-last-directory
11317                                nil t))
11318          current-prefix-arg))
11319   (gnus-summary-iterate n
11320     (let ((gnus-display-mime-function nil)
11321           (gnus-inhibit-treatment t))
11322       (gnus-summary-select-article))
11323     (save-excursion
11324       (set-buffer gnus-article-buffer)
11325       (let ((handles (or gnus-article-mime-handles
11326                          (mm-dissect-buffer nil gnus-article-loose-mime)
11327                          (and gnus-article-emulate-mime
11328                               (mm-uu-dissect)))))
11329         (when handles
11330           (gnus-summary-save-parts-1 type dir handles reverse)
11331           (unless gnus-article-mime-handles ;; Don't destroy this case.
11332             (mm-destroy-parts handles)))))))
11333
11334 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11335   (if (stringp (car handle))
11336       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11337               (cdr handle))
11338     (when (if reverse
11339               (not (string-match type (mm-handle-media-type handle)))
11340             (string-match type (mm-handle-media-type handle)))
11341       (let ((file (expand-file-name
11342                    (gnus-map-function
11343                     mm-file-name-rewrite-functions
11344                     (file-name-nondirectory
11345                      (or
11346                       (mail-content-type-get
11347                        (mm-handle-disposition handle) 'filename)
11348                       (mail-content-type-get
11349                        (mm-handle-type handle) 'name)
11350                       (concat gnus-newsgroup-name
11351                               "." (number-to-string
11352                                    (cdr gnus-article-current))))))
11353                    dir)))
11354         (unless (file-exists-p file)
11355           (mm-save-part-to-file handle file))))))
11356
11357 ;; Summary extract commands
11358
11359 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
11360   (let ((buffer-read-only nil)
11361         (article (gnus-summary-article-number))
11362         after-article b e)
11363     (unless (gnus-summary-goto-subject article)
11364       (error "No such article: %d" article))
11365     (gnus-summary-position-point)
11366     ;; If all commands are to be bunched up on one line, we collect
11367     ;; them here.
11368     (unless gnus-view-pseudos-separately
11369       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
11370             files action)
11371         (while ps
11372           (setq action (cdr (assq 'action (car ps))))
11373           (setq files (list (cdr (assq 'name (car ps)))))
11374           (while (and ps (cdr ps)
11375                       (string= (or action "1")
11376                                (or (cdr (assq 'action (cadr ps))) "2")))
11377             (push (cdr (assq 'name (cadr ps))) files)
11378             (setcdr ps (cddr ps)))
11379           (when files
11380             (when (not (string-match "%s" action))
11381               (push " " files))
11382             (push " " files)
11383             (when (assq 'execute (car ps))
11384               (setcdr (assq 'execute (car ps))
11385                       (funcall (if (string-match "%s" action)
11386                                    'format 'concat)
11387                                action
11388                                (mapconcat
11389                                 (lambda (f)
11390                                   (if (equal f " ")
11391                                       f
11392                                     (shell-quote-argument f)))
11393                                 files " ")))))
11394           (setq ps (cdr ps)))))
11395     (if (and gnus-view-pseudos (not not-view))
11396         (while pslist
11397           (when (assq 'execute (car pslist))
11398             (gnus-execute-command (cdr (assq 'execute (car pslist)))
11399                                   (eq gnus-view-pseudos 'not-confirm)))
11400           (setq pslist (cdr pslist)))
11401       (save-excursion
11402         (while pslist
11403           (setq after-article (or (cdr (assq 'article (car pslist)))
11404                                   (gnus-summary-article-number)))
11405           (gnus-summary-goto-subject after-article)
11406           (forward-line 1)
11407           (setq b (point))
11408           (insert "    " (file-name-nondirectory
11409                           (cdr (assq 'name (car pslist))))
11410                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
11411           (setq e (point))
11412           (forward-line -1)             ; back to `b'
11413           (gnus-add-text-properties
11414            b (1- e) (list 'gnus-number gnus-reffed-article-number
11415                           gnus-mouse-face-prop gnus-mouse-face))
11416           (gnus-data-enter
11417            after-article gnus-reffed-article-number
11418            gnus-unread-mark b (car pslist) 0 (- e b))
11419           (setq gnus-newsgroup-unreads
11420                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
11421                                          gnus-reffed-article-number))
11422           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
11423           (setq pslist (cdr pslist)))))))
11424
11425 (defun gnus-pseudos< (p1 p2)
11426   (let ((c1 (cdr (assq 'action p1)))
11427         (c2 (cdr (assq 'action p2))))
11428     (and c1 c2 (string< c1 c2))))
11429
11430 (defun gnus-request-pseudo-article (props)
11431   (cond ((assq 'execute props)
11432          (gnus-execute-command (cdr (assq 'execute props)))))
11433   (let ((gnus-current-article (gnus-summary-article-number)))
11434     (gnus-run-hooks 'gnus-mark-article-hook)))
11435
11436 (defun gnus-execute-command (command &optional automatic)
11437   (save-excursion
11438     (gnus-article-setup-buffer)
11439     (set-buffer gnus-article-buffer)
11440     (setq buffer-read-only nil)
11441     (let ((command (if automatic command
11442                      (read-string "Command: " (cons command 0)))))
11443       (erase-buffer)
11444       (insert "$ " command "\n\n")
11445       (if gnus-view-pseudo-asynchronously
11446           (start-process "gnus-execute" (current-buffer) shell-file-name
11447                          shell-command-switch command)
11448         (call-process shell-file-name nil t nil
11449                       shell-command-switch command)))))
11450
11451 ;; Summary kill commands.
11452
11453 (defun gnus-summary-edit-global-kill (article)
11454   "Edit the \"global\" kill file."
11455   (interactive (list (gnus-summary-article-number)))
11456   (gnus-group-edit-global-kill article))
11457
11458 (defun gnus-summary-edit-local-kill ()
11459   "Edit a local kill file applied to the current newsgroup."
11460   (interactive)
11461   (setq gnus-current-headers (gnus-summary-article-header))
11462   (gnus-group-edit-local-kill
11463    (gnus-summary-article-number) gnus-newsgroup-name))
11464
11465 ;;; Header reading.
11466
11467 (defun gnus-read-header (id &optional header)
11468   "Read the headers of article ID and enter them into the Gnus system."
11469   (let ((group gnus-newsgroup-name)
11470         (gnus-override-method
11471          (or
11472           gnus-override-method
11473           (and (gnus-news-group-p gnus-newsgroup-name)
11474                (car (gnus-refer-article-methods)))))
11475         where)
11476     ;; First we check to see whether the header in question is already
11477     ;; fetched.
11478     (if (stringp id)
11479         ;; This is a Message-ID.
11480         (setq header (or header (gnus-id-to-header id)))
11481       ;; This is an article number.
11482       (setq header (or header (gnus-summary-article-header id))))
11483     (if (and header
11484              (not (gnus-summary-article-sparse-p (mail-header-number header))))
11485         ;; We have found the header.
11486         header
11487       ;; We have to really fetch the header to this article.
11488       (save-excursion
11489         (set-buffer nntp-server-buffer)
11490         (when (setq where (gnus-request-head id group))
11491           (nnheader-fold-continuation-lines)
11492           (goto-char (point-max))
11493           (insert ".\n")
11494           (goto-char (point-min))
11495           (insert "211 ")
11496           (princ (cond
11497                   ((numberp id) id)
11498                   ((cdr where) (cdr where))
11499                   (header (mail-header-number header))
11500                   (t gnus-reffed-article-number))
11501                  (current-buffer))
11502           (insert " Article retrieved.\n"))
11503         (if (or (not where)
11504                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
11505             ()                          ; Malformed head.
11506           (unless (gnus-summary-article-sparse-p (mail-header-number header))
11507             (when (and (stringp id)
11508                        (not (string= (gnus-group-real-name group)
11509                                      (car where))))
11510               ;; If we fetched by Message-ID and the article came
11511               ;; from a different group, we fudge some bogus article
11512               ;; numbers for this article.
11513               (mail-header-set-number header gnus-reffed-article-number))
11514             (save-excursion
11515               (set-buffer gnus-summary-buffer)
11516               (decf gnus-reffed-article-number)
11517               (gnus-remove-header (mail-header-number header))
11518               (push header gnus-newsgroup-headers)
11519               (setq gnus-current-headers header)
11520               (push (mail-header-number header) gnus-newsgroup-limit)))
11521           header)))))
11522
11523 (defun gnus-remove-header (number)
11524   "Remove header NUMBER from `gnus-newsgroup-headers'."
11525   (if (and gnus-newsgroup-headers
11526            (= number (mail-header-number (car gnus-newsgroup-headers))))
11527       (pop gnus-newsgroup-headers)
11528     (let ((headers gnus-newsgroup-headers))
11529       (while (and (cdr headers)
11530                   (not (= number (mail-header-number (cadr headers)))))
11531         (pop headers))
11532       (when (cdr headers)
11533         (setcdr headers (cddr headers))))))
11534
11535 ;;;
11536 ;;; summary highlights
11537 ;;;
11538
11539 (defun gnus-highlight-selected-summary ()
11540   "Highlight selected article in summary buffer."
11541   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
11542   (when gnus-summary-selected-face
11543     (save-excursion
11544       (let* ((beg (point-at-bol))
11545              (end (point-at-eol))
11546              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
11547              (from (if (get-text-property beg gnus-mouse-face-prop)
11548                        beg
11549                      (or (next-single-property-change
11550                           beg gnus-mouse-face-prop nil end)
11551                          beg)))
11552              (to
11553               (if (= from end)
11554                   (- from 2)
11555                 (or (next-single-property-change
11556                      from gnus-mouse-face-prop nil end)
11557                     end))))
11558         ;; If no mouse-face prop on line we will have to = from = end,
11559         ;; so we highlight the entire line instead.
11560         (when (= (+ to 2) from)
11561           (setq from beg)
11562           (setq to end))
11563         (if gnus-newsgroup-selected-overlay
11564             ;; Move old overlay.
11565             (gnus-move-overlay
11566              gnus-newsgroup-selected-overlay from to (current-buffer))
11567           ;; Create new overlay.
11568           (gnus-overlay-put
11569            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
11570            'face gnus-summary-selected-face))))))
11571
11572 (defvar gnus-summary-highlight-line-cached nil)
11573 (defvar gnus-summary-highlight-line-trigger nil)
11574
11575 (defun gnus-summary-highlight-line-0 ()
11576   (if (and (eq gnus-summary-highlight-line-trigger
11577                gnus-summary-highlight)
11578            gnus-summary-highlight-line-cached)
11579       gnus-summary-highlight-line-cached
11580     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
11581           gnus-summary-highlight-line-cached
11582           (let* ((cond (list 'cond))
11583                  (c cond)
11584                  (list gnus-summary-highlight))
11585             (while list
11586               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
11587                               nil))
11588               (setq c (cdr c)
11589                     list (cdr list)))
11590             (gnus-byte-compile (list 'lambda nil cond))))))
11591
11592 (defun gnus-summary-highlight-line ()
11593   "Highlight current line according to `gnus-summary-highlight'."
11594   (let* ((beg (point-at-bol))
11595          (article (or (gnus-summary-article-number) gnus-current-article))
11596          (score (or (cdr (assq article
11597                                gnus-newsgroup-scored))
11598                     gnus-summary-default-score 0))
11599          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
11600          (inhibit-read-only t)
11601          (default gnus-summary-default-score)
11602          (default-high gnus-summary-default-high-score)
11603          (default-low gnus-summary-default-low-score)
11604          (uncached (and gnus-summary-use-undownloaded-faces
11605                         (memq article gnus-newsgroup-undownloaded)
11606                         (not (memq article gnus-newsgroup-cached)))))
11607     (let ((face (funcall (gnus-summary-highlight-line-0))))
11608       (unless (eq face (get-text-property beg 'face))
11609         (gnus-put-text-property-excluding-characters-with-faces
11610          beg (point-at-eol) 'face
11611          (setq face (if (boundp face) (symbol-value face) face)))
11612         (when gnus-summary-highlight-line-function
11613           (funcall gnus-summary-highlight-line-function article face))))))
11614
11615 (defun gnus-update-read-articles (group unread &optional compute)
11616   "Update the list of read articles in GROUP.
11617 UNREAD is a sorted list."
11618   (let ((active (or gnus-newsgroup-active (gnus-active group)))
11619         (info (gnus-get-info group))
11620         (prev 1)
11621         read)
11622     (if (or (not info) (not active))
11623         ;; There is no info on this group if it was, in fact,
11624         ;; killed.  Gnus stores no information on killed groups, so
11625         ;; there's nothing to be done.
11626         ;; One could store the information somewhere temporarily,
11627         ;; perhaps...  Hmmm...
11628         ()
11629       ;; Remove any negative articles numbers.
11630       (while (and unread (< (car unread) 0))
11631         (setq unread (cdr unread)))
11632       ;; Remove any expired article numbers
11633       (while (and unread (< (car unread) (car active)))
11634         (setq unread (cdr unread)))
11635       ;; Compute the ranges of read articles by looking at the list of
11636       ;; unread articles.
11637       (while unread
11638         (when (/= (car unread) prev)
11639           (push (if (= prev (1- (car unread))) prev
11640                   (cons prev (1- (car unread))))
11641                 read))
11642         (setq prev (1+ (car unread)))
11643         (setq unread (cdr unread)))
11644       (when (<= prev (cdr active))
11645         (push (cons prev (cdr active)) read))
11646       (setq read (if (> (length read) 1) (nreverse read) read))
11647       (if compute
11648           read
11649         (save-excursion
11650           (let (setmarkundo)
11651             ;; Propagate the read marks to the backend.
11652             (when (gnus-check-backend-function 'request-set-mark group)
11653               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
11654                     (add (gnus-remove-from-range read (gnus-info-read info))))
11655                 (when (or add del)
11656                   (unless (gnus-check-group group)
11657                     (error "Can't open server for %s" group))
11658                   (gnus-request-set-mark
11659                    group (delq nil (list (if add (list add 'add '(read)))
11660                                          (if del (list del 'del '(read))))))
11661                   (setq setmarkundo
11662                         `(gnus-request-set-mark
11663                           ,group
11664                           ',(delq nil (list
11665                                        (if del (list del 'add '(read)))
11666                                        (if add (list add 'del '(read))))))))))
11667             (set-buffer gnus-group-buffer)
11668             (gnus-undo-register
11669               `(progn
11670                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
11671                  (gnus-info-set-read ',info ',(gnus-info-read info))
11672                  (gnus-get-unread-articles-in-group ',info
11673                                                     (gnus-active ,group))
11674                  (gnus-group-update-group ,group t)
11675                  ,setmarkundo))))
11676         ;; Enter this list into the group info.
11677         (gnus-info-set-read info read)
11678         ;; Set the number of unread articles in gnus-newsrc-hashtb.
11679         (gnus-get-unread-articles-in-group info (gnus-active group))
11680         t))))
11681
11682 (defun gnus-offer-save-summaries ()
11683   "Offer to save all active summary buffers."
11684   (let (buffers)
11685     ;; Go through all buffers and find all summaries.
11686     (dolist (buffer (buffer-list))
11687       (when (and (setq buffer (buffer-name buffer))
11688                  (string-match "Summary" buffer)
11689                  (with-current-buffer buffer
11690                    ;; We check that this is, indeed, a summary buffer.
11691                    (and (eq major-mode 'gnus-summary-mode)
11692                         ;; Also make sure this isn't bogus.
11693                         gnus-newsgroup-prepared
11694                         ;; Also make sure that this isn't a
11695                         ;; dead summary buffer.
11696                         (not gnus-dead-summary-mode))))
11697         (push buffer buffers)))
11698     ;; Go through all these summary buffers and offer to save them.
11699     (when buffers
11700       (save-excursion
11701         (map-y-or-n-p
11702          "Update summary buffer %s? "
11703          (lambda (buf)
11704            (switch-to-buffer buf)
11705            (gnus-summary-exit))
11706          buffers)))))
11707
11708
11709 ;;; @ for mime-partial
11710 ;;;
11711
11712 (defun gnus-request-partial-message ()
11713   (save-excursion
11714     (let ((number (gnus-summary-article-number))
11715           (group gnus-newsgroup-name)
11716           (mother gnus-article-buffer))
11717       (set-buffer (get-buffer-create " *Partial Article*"))
11718       (erase-buffer)
11719       (setq mime-preview-buffer mother)
11720       (gnus-request-article-this-buffer number group)
11721       (mime-parse-buffer)
11722       )))
11723
11724 (autoload 'mime-combine-message/partial-pieces-automatically
11725   "mime-partial"
11726   "Internal method to combine message/partial messages automatically.")
11727
11728 (mime-add-condition
11729  'action '((type . message)(subtype . partial)
11730            (major-mode . gnus-original-article-mode)
11731            (method . mime-combine-message/partial-pieces-automatically)
11732            (summary-buffer-exp . gnus-summary-buffer)
11733            (request-partial-message-method . gnus-request-partial-message)
11734            ))
11735
11736
11737 ;;; @ for message/rfc822
11738 ;;;
11739
11740 (defun gnus-mime-extract-message/rfc822 (entity situation)
11741   "Burst a forwarded article."
11742   (save-excursion
11743     (set-buffer gnus-summary-buffer)
11744     (let* ((group (completing-read "Group: " gnus-active-hashtb nil t
11745                                    gnus-newsgroup-name 'gnus-group-history))
11746            (gnus-group-marked (list group))
11747            article info)
11748       (with-temp-buffer
11749         (mime-insert-entity-content entity)
11750         (setq article (gnus-request-accept-article group)))
11751       (when (and (consp article)
11752                  (numberp (setq article (cdr article))))
11753         (setq info (gnus-get-info group))
11754         (gnus-info-set-read info
11755                             (gnus-remove-from-range (gnus-info-read info)
11756                                                     (list article)))
11757         (when (string-equal group gnus-newsgroup-name)
11758           (forward-line 1)
11759           (let (gnus-show-threads)
11760             (gnus-summary-goto-subject article t))
11761           (gnus-summary-clear-mark-forward 1))
11762         (set-buffer gnus-group-buffer)
11763         (gnus-group-get-new-news-this-group nil t)))))
11764
11765 (mime-add-condition
11766  'action '((type . message)(subtype . rfc822)
11767            (major-mode . gnus-original-article-mode)
11768            (method . gnus-mime-extract-message/rfc822)
11769            (mode . "extract")
11770            ))
11771
11772 (mime-add-condition
11773  'action '((type . message)(subtype . news)
11774            (major-mode . gnus-original-article-mode)
11775            (method . gnus-mime-extract-message/rfc822)
11776            (mode . "extract")
11777            ))
11778
11779 (defun gnus-mime-extract-multipart (entity situation)
11780   (let ((children (mime-entity-children entity))
11781         mime-acting-situation-to-override
11782         f)
11783     (while children
11784       (mime-play-entity (car children)
11785                         (cons (assq 'mode situation)
11786                               mime-acting-situation-to-override))
11787       (setq children (cdr children)))
11788     (if (setq f (cdr (assq 'after-method
11789                            mime-acting-situation-to-override)))
11790         (eval f)
11791       )))
11792
11793 (mime-add-condition
11794  'action '((type . multipart)
11795            (method . gnus-mime-extract-multipart)
11796            (mode . "extract")
11797            )
11798  'with-default)
11799
11800
11801 ;;; @ end
11802 ;;;
11803
11804 (defun gnus-summary-inherit-default-charset ()
11805   "Import `default-mime-charset' from summary buffer.
11806 Also take care of `default-mime-charset-unlimited' if the LIMIT version
11807 of FLIM is used."
11808   (if (buffer-live-p gnus-summary-buffer)
11809       (let (d-m-c d-m-c-u)
11810         (with-current-buffer gnus-summary-buffer
11811           (setq d-m-c (if (local-variable-p 'default-mime-charset
11812                                             gnus-summary-buffer)
11813                           default-mime-charset
11814                         t)
11815                 ;; LIMIT
11816                 d-m-c-u (if (local-variable-p 'default-mime-charset-unlimited
11817                                               gnus-summary-buffer)
11818                             (symbol-value 'default-mime-charset-unlimited)
11819                           t)))
11820         (if (eq t d-m-c)
11821             (kill-local-variable 'default-mime-charset)
11822           (set (make-local-variable 'default-mime-charset) d-m-c))
11823         (if (eq t d-m-c-u)
11824             (kill-local-variable 'default-mime-charset-unlimited)
11825           (set (make-local-variable 'default-mime-charset-unlimited)
11826                d-m-c-u)))))
11827
11828 (defun gnus-summary-setup-default-charset ()
11829   "Setup newsgroup default charset."
11830   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
11831       (progn
11832         (setq gnus-newsgroup-charset nil)
11833         (set (make-local-variable 'default-mime-charset) nil)
11834         (when (boundp 'default-mime-charset-unlimited);; LIMIT
11835           (set (make-local-variable 'default-mime-charset-unlimited) nil)))
11836     (let ((ignored-charsets
11837            (or gnus-newsgroup-ephemeral-ignored-charsets
11838                (append
11839                 (and gnus-newsgroup-name
11840                      (gnus-parameter-ignored-charsets gnus-newsgroup-name))
11841                 gnus-newsgroup-ignored-charsets)))
11842           charset)
11843       (setq gnus-newsgroup-charset
11844             (or gnus-newsgroup-ephemeral-charset
11845                 (when (and gnus-newsgroup-name
11846                            (setq charset (gnus-parameter-charset
11847                                           gnus-newsgroup-name)))
11848                   (make-local-variable 'default-mime-charset)
11849                   (setq default-mime-charset charset))
11850                 gnus-default-charset))
11851       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
11852            ignored-charsets))))
11853
11854 ;;;
11855 ;;; Mime Commands
11856 ;;;
11857
11858 (defun gnus-summary-display-buttonized (&optional show-all-parts)
11859   "Display the current article buffer fully MIME-buttonized.
11860 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
11861 treated as multipart/mixed."
11862   (interactive "P")
11863   (require 'gnus-art)
11864   (let ((gnus-unbuttonized-mime-types nil)
11865         (gnus-mime-display-multipart-as-mixed show-all-parts))
11866     (gnus-summary-show-article)))
11867
11868 (defun gnus-summary-repair-multipart (article)
11869   "Add a Content-Type header to a multipart article without one."
11870   (interactive (list (gnus-summary-article-number)))
11871   (gnus-with-article article
11872     (message-narrow-to-head)
11873     (message-remove-header "Mime-Version")
11874     (goto-char (point-max))
11875     (insert "Mime-Version: 1.0\n")
11876     (widen)
11877     (when (search-forward "\n--" nil t)
11878       (let ((separator (buffer-substring (point) (point-at-eol))))
11879         (message-narrow-to-head)
11880         (message-remove-header "Content-Type")
11881         (goto-char (point-max))
11882         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
11883                         separator))
11884         (widen))))
11885   (let (gnus-mark-article-hook)
11886     (gnus-summary-select-article t t nil article)))
11887
11888 (defun gnus-summary-toggle-display-buttonized ()
11889   "Toggle the buttonizing of the article buffer."
11890   (interactive)
11891   (require 'gnus-art)
11892   (if (setq gnus-inhibit-mime-unbuttonizing
11893             (not gnus-inhibit-mime-unbuttonizing))
11894       (let ((gnus-unbuttonized-mime-types nil))
11895         (gnus-summary-show-article))
11896     (gnus-summary-show-article)))
11897
11898 ;;;
11899 ;;; Intelli-mouse commmands
11900 ;;;
11901
11902 (defun gnus-wheel-summary-scroll (event)
11903   (interactive "e")
11904   (let ((amount (if (memq 'shift (event-modifiers event))
11905                     (car gnus-wheel-scroll-amount)
11906                   (cdr gnus-wheel-scroll-amount)))
11907         (direction (- (* (static-if (featurep 'xemacs)
11908                              (event-button event)
11909                            (cond ((eq 'mouse-4 (event-basic-type event))
11910                                   4)
11911                                  ((eq 'mouse-5 (event-basic-type event))
11912                                   5)))
11913                          2) 9))
11914         edge)
11915     (gnus-summary-scroll-up (* amount direction))
11916     (when (gnus-eval-in-buffer-window gnus-article-buffer
11917             (save-restriction
11918               (widen)
11919               (and (if (< 0 direction)
11920                        (gnus-article-next-page 0)
11921                      (gnus-article-prev-page 0)
11922                      (bobp))
11923                    (if (setq edge (get-text-property
11924                                    (point-min) 'gnus-wheel-edge))
11925                        (setq edge (* edge direction))
11926                      (setq edge -1))
11927                    (or (plusp edge)
11928                        (let ((buffer-read-only nil)
11929                              (inhibit-read-only t))
11930                          (put-text-property (point-min) (point-max)
11931                                             'gnus-wheel-edge direction)
11932                          nil))
11933                    (or (> edge gnus-wheel-edge-resistance)
11934                        (let ((buffer-read-only nil)
11935                              (inhibit-read-only t))
11936                          (put-text-property (point-min) (point-max)
11937                                             'gnus-wheel-edge
11938                                             (* (1+ edge) direction))
11939                          nil))
11940                    (eq last-command 'gnus-wheel-summary-scroll))))
11941       (gnus-summary-next-article nil nil (minusp direction)))))
11942
11943 (defun gnus-wheel-install ()
11944   "Enable mouse wheel support on summary window."
11945   (when gnus-use-wheel
11946     (let ((keys
11947            '([(mouse-4)] [(shift mouse-4)] [(mouse-5)] [(shift mouse-5)])))
11948       (dolist (key keys)
11949         (define-key gnus-summary-mode-map key
11950           'gnus-wheel-summary-scroll)))))
11951
11952 (add-hook 'gnus-summary-mode-hook 'gnus-wheel-install)
11953
11954 ;;;
11955 ;;; Traditional PGP commmands
11956 ;;;
11957
11958 (defun gnus-summary-decrypt-article (&optional force)
11959   "Decrypt the current article in traditional PGP way.
11960 This will have permanent effect only in mail groups.
11961 If FORCE is non-nil, allow editing of articles even in read-only
11962 groups."
11963   (interactive "P")
11964   (gnus-summary-select-article t)
11965   (gnus-eval-in-buffer-window gnus-article-buffer
11966     (save-excursion
11967       (save-restriction
11968         (widen)
11969         (goto-char (point-min))
11970         (unless (re-search-forward (car pgg-armor-header-lines) nil t)
11971           (error "Not a traditional PGP message!"))
11972         (let ((armor-start (match-beginning 0)))
11973           (if (and (pgg-decrypt-region armor-start (point-max))
11974                    (or force (not (gnus-group-read-only-p))))
11975               (let ((inhibit-read-only t)
11976                     buffer-read-only)
11977                 (delete-region armor-start
11978                                (progn
11979                                  (re-search-forward "^-+END PGP" nil t)
11980                                  (beginning-of-line 2)
11981                                  (point)))
11982                 (insert-buffer-substring pgg-output-buffer))))))))
11983
11984 (defun gnus-summary-verify-article ()
11985   "Verify the current article in traditional PGP way."
11986   (interactive)
11987   (save-excursion
11988     (set-buffer gnus-original-article-buffer)
11989     (goto-char (point-min))
11990     (unless (re-search-forward "^-+BEGIN PGP SIGNED MESSAGE" nil t)
11991       (error "Not a traditional PGP message!"))
11992     (re-search-forward "^-+END PGP" nil t)
11993     (beginning-of-line 2)
11994     (call-interactively (function pgg-verify-region))))
11995
11996 ;;;
11997 ;;; Generic summary marking commands
11998 ;;;
11999
12000 (defvar gnus-summary-marking-alist
12001   '((read gnus-del-mark "d")
12002     (unread gnus-unread-mark "u")
12003     (ticked gnus-ticked-mark "!")
12004     (dormant gnus-dormant-mark "?")
12005     (expirable gnus-expirable-mark "e"))
12006   "An alist of names/marks/keystrokes.")
12007
12008 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12009 (defvar gnus-summary-mark-map)
12010
12011 (defun gnus-summary-make-all-marking-commands ()
12012   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12013   (dolist (elem gnus-summary-marking-alist)
12014     (apply 'gnus-summary-make-marking-command elem)))
12015
12016 (defun gnus-summary-make-marking-command (name mark keystroke)
12017   (let ((map (make-sparse-keymap)))
12018     (define-key gnus-summary-generic-mark-map keystroke map)
12019     (dolist (lway `((next "next" next nil "n")
12020                     (next-unread "next unread" next t "N")
12021                     (prev "previous" prev nil "p")
12022                     (prev-unread "previous unread" prev t "P")
12023                     (nomove "" nil nil ,keystroke)))
12024       (let ((func (gnus-summary-make-marking-command-1
12025                    mark (car lway) lway name)))
12026         (setq func (eval func))
12027         (define-key map (nth 4 lway) func)))))
12028
12029 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12030   `(defun ,(intern
12031             (format "gnus-summary-put-mark-as-%s%s"
12032                     name (if (eq way 'nomove)
12033                              ""
12034                            (concat "-" (symbol-name way)))))
12035      (n)
12036      ,(format
12037        "Mark the current article as %s%s.
12038 If N, the prefix, then repeat N times.
12039 If N is negative, move in reverse order.
12040 The difference between N and the actual number of articles marked is
12041 returned."
12042        name (car (cdr lway)))
12043      (interactive "p")
12044      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12045
12046 (defun gnus-summary-generic-mark (n mark move unread)
12047   "Mark N articles with MARK."
12048   (unless (eq major-mode 'gnus-summary-mode)
12049     (error "This command can only be used in the summary buffer"))
12050   (gnus-summary-show-thread)
12051   (let ((nummove
12052          (cond
12053           ((eq move 'next) 1)
12054           ((eq move 'prev) -1)
12055           (t 0))))
12056     (if (zerop nummove)
12057         (setq n 1)
12058       (when (< n 0)
12059         (setq n (abs n)
12060               nummove (* -1 nummove))))
12061     (while (and (> n 0)
12062                 (gnus-summary-mark-article nil mark)
12063                 (zerop (gnus-summary-next-subject nummove unread t)))
12064       (setq n (1- n)))
12065     (when (/= 0 n)
12066       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12067     (gnus-summary-recenter)
12068     (gnus-summary-position-point)
12069     (gnus-set-mode-line 'summary)
12070     n))
12071
12072 (defun gnus-summary-insert-articles (articles)
12073   (when (setq articles
12074               (gnus-sorted-difference articles
12075                                       (mapcar (lambda (h)
12076                                                 (mail-header-number h))
12077                                               gnus-newsgroup-headers)))
12078     (setq gnus-newsgroup-headers
12079           (gnus-merge 'list
12080                       gnus-newsgroup-headers
12081                       (gnus-fetch-headers articles)
12082                       'gnus-article-sort-by-number))
12083     ;; Suppress duplicates?
12084     (when gnus-suppress-duplicates
12085       (gnus-dup-suppress-articles))
12086
12087     ;; We might want to build some more threads first.
12088     (when (and gnus-fetch-old-headers
12089                (eq gnus-headers-retrieved-by 'nov))
12090       (if (eq gnus-fetch-old-headers 'invisible)
12091           (gnus-build-all-threads)
12092         (gnus-build-old-threads)))
12093     ;; Let the Gnus agent mark articles as read.
12094     (when gnus-agent
12095       (gnus-agent-get-undownloaded-list))
12096     ;; Remove list identifiers from subject
12097     (when gnus-list-identifiers
12098       (gnus-summary-remove-list-identifiers))
12099     ;; First and last article in this newsgroup.
12100     (when gnus-newsgroup-headers
12101       (setq gnus-newsgroup-begin
12102             (mail-header-number (car gnus-newsgroup-headers))
12103             gnus-newsgroup-end
12104             (mail-header-number
12105              (gnus-last-element gnus-newsgroup-headers))))
12106     (when gnus-use-scoring
12107       (gnus-possibly-score-headers))))
12108
12109 (defun gnus-summary-insert-old-articles (&optional all)
12110   "Insert all old articles in this group.
12111 If ALL is non-nil, already read articles become readable.
12112 If ALL is a number, fetch this number of articles."
12113   (interactive "P")
12114   (prog1
12115       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12116             older len)
12117         (setq older
12118               ;; Some nntp servers lie about their active range.  When
12119               ;; this happens, the active range can be in the millions.
12120               ;; Use a compressed range to avoid creating a huge list.
12121               (gnus-range-difference (list gnus-newsgroup-active) old))
12122         (setq len (gnus-range-length older))
12123         (cond
12124          ((null older) nil)
12125          ((numberp all)
12126           (if (< all len)
12127               (let ((older-range (nreverse older)))
12128                 (setq older nil)
12129
12130                 (while (> all 0)
12131                   (let* ((r (pop older-range))
12132                          (min (if (numberp r) r (car r)))
12133                          (max (if (numberp r) r (cdr r))))
12134                     (while (and (<= min max)
12135                                 (> all 0))
12136                       (push max older)
12137                       (setq all (1- all)
12138                             max (1- max))))))
12139             (setq older (gnus-uncompress-range older))))
12140          (all
12141           (setq older (gnus-uncompress-range older)))
12142          (t
12143           (when (and (numberp gnus-large-newsgroup)
12144                    (> len gnus-large-newsgroup))
12145               (let* ((cursor-in-echo-area nil)
12146                      (initial (gnus-parameter-large-newsgroup-initial
12147                                gnus-newsgroup-name))
12148                      (input
12149                       (read-string
12150                        (format
12151                         "How many articles from %s (%s %d): "
12152                         (gnus-limit-string
12153                          (gnus-group-decoded-name gnus-newsgroup-name) 35)
12154                         (if initial "max" "default")
12155                         len)
12156                        (if initial
12157                            (cons (number-to-string initial)
12158                                  0)))))
12159                 (unless (string-match "^[ \t]*$" input)
12160                   (setq all (string-to-number input))
12161                   (if (< all len)
12162                       (let ((older-range (nreverse older)))
12163                         (setq older nil)
12164
12165                         (while (> all 0)
12166                           (let* ((r (pop older-range))
12167                                  (min (if (numberp r) r (car r)))
12168                                  (max (if (numberp r) r (cdr r))))
12169                             (while (and (<= min max)
12170                                         (> all 0))
12171                               (push max older)
12172                               (setq all (1- all)
12173                                     max (1- max))))))))))
12174           (setq older (gnus-uncompress-range older))))
12175         (if (not older)
12176             (message "No old news.")
12177           (gnus-summary-insert-articles older)
12178           (gnus-summary-limit (gnus-sorted-nunion old older))))
12179     (gnus-summary-position-point)))
12180
12181 (defun gnus-summary-insert-new-articles ()
12182   "Insert all new articles in this group."
12183   (interactive)
12184   (prog1
12185       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12186             (old-active gnus-newsgroup-active)
12187             (nnmail-fetched-sources (list t))
12188             i new)
12189         (setq gnus-newsgroup-active
12190               (gnus-activate-group gnus-newsgroup-name 'scan))
12191         (setq i (cdr gnus-newsgroup-active))
12192         (while (> i (cdr old-active))
12193           (push i new)
12194           (decf i))
12195         (if (not new)
12196             (message "No gnus is bad news")
12197           (gnus-summary-insert-articles new)
12198           (setq gnus-newsgroup-unreads
12199                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12200           (gnus-summary-limit (gnus-sorted-nunion old new))))
12201     (gnus-summary-position-point)))
12202
12203 (gnus-summary-make-all-marking-commands)
12204
12205 (gnus-ems-redefine)
12206
12207 (provide 'gnus-sum)
12208
12209 (run-hooks 'gnus-sum-load-hook)
12210
12211 ;; Local Variables:
12212 ;; coding: iso-8859-1
12213 ;; End:
12214
12215 ;;; gnus-sum.el ends here