* binhex.el (binhex-decode-region-internal)
[gnus] / lisp / gnus-sum.el
1 ;;; gnus-sum.el --- summary mode commands for Gnus
2
3 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 ;; For Emacs < 22.2.
29 (eval-and-compile
30   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
31 (eval-when-compile
32   (require 'cl))
33 (eval-when-compile
34   (when (featurep 'xemacs)
35     (require 'easy-mmode))) ; for `define-minor-mode'
36
37 (defvar tool-bar-mode)
38 (defvar gnus-tmp-header)
39
40 (require 'gnus)
41 (require 'gnus-group)
42 (require 'gnus-spec)
43 (require 'gnus-range)
44 (require 'gnus-int)
45 (require 'gnus-undo)
46 (require 'gnus-util)
47 (require 'gmm-utils)
48 (require 'mm-decode)
49 (require 'nnoo)
50
51 (autoload 'gnus-summary-limit-include-cached "gnus-cache" nil t)
52 (autoload 'gnus-cache-write-active "gnus-cache")
53 (autoload 'gnus-mailing-list-insinuate "gnus-ml" nil t)
54 (autoload 'turn-on-gnus-mailing-list-mode "gnus-ml" nil t)
55 (autoload 'gnus-pick-line-number "gnus-salt" nil t)
56 (autoload 'mm-uu-dissect "mm-uu")
57 (autoload 'gnus-article-outlook-deuglify-article "deuglify"
58   "Deuglify broken Outlook (Express) articles and redisplay."
59   t)
60 (autoload 'gnus-article-outlook-unwrap-lines "deuglify" nil t)
61 (autoload 'gnus-article-outlook-repair-attribution "deuglify" nil t)
62 (autoload 'gnus-article-outlook-rearrange-citation "deuglify" nil t)
63
64 (defcustom gnus-kill-summary-on-exit t
65   "*If non-nil, kill the summary buffer when you exit from it.
66 If nil, the summary will become a \"*Dead Summary*\" buffer, and
67 it will be killed sometime later."
68   :group 'gnus-summary-exit
69   :type 'boolean)
70
71 (defcustom gnus-summary-next-group-on-exit t
72   "If non-nil, go to the next unread newsgroup on summary exit.
73 See `gnus-group-goto-unread'."
74   :link '(custom-manual "(gnus)Group Maneuvering")
75   :group 'gnus-summary-exit
76   :version "23.1" ;; No Gnus
77   :type 'boolean)
78
79 (defcustom gnus-fetch-old-headers nil
80   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
81 If an unread article in the group refers to an older, already
82 read (or just marked as read) article, the old article will not
83 normally be displayed in the Summary buffer.  If this variable is
84 t, Gnus will attempt to grab the headers to the old articles, and
85 thereby build complete threads.  If it has the value `some', all
86 old headers will be fetched but only enough headers to connect
87 otherwise loose threads will be displayed.  This variable can
88 also be a number.  In that case, no more than that number of old
89 headers will be fetched.  If it has the value `invisible', all
90 old headers will be fetched, but none will be displayed.
91
92 The server has to support NOV for any of this to work.
93
94 This feature can seriously impact performance it ignores all
95 locally cached header entries.  Setting it to t for groups for a
96 server that doesn't expire articles (such as news.gmane.org),
97 leads to very slow summary generation."
98   :group 'gnus-thread
99   :type '(choice (const :tag "off" nil)
100                  (const :tag "on" t)
101                  (const some)
102                  (const invisible)
103                  number
104                  (sexp :menu-tag "other" t)))
105
106 (defcustom gnus-refer-thread-limit 500
107   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
108 If t, fetch all the available old headers."
109   :group 'gnus-thread
110   :type '(choice number
111                  (sexp :menu-tag "other" t)))
112
113 (defcustom gnus-summary-make-false-root 'adopt
114   "*nil means that Gnus won't gather loose threads.
115 If the root of a thread has expired or been read in a previous
116 session, the information necessary to build a complete thread has been
117 lost.  Instead of having many small sub-threads from this original thread
118 scattered all over the summary buffer, Gnus can gather them.
119
120 If non-nil, Gnus will try to gather all loose sub-threads from an
121 original thread into one large thread.
122
123 If this variable is non-nil, it should be one of `none', `adopt',
124 `dummy' or `empty'.
125
126 If this variable is `none', Gnus will not make a false root, but just
127 present the sub-threads after another.
128 If this variable is `dummy', Gnus will create a dummy root that will
129 have all the sub-threads as children.
130 If this variable is `adopt', Gnus will make one of the \"children\"
131 the parent and mark all the step-children as such.
132 If this variable is `empty', the \"children\" are printed with empty
133 subject fields.  (Or rather, they will be printed with a string
134 given by the `gnus-summary-same-subject' variable.)"
135   :group 'gnus-thread
136   :type '(choice (const :tag "off" nil)
137                  (const none)
138                  (const dummy)
139                  (const adopt)
140                  (const empty)))
141
142 (defcustom gnus-summary-make-false-root-always nil
143   "Always make a false dummy root."
144   :version "22.1"
145   :group 'gnus-thread
146   :type 'boolean)
147
148 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
149   "*A regexp to match subjects to be excluded from loose thread gathering.
150 As loose thread gathering is done on subjects only, that means that
151 there can be many false gatherings performed.  By rooting out certain
152 common subjects, gathering might become saner."
153   :group 'gnus-thread
154   :type 'regexp)
155
156 (defcustom gnus-summary-gather-subject-limit nil
157   "*Maximum length of subject comparisons when gathering loose threads.
158 Use nil to compare full subjects.  Setting this variable to a low
159 number will help gather threads that have been corrupted by
160 newsreaders chopping off subject lines, but it might also mean that
161 unrelated articles that have subject that happen to begin with the
162 same few characters will be incorrectly gathered.
163
164 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
165 comparing subjects."
166   :group 'gnus-thread
167   :type '(choice (const :tag "off" nil)
168                  (const fuzzy)
169                  (sexp :menu-tag "on" t)))
170
171 (defcustom gnus-simplify-subject-functions nil
172   "List of functions taking a string argument that simplify subjects.
173 The functions are applied recursively.
174
175 Useful functions to put in this list include:
176 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
177 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
178   :group 'gnus-thread
179   :type '(repeat function))
180
181 (defcustom gnus-simplify-ignored-prefixes nil
182   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
183   :group 'gnus-thread
184   :type '(choice (const :tag "off" nil)
185                  regexp))
186
187 (defcustom gnus-build-sparse-threads nil
188   "*If non-nil, fill in the gaps in threads.
189 If `some', only fill in the gaps that are needed to tie loose threads
190 together.  If `more', fill in all leaf nodes that Gnus can find.  If
191 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
192   :group 'gnus-thread
193   :type '(choice (const :tag "off" nil)
194                  (const some)
195                  (const more)
196                  (sexp :menu-tag "all" t)))
197
198 (defcustom gnus-summary-thread-gathering-function
199   'gnus-gather-threads-by-subject
200   "*Function used for gathering loose threads.
201 There are two pre-defined functions: `gnus-gather-threads-by-subject',
202 which only takes Subjects into consideration; and
203 `gnus-gather-threads-by-references', which compared the References
204 headers of the articles to find matches."
205   :group 'gnus-thread
206   :type '(radio (function-item gnus-gather-threads-by-subject)
207                 (function-item gnus-gather-threads-by-references)
208                 (function :tag "other")))
209
210 (defcustom gnus-summary-same-subject ""
211   "*String indicating that the current article has the same subject as the previous.
212 This variable will only be used if the value of
213 `gnus-summary-make-false-root' is `empty'."
214   :group 'gnus-summary-format
215   :type 'string)
216
217 (defcustom gnus-summary-goto-unread t
218   "*If t, many commands will go to the next unread article.
219 This applies to marking commands as well as other commands that
220 \"naturally\" select the next article, like, for instance, `SPC' at
221 the end of an article.
222
223 If nil, the marking commands do NOT go to the next unread article
224 \(they go to the next article instead).  If `never', commands that
225 usually go to the next unread article, will go to the next article,
226 whether it is read or not."
227   :group 'gnus-summary-marks
228   :link '(custom-manual "(gnus)Setting Marks")
229   :type '(choice (const :tag "off" nil)
230                  (const never)
231                  (sexp :menu-tag "on" t)))
232
233 (defcustom gnus-summary-default-score 0
234   "*Default article score level.
235 All scores generated by the score files will be added to this score.
236 If this variable is nil, scoring will be disabled."
237   :group 'gnus-score-default
238   :type '(choice (const :tag "disable")
239                  integer))
240
241 (defcustom gnus-summary-default-high-score 0
242   "*Default threshold for a high scored article.
243 An article will be highlighted as high scored if its score is greater
244 than this score."
245   :version "22.1"
246   :group 'gnus-score-default
247   :type 'integer)
248
249 (defcustom gnus-summary-default-low-score 0
250   "*Default threshold for a low scored article.
251 An article will be highlighted as low scored if its score is smaller
252 than this score."
253   :version "22.1"
254   :group 'gnus-score-default
255   :type 'integer)
256
257 (defcustom gnus-summary-zcore-fuzz 0
258   "*Fuzziness factor for the zcore in the summary buffer.
259 Articles with scores closer than this to `gnus-summary-default-score'
260 will not be marked."
261   :group 'gnus-summary-format
262   :type 'integer)
263
264 (defcustom gnus-simplify-subject-fuzzy-regexp nil
265   "*Strings to be removed when doing fuzzy matches.
266 This can either be a regular expression or list of regular expressions
267 that will be removed from subject strings if fuzzy subject
268 simplification is selected."
269   :group 'gnus-thread
270   :type '(repeat regexp))
271
272 (defcustom gnus-show-threads t
273   "*If non-nil, display threads in summary mode."
274   :group 'gnus-thread
275   :type 'boolean)
276
277 (defcustom gnus-thread-hide-subtree nil
278   "*If non-nil, hide all threads initially.
279 This can be a predicate specifier which says which threads to hide.
280 If threads are hidden, you have to run the command
281 `gnus-summary-show-thread' by hand or select an article."
282   :group 'gnus-thread
283   :type '(radio (sexp :format "Non-nil\n"
284                       :match (lambda (widget value)
285                                (not (or (consp value) (functionp value))))
286                       :value t)
287                 (const nil)
288                 (sexp :tag "Predicate specifier")))
289
290 (defcustom gnus-thread-hide-killed t
291   "*If non-nil, hide killed threads automatically."
292   :group 'gnus-thread
293   :type 'boolean)
294
295 (defcustom gnus-thread-ignore-subject t
296   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
297 If nil, articles that have different subjects from their parents will
298 start separate threads."
299   :group 'gnus-thread
300   :type 'boolean)
301
302 (defcustom gnus-thread-operation-ignore-subject t
303   "*If non-nil, subjects will be ignored when doing thread commands.
304 This affects commands like `gnus-summary-kill-thread' and
305 `gnus-summary-lower-thread'.
306
307 If this variable is nil, articles in the same thread with different
308 subjects will not be included in the operation in question.  If this
309 variable is `fuzzy', only articles that have subjects that are fuzzily
310 equal will be included."
311   :group 'gnus-thread
312   :type '(choice (const :tag "off" nil)
313                  (const fuzzy)
314                  (sexp :tag "on" t)))
315
316 (defcustom gnus-thread-indent-level 4
317   "*Number that says how much each sub-thread should be indented."
318   :group 'gnus-thread
319   :type 'integer)
320
321 (defcustom gnus-auto-extend-newsgroup t
322   "*If non-nil, extend newsgroup forward and backward when requested."
323   :group 'gnus-summary-choose
324   :type 'boolean)
325
326 (defcustom gnus-auto-select-first t
327   "If non-nil, select an article on group entry.
328 An article is selected automatically when entering a group
329 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
330 `gnus-summary-catchup-and-goto-next-group'.
331
332 Which article is selected is controlled by the variable
333 `gnus-auto-select-subject'.
334
335 If you want to prevent automatic selection of articles in some
336 newsgroups, set the variable to nil in `gnus-select-group-hook'."
337   ;; Commands include...
338   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
339   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
340   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
341   :group 'gnus-group-select
342   :type '(choice (const :tag "none" nil)
343                  (sexp :menu-tag "first" t)))
344
345 (defcustom gnus-auto-select-subject 'unread
346   "*Says what subject to place under point when entering a group.
347
348 This variable can either be the symbols `first' (place point on the
349 first subject), `unread' (place point on the subject line of the first
350 unread article), `best' (place point on the subject line of the
351 higest-scored article), `unseen' (place point on the subject line of
352 the first unseen article), `unseen-or-unread' (place point on the subject
353 line of the first unseen article or, if all article have been seen, on the
354 subject line of the first unread article), or a function to be called to
355 place point on some subject line."
356   :version "22.1"
357   :group 'gnus-group-select
358   :type '(choice (const best)
359                  (const unread)
360                  (const first)
361                  (const unseen)
362                  (const unseen-or-unread)))
363
364 (defcustom gnus-auto-select-next t
365   "*If non-nil, offer to go to the next group from the end of the previous.
366 If the value is t and the next newsgroup is empty, Gnus will exit
367 summary mode and go back to group mode.  If the value is neither nil
368 nor t, Gnus will select the following unread newsgroup.  In
369 particular, if the value is the symbol `quietly', the next unread
370 newsgroup will be selected without any confirmation, and if it is
371 `almost-quietly', the next group will be selected without any
372 confirmation if you are located on the last article in the group.
373 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
374 will go to the next group without confirmation."
375   :group 'gnus-summary-maneuvering
376   :type '(choice (const :tag "off" nil)
377                  (const quietly)
378                  (const almost-quietly)
379                  (const slightly-quietly)
380                  (sexp :menu-tag "on" t)))
381
382 (defcustom gnus-auto-select-same nil
383   "*If non-nil, select the next article with the same subject.
384 If there are no more articles with the same subject, go to
385 the first unread article."
386   :group 'gnus-summary-maneuvering
387   :type 'boolean)
388
389 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
390   "What article should be selected after exiting an ephemeral group.
391 Valid values include:
392
393 `next'
394   Select the next article.
395 `next-unread'
396   Select the next unread article.
397 `next-noselect'
398   Move the cursor to the next article.  This is the default.
399 `next-unread-noselect'
400   Move the cursor to the next unread article.
401
402 If it has any other value or there is no next (unread) article, the
403 article selected before entering to the ephemeral group will appear."
404   :version "23.1" ;; No Gnus
405   :group 'gnus-summary-maneuvering
406   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
407                  (const next) (const next-unread)
408                  (const next-noselect) (const next-unread-noselect)
409                  (sexp :tag "other" :value nil)))
410
411 (defcustom gnus-auto-goto-ignores 'unfetched
412   "*Says how to handle unfetched articles when maneuvering.
413
414 This variable can either be the symbols nil (maneuver to any
415 article), `undownloaded' (maneuvering while unplugged ignores articles
416 that have not been fetched), `always-undownloaded' (maneuvering always
417 ignores articles that have not been fetched), `unfetched' (maneuvering
418 ignores articles whose headers have not been fetched).
419
420 NOTE: The list of unfetched articles will always be nil when plugged
421 and, when unplugged, a subset of the undownloaded article list."
422   :version "22.1"
423   :group 'gnus-summary-maneuvering
424   :type '(choice (const :tag "None" nil)
425                  (const :tag "Undownloaded when unplugged" undownloaded)
426                  (const :tag "Undownloaded" always-undownloaded)
427                  (const :tag "Unfetched" unfetched)))
428
429 (defcustom gnus-summary-check-current nil
430   "*If non-nil, consider the current article when moving.
431 The \"unread\" movement commands will stay on the same line if the
432 current article is unread."
433   :group 'gnus-summary-maneuvering
434   :type 'boolean)
435
436 (defcustom gnus-auto-center-summary 2
437   "*If non-nil, always center the current summary buffer.
438 In particular, if `vertical' do only vertical recentering.  If non-nil
439 and non-`vertical', do both horizontal and vertical recentering."
440   :group 'gnus-summary-maneuvering
441   :type '(choice (const :tag "none" nil)
442                  (const vertical)
443                  (integer :tag "height")
444                  (sexp :menu-tag "both" t)))
445
446 (defvar gnus-auto-center-group t
447   "*If non-nil, always center the group buffer.")
448
449 (defcustom gnus-show-all-headers nil
450   "*If non-nil, don't hide any headers."
451   :group 'gnus-article-hiding
452   :group 'gnus-article-headers
453   :type 'boolean)
454
455 (defcustom gnus-summary-ignore-duplicates nil
456   "*If non-nil, ignore articles with identical Message-ID headers."
457   :group 'gnus-summary
458   :type 'boolean)
459
460 (defcustom gnus-single-article-buffer t
461   "*If non-nil, display all articles in the same buffer.
462 If nil, each group will get its own article buffer."
463   :group 'gnus-article-various
464   :type 'boolean)
465
466 (defcustom gnus-break-pages t
467   "*If non-nil, do page breaking on articles.
468 The page delimiter is specified by the `gnus-page-delimiter'
469 variable."
470   :group 'gnus-article-various
471   :type 'boolean)
472
473 (defcustom gnus-move-split-methods nil
474   "*Variable used to suggest where articles are to be moved to.
475 It uses the same syntax as the `gnus-split-methods' variable.
476 However, whereas `gnus-split-methods' specifies file names as targets,
477 this variable specifies group names."
478   :group 'gnus-summary-mail
479   :type '(repeat (choice (list :value (fun) function)
480                          (cons :value ("" "") regexp (repeat string))
481                          (sexp :value nil))))
482
483 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
484   "Function used to compute default prefix for article move/copy/etc prompts.
485 The function should take one argument, a group name, and return a
486 string with the suggested prefix."
487   :group 'gnus-summary-mail
488   :type 'function)
489
490 ;; FIXME: Although the custom type is `character' for the following variables,
491 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
492
493 (defcustom gnus-unread-mark ?           ;Whitespace
494   "*Mark used for unread articles."
495   :group 'gnus-summary-marks
496   :type 'character)
497
498 (defcustom gnus-ticked-mark ?!
499   "*Mark used for ticked articles."
500   :group 'gnus-summary-marks
501   :type 'character)
502
503 (defcustom gnus-dormant-mark ??
504   "*Mark used for dormant articles."
505   :group 'gnus-summary-marks
506   :type 'character)
507
508 (defcustom gnus-del-mark ?r
509   "*Mark used for del'd articles."
510   :group 'gnus-summary-marks
511   :type 'character)
512
513 (defcustom gnus-read-mark ?R
514   "*Mark used for read articles."
515   :group 'gnus-summary-marks
516   :type 'character)
517
518 (defcustom gnus-expirable-mark ?E
519   "*Mark used for expirable articles."
520   :group 'gnus-summary-marks
521   :type 'character)
522
523 (defcustom gnus-killed-mark ?K
524   "*Mark used for killed articles."
525   :group 'gnus-summary-marks
526   :type 'character)
527
528 (defcustom gnus-spam-mark ?$
529   "*Mark used for spam articles."
530   :version "22.1"
531   :group 'gnus-summary-marks
532   :type 'character)
533
534 (defcustom gnus-souped-mark ?F
535   "*Mark used for souped articles."
536   :group 'gnus-summary-marks
537   :type 'character)
538
539 (defcustom gnus-kill-file-mark ?X
540   "*Mark used for articles killed by kill files."
541   :group 'gnus-summary-marks
542   :type 'character)
543
544 (defcustom gnus-low-score-mark ?Y
545   "*Mark used for articles with a low score."
546   :group 'gnus-summary-marks
547   :type 'character)
548
549 (defcustom gnus-catchup-mark ?C
550   "*Mark used for articles that are caught up."
551   :group 'gnus-summary-marks
552   :type 'character)
553
554 (defcustom gnus-replied-mark ?A
555   "*Mark used for articles that have been replied to."
556   :group 'gnus-summary-marks
557   :type 'character)
558
559 (defcustom gnus-forwarded-mark ?F
560   "*Mark used for articles that have been forwarded."
561   :version "22.1"
562   :group 'gnus-summary-marks
563   :type 'character)
564
565 (defcustom gnus-recent-mark ?N
566   "*Mark used for articles that are recent."
567   :version "22.1"
568   :group 'gnus-summary-marks
569   :type 'character)
570
571 (defcustom gnus-cached-mark ?*
572   "*Mark used for articles that are in the cache."
573   :group 'gnus-summary-marks
574   :type 'character)
575
576 (defcustom gnus-saved-mark ?S
577   "*Mark used for articles that have been saved."
578   :group 'gnus-summary-marks
579   :type 'character)
580
581 (defcustom gnus-unseen-mark ?.
582   "*Mark used for articles that haven't been seen."
583   :version "22.1"
584   :group 'gnus-summary-marks
585   :type 'character)
586
587 (defcustom gnus-no-mark ?               ;Whitespace
588   "*Mark used for articles that have no other secondary mark."
589   :version "22.1"
590   :group 'gnus-summary-marks
591   :type 'character)
592
593 (defcustom gnus-ancient-mark ?O
594   "*Mark used for ancient articles."
595   :group 'gnus-summary-marks
596   :type 'character)
597
598 (defcustom gnus-sparse-mark ?Q
599   "*Mark used for sparsely reffed articles."
600   :group 'gnus-summary-marks
601   :type 'character)
602
603 (defcustom gnus-canceled-mark ?G
604   "*Mark used for canceled articles."
605   :group 'gnus-summary-marks
606   :type 'character)
607
608 (defcustom gnus-duplicate-mark ?M
609   "*Mark used for duplicate articles."
610   :group 'gnus-summary-marks
611   :type 'character)
612
613 (defcustom gnus-undownloaded-mark ?-
614   "*Mark used for articles that weren't downloaded."
615   :version "22.1"
616   :group 'gnus-summary-marks
617   :type 'character)
618
619 (defcustom gnus-downloaded-mark ?+
620   "*Mark used for articles that were downloaded."
621   :group 'gnus-summary-marks
622   :type 'character)
623
624 (defcustom gnus-downloadable-mark ?%
625   "*Mark used for articles that are to be downloaded."
626   :group 'gnus-summary-marks
627   :type 'character)
628
629 (defcustom gnus-unsendable-mark ?=
630   "*Mark used for articles that won't be sent."
631   :group 'gnus-summary-marks
632   :type 'character)
633
634 (defcustom gnus-score-over-mark ?+
635   "*Score mark used for articles with high scores."
636   :group 'gnus-summary-marks
637   :type 'character)
638
639 (defcustom gnus-score-below-mark ?-
640   "*Score mark used for articles with low scores."
641   :group 'gnus-summary-marks
642   :type 'character)
643
644 (defcustom gnus-empty-thread-mark ?     ;Whitespace
645   "*There is no thread under the article."
646   :group 'gnus-summary-marks
647   :type 'character)
648
649 (defcustom gnus-not-empty-thread-mark ?=
650   "*There is a thread under the article."
651   :group 'gnus-summary-marks
652   :type 'character)
653
654 (defcustom gnus-view-pseudo-asynchronously nil
655   "*If non-nil, Gnus will view pseudo-articles asynchronously."
656   :group 'gnus-extract-view
657   :type 'boolean)
658
659 (defcustom gnus-auto-expirable-marks
660   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
661         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
662         gnus-souped-mark gnus-duplicate-mark)
663   "*The list of marks converted into expiration if a group is auto-expirable."
664   :version "21.1"
665   :group 'gnus-summary
666   :type '(repeat character))
667
668 (defcustom gnus-inhibit-user-auto-expire t
669   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
670   :version "21.1"
671   :group 'gnus-summary
672   :type 'boolean)
673
674 (defcustom gnus-mark-copied-or-moved-articles-as-expirable nil
675   "If non-nil, mark articles copied or moved to auto-expire group as expirable.
676 If nil, the expirable marks will be unchanged except that the marks
677 will be removed when copying or moving articles to a group that has
678 not turned auto-expire on.  If non-nil, articles that have been read
679 will be marked as expirable when being copied or moved to a group in
680 which auto-expire is turned on."
681   :version "23.2"
682   :type 'boolean
683   :group 'gnus-summary-marks)
684
685 (defcustom gnus-view-pseudos nil
686   "*If `automatic', pseudo-articles will be viewed automatically.
687 If `not-confirm', pseudos will be viewed automatically, and the user
688 will not be asked to confirm the command."
689   :group 'gnus-extract-view
690   :type '(choice (const :tag "off" nil)
691                  (const automatic)
692                  (const not-confirm)))
693
694 (defcustom gnus-view-pseudos-separately t
695   "*If non-nil, one pseudo-article will be created for each file to be viewed.
696 If nil, all files that use the same viewing command will be given as a
697 list of parameters to that command."
698   :group 'gnus-extract-view
699   :type 'boolean)
700
701 (defcustom gnus-insert-pseudo-articles t
702   "*If non-nil, insert pseudo-articles when decoding articles."
703   :group 'gnus-extract-view
704   :type 'boolean)
705
706 (defcustom gnus-summary-dummy-line-format
707   "   %(:                             :%) %S\n"
708   "*The format specification for the dummy roots in the summary buffer.
709 It works along the same lines as a normal formatting string,
710 with some simple extensions.
711
712 %S  The subject
713
714 General format specifiers can also be used.
715 See `(gnus)Formatting Variables'."
716   :link '(custom-manual "(gnus)Formatting Variables")
717   :group 'gnus-threading
718   :type 'string)
719
720 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
721   "*The format specification for the summary mode line.
722 It works along the same lines as a normal formatting string,
723 with some simple extensions:
724
725 %G  Group name
726 %p  Unprefixed group name
727 %A  Current article number
728 %z  Current article score
729 %V  Gnus version
730 %U  Number of unread articles in the group
731 %e  Number of unselected articles in the group
732 %Z  A string with unread/unselected article counts
733 %g  Shortish group name
734 %S  Subject of the current article
735 %u  User-defined spec
736 %s  Current score file name
737 %d  Number of dormant articles
738 %r  Number of articles that have been marked as read in this session
739 %E  Number of articles expunged by the score files"
740   :group 'gnus-summary-format
741   :type 'string)
742
743 (defcustom gnus-list-identifiers nil
744   "Regexp that matches list identifiers to be removed from subject.
745 This can also be a list of regexps."
746   :version "21.1"
747   :group 'gnus-summary-format
748   :group 'gnus-article-hiding
749   :type '(choice (const :tag "none" nil)
750                  (regexp :value ".*")
751                  (repeat :value (".*") regexp)))
752
753 (defcustom gnus-summary-mark-below 0
754   "*Mark all articles with a score below this variable as read.
755 This variable is local to each summary buffer and usually set by the
756 score file."
757   :group 'gnus-score-default
758   :type 'integer)
759
760 (defun gnus-widget-reversible-match (widget value)
761   "Ignoring WIDGET, convert VALUE to internal form.
762 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
763   ;; (debug value)
764   (or (symbolp value)
765       (and (listp value)
766            (eq (length value) 2)
767            (eq (nth 0 value) 'not)
768            (symbolp (nth 1 value)))))
769
770 (defun gnus-widget-reversible-to-internal (widget value)
771   "Ignoring WIDGET, convert VALUE to internal form.
772 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
773 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
774   ;; (debug value)
775   (if (atom value)
776       (list value nil)
777     (list (nth 1 value) t)))
778
779 (defun gnus-widget-reversible-to-external (widget value)
780   "Ignoring WIDGET, convert VALUE to external form.
781 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
782 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
783   ;; (debug value)
784   (if (nth 1 value)
785       (list 'not (nth 0 value))
786     (nth 0 value)))
787
788 (define-widget 'gnus-widget-reversible 'group
789   "A `group' that convert values."
790   :match 'gnus-widget-reversible-match
791   :value-to-internal 'gnus-widget-reversible-to-internal
792   :value-to-external 'gnus-widget-reversible-to-external)
793
794 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
795   "*List of functions used for sorting articles in the summary buffer.
796
797 Each function takes two articles and returns non-nil if the first
798 article should be sorted before the other.  If you use more than one
799 function, the primary sort function should be the last.  You should
800 probably always include `gnus-article-sort-by-number' in the list of
801 sorting functions -- preferably first.  Also note that sorting by date
802 is often much slower than sorting by number, and the sorting order is
803 very similar.  (Sorting by date means sorting by the time the message
804 was sent, sorting by number means sorting by arrival time.)
805
806 Each item can also be a list `(not F)' where F is a function;
807 this reverses the sort order.
808
809 Ready-made functions include `gnus-article-sort-by-number',
810 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
811 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
812 and `gnus-article-sort-by-score'.
813
814 When threading is turned on, the variable `gnus-thread-sort-functions'
815 controls how articles are sorted."
816   :group 'gnus-summary-sort
817   :type '(repeat (gnus-widget-reversible
818                   (choice (function-item gnus-article-sort-by-number)
819                           (function-item gnus-article-sort-by-author)
820                           (function-item gnus-article-sort-by-subject)
821                           (function-item gnus-article-sort-by-date)
822                           (function-item gnus-article-sort-by-score)
823                           (function-item gnus-article-sort-by-random)
824                           (function :tag "other"))
825                   (boolean :tag "Reverse order"))))
826
827
828 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
829   "*List of functions used for sorting threads in the summary buffer.
830 By default, threads are sorted by article number.
831
832 Each function takes two threads and returns non-nil if the first
833 thread should be sorted before the other.  If you use more than one
834 function, the primary sort function should be the last.  You should
835 probably always include `gnus-thread-sort-by-number' in the list of
836 sorting functions -- preferably first.  Also note that sorting by date
837 is often much slower than sorting by number, and the sorting order is
838 very similar.  (Sorting by date means sorting by the time the message
839 was sent, sorting by number means sorting by arrival time.)
840
841 Each list item can also be a list `(not F)' where F is a
842 function; this specifies reversed sort order.
843
844 Ready-made functions include `gnus-thread-sort-by-number',
845 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
846 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
847 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
848 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
849 and `gnus-thread-sort-by-total-score' (see
850 `gnus-thread-score-function').
851
852 When threading is turned off, the variable
853 `gnus-article-sort-functions' controls how articles are sorted."
854   :group 'gnus-summary-sort
855   :type '(repeat
856           (gnus-widget-reversible
857            (choice (function-item gnus-thread-sort-by-number)
858                    (function-item gnus-thread-sort-by-author)
859                    (function-item gnus-thread-sort-by-recipient)
860                    (function-item gnus-thread-sort-by-subject)
861                    (function-item gnus-thread-sort-by-date)
862                    (function-item gnus-thread-sort-by-score)
863                    (function-item gnus-thread-sort-by-most-recent-number)
864                    (function-item gnus-thread-sort-by-most-recent-date)
865                    (function-item gnus-thread-sort-by-random)
866                    (function-item gnus-thread-sort-by-total-score)
867                    (function :tag "other"))
868            (boolean :tag "Reverse order"))))
869
870 (defcustom gnus-thread-score-function '+
871   "*Function used for calculating the total score of a thread.
872
873 The function is called with the scores of the article and each
874 subthread and should then return the score of the thread.
875
876 Some functions you can use are `+', `max', or `min'."
877   :group 'gnus-summary-sort
878   :type 'function)
879
880 (defcustom gnus-summary-expunge-below nil
881   "All articles that have a score less than this variable will be expunged.
882 This variable is local to the summary buffers."
883   :group 'gnus-score-default
884   :type '(choice (const :tag "off" nil)
885                  integer))
886
887 (defcustom gnus-thread-expunge-below nil
888   "All threads that have a total score less than this variable will be expunged.
889 See `gnus-thread-score-function' for en explanation of what a
890 \"thread score\" is.
891
892 This variable is local to the summary buffers."
893   :group 'gnus-threading
894   :group 'gnus-score-default
895   :type '(choice (const :tag "off" nil)
896                  integer))
897
898 (defcustom gnus-summary-mode-hook nil
899   "*A hook for Gnus summary mode.
900 This hook is run before any variables are set in the summary buffer."
901   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
902   :group 'gnus-summary-various
903   :type 'hook)
904
905 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
906 (when (featurep 'xemacs)
907   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
908   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
909   (add-hook 'gnus-summary-mode-hook
910             'gnus-xmas-switch-horizontal-scrollbar-off))
911
912 (defcustom gnus-summary-menu-hook nil
913   "*Hook run after the creation of the summary mode menu."
914   :group 'gnus-summary-visual
915   :type 'hook)
916
917 (defcustom gnus-summary-exit-hook nil
918   "*A hook called on exit from the summary buffer.
919 It will be called with point in the group buffer."
920   :group 'gnus-summary-exit
921   :type 'hook)
922
923 (defcustom gnus-summary-prepare-hook nil
924   "*A hook called after the summary buffer has been generated.
925 If you want to modify the summary buffer, you can use this hook."
926   :group 'gnus-summary-various
927   :type 'hook)
928
929 (defcustom gnus-summary-prepared-hook nil
930   "*A hook called as the last thing after the summary buffer has been generated."
931   :group 'gnus-summary-various
932   :type 'hook)
933
934 (defcustom gnus-summary-generate-hook nil
935   "*A hook run just before generating the summary buffer.
936 This hook is commonly used to customize threading variables and the
937 like."
938   :group 'gnus-summary-various
939   :type 'hook)
940
941 (defcustom gnus-select-group-hook nil
942   "*A hook called when a newsgroup is selected.
943
944 If you'd like to simplify subjects like the
945 `gnus-summary-next-same-subject' command does, you can use the
946 following hook:
947
948  (add-hook gnus-select-group-hook
949            (lambda ()
950              (mapcar (lambda (header)
951                        (mail-header-set-subject
952                         header
953                         (gnus-simplify-subject
954                          (mail-header-subject header) 're-only)))
955                      gnus-newsgroup-headers)))"
956   :group 'gnus-group-select
957   :type 'hook)
958
959 (defcustom gnus-select-article-hook nil
960   "*A hook called when an article is selected."
961   :group 'gnus-summary-choose
962   :options '(gnus-agent-fetch-selected-article)
963   :type 'hook)
964
965 (defcustom gnus-visual-mark-article-hook
966   (list 'gnus-highlight-selected-summary)
967   "*Hook run after selecting an article in the summary buffer.
968 It is meant to be used for highlighting the article in some way.  It
969 is not run if `gnus-visual' is nil."
970   :group 'gnus-summary-visual
971   :type 'hook)
972
973 (defcustom gnus-parse-headers-hook nil
974   "*A hook called before parsing the headers."
975   :group 'gnus-various
976   :type 'hook)
977
978 (defcustom gnus-exit-group-hook nil
979   "*A hook called when exiting summary mode.
980 This hook is not called from the non-updating exit commands like `Q'."
981   :group 'gnus-various
982   :type 'hook)
983
984 (defcustom gnus-summary-update-hook
985   (list 'gnus-summary-highlight-line)
986   "*A hook called when a summary line is changed.
987 The hook will not be called if `gnus-visual' is nil.
988
989 The default function `gnus-summary-highlight-line' will
990 highlight the line according to the `gnus-summary-highlight'
991 variable."
992   :group 'gnus-summary-visual
993   :type 'hook)
994
995 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
996   "*A hook called when an article is selected for the first time.
997 The hook is intended to mark an article as read (or unread)
998 automatically when it is selected."
999   :group 'gnus-summary-choose
1000   :type 'hook)
1001
1002 (defcustom gnus-group-no-more-groups-hook nil
1003   "*A hook run when returning to group mode having no more (unread) groups."
1004   :group 'gnus-group-select
1005   :type 'hook)
1006
1007 (defcustom gnus-ps-print-hook nil
1008   "*A hook run before ps-printing something from Gnus."
1009   :group 'gnus-summary
1010   :type 'hook)
1011
1012 (defcustom gnus-summary-article-move-hook nil
1013   "*A hook called after an article is moved, copied, respooled, or crossposted."
1014   :version "22.1"
1015   :group 'gnus-summary
1016   :type 'hook)
1017
1018 (defcustom gnus-summary-article-delete-hook nil
1019   "*A hook called after an article is deleted."
1020   :version "22.1"
1021   :group 'gnus-summary
1022   :type 'hook)
1023
1024 (defcustom gnus-summary-article-expire-hook nil
1025   "*A hook called after an article is expired."
1026   :version "22.1"
1027   :group 'gnus-summary
1028   :type 'hook)
1029
1030 (defcustom gnus-summary-display-arrow
1031   (and (fboundp 'display-graphic-p)
1032        (display-graphic-p))
1033   "*If non-nil, display an arrow highlighting the current article."
1034   :version "22.1"
1035   :group 'gnus-summary
1036   :type 'boolean)
1037
1038 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1039   "Face used for highlighting the current article in the summary buffer."
1040   :group 'gnus-summary-visual
1041   :type 'face)
1042
1043 (defvar gnus-tmp-downloaded nil)
1044
1045 (defcustom gnus-summary-highlight
1046   '(((eq mark gnus-canceled-mark)
1047      . gnus-summary-cancelled)
1048     ((and uncached (> score default-high))
1049      . gnus-summary-high-undownloaded)
1050     ((and uncached (< score default-low))
1051      . gnus-summary-low-undownloaded)
1052     (uncached
1053      . gnus-summary-normal-undownloaded)
1054     ((and (> score default-high)
1055           (or (eq mark gnus-dormant-mark)
1056               (eq mark gnus-ticked-mark)))
1057      . gnus-summary-high-ticked)
1058     ((and (< score default-low)
1059           (or (eq mark gnus-dormant-mark)
1060               (eq mark gnus-ticked-mark)))
1061      . gnus-summary-low-ticked)
1062     ((or (eq mark gnus-dormant-mark)
1063          (eq mark gnus-ticked-mark))
1064      . gnus-summary-normal-ticked)
1065     ((and (> score default-high) (eq mark gnus-ancient-mark))
1066      . gnus-summary-high-ancient)
1067     ((and (< score default-low) (eq mark gnus-ancient-mark))
1068      . gnus-summary-low-ancient)
1069     ((eq mark gnus-ancient-mark)
1070      . gnus-summary-normal-ancient)
1071     ((and (> score default-high) (eq mark gnus-unread-mark))
1072      . gnus-summary-high-unread)
1073     ((and (< score default-low) (eq mark gnus-unread-mark))
1074      . gnus-summary-low-unread)
1075     ((eq mark gnus-unread-mark)
1076      . gnus-summary-normal-unread)
1077     ((> score default-high)
1078      . gnus-summary-high-read)
1079     ((< score default-low)
1080      . gnus-summary-low-read)
1081     (t
1082      . gnus-summary-normal-read))
1083   "*Controls the highlighting of summary buffer lines.
1084
1085 A list of (FORM . FACE) pairs.  When deciding how a particular
1086 summary line should be displayed, each form is evaluated.  The content
1087 of the face field after the first true form is used.  You can change
1088 how those summary lines are displayed, by editing the face field.
1089
1090 You can use the following variables in the FORM field.
1091
1092 score:        The article's score.
1093 default:      The default article score.
1094 default-high: The default score for high scored articles.
1095 default-low:  The default score for low scored articles.
1096 below:        The score below which articles are automatically marked as read.
1097 mark:         The article's mark.
1098 uncached:     Non-nil if the article is uncached."
1099   :group 'gnus-summary-visual
1100   :type '(repeat (cons (sexp :tag "Form" nil)
1101                        face)))
1102 (put 'gnus-summary-highlight 'risky-local-variable t)
1103
1104 (defcustom gnus-alter-header-function nil
1105   "Function called to allow alteration of article header structures.
1106 The function is called with one parameter, the article header vector,
1107 which it may alter in any way."
1108   :type '(choice (const :tag "None" nil)
1109                  function)
1110   :group 'gnus-summary)
1111
1112 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1113   "Function used to decode a string with encoded words.")
1114
1115 (defvar gnus-decode-encoded-address-function
1116   'mail-decode-encoded-address-string
1117   "Function used to decode addresses with encoded words.")
1118
1119 (defcustom gnus-extra-headers '(To Newsgroups)
1120   "*Extra headers to parse."
1121   :version "21.1"
1122   :group 'gnus-summary
1123   :type '(repeat symbol))
1124
1125 (defcustom gnus-ignored-from-addresses
1126   (and user-mail-address
1127        (not (string= user-mail-address ""))
1128        (regexp-quote user-mail-address))
1129   "*From headers that may be suppressed in favor of To headers.
1130 This can be a regexp or a list of regexps."
1131   :version "21.1"
1132   :group 'gnus-summary
1133   :type '(choice regexp
1134                  (repeat :tag "Regexp List" regexp)))
1135
1136 (defsubst gnus-ignored-from-addresses ()
1137   (gmm-regexp-concat gnus-ignored-from-addresses))
1138
1139 (defcustom gnus-summary-to-prefix "-> "
1140   "*String prefixed to the To field in the summary line when
1141 using `gnus-ignored-from-addresses'."
1142   :version "22.1"
1143   :group 'gnus-summary
1144   :type 'string)
1145
1146 (defcustom gnus-summary-newsgroup-prefix "=> "
1147   "*String prefixed to the Newsgroup field in the summary
1148 line when using `gnus-ignored-from-addresses'."
1149   :version "22.1"
1150   :group 'gnus-summary
1151   :type 'string)
1152
1153 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1154   "List of charsets that should be ignored.
1155 When these charsets are used in the \"charset\" parameter, the
1156 default charset will be used instead."
1157   :version "21.1"
1158   :type '(repeat symbol)
1159   :group 'gnus-charset)
1160
1161 (defcustom gnus-newsgroup-maximum-articles nil
1162   "The maximum number of articles a newsgroup.
1163 If this is a number, old articles in a newsgroup exceeding this number
1164 are silently ignored.  If it is nil, no article is ignored.  Note that
1165 setting this variable to a number might prevent you from reading very
1166 old articles."
1167   :group 'gnus-group-select
1168   :version "22.2"
1169   :type '(choice (const :tag "No limit" nil)
1170                  integer))
1171
1172 (gnus-define-group-parameter
1173  ignored-charsets
1174  :type list
1175  :function-document
1176  "Return the ignored charsets of GROUP."
1177  :variable gnus-group-ignored-charsets-alist
1178  :variable-default
1179  '(("alt\\.chinese\\.text" iso-8859-1))
1180  :variable-document
1181  "Alist of regexps (to match group names) and charsets that should be ignored.
1182 When these charsets are used in the \"charset\" parameter, the
1183 default charset will be used instead."
1184  :variable-group gnus-charset
1185  :variable-type '(repeat (cons (regexp :tag "Group")
1186                                (repeat symbol)))
1187  :parameter-type '(choice :tag "Ignored charsets"
1188                           :value nil
1189                           (repeat (symbol)))
1190  :parameter-document       "\
1191 List of charsets that should be ignored.
1192
1193 When these charsets are used in the \"charset\" parameter, the
1194 default charset will be used instead.")
1195
1196 (defcustom gnus-group-highlight-words-alist nil
1197   "Alist of group regexps and highlight regexps.
1198 This variable uses the same syntax as `gnus-emphasis-alist'."
1199   :version "21.1"
1200   :type '(repeat (cons (regexp :tag "Group")
1201                        (repeat (list (regexp :tag "Highlight regexp")
1202                                      (number :tag "Group for entire word" 0)
1203                                      (number :tag "Group for displayed part" 0)
1204                                      (symbol :tag "Face"
1205                                              gnus-emphasis-highlight-words)))))
1206   :group 'gnus-summary-visual)
1207
1208 (defcustom gnus-summary-show-article-charset-alist
1209   nil
1210   "Alist of number and charset.
1211 The article will be shown with the charset corresponding to the
1212 numbered argument.
1213 For example: ((1 . cn-gb-2312) (2 . big5))."
1214   :version "21.1"
1215   :type '(repeat (cons (number :tag "Argument" 1)
1216                        (symbol :tag "Charset")))
1217   :group 'gnus-charset)
1218
1219 (defcustom gnus-preserve-marks t
1220   "Whether marks are preserved when moving, copying and respooling messages."
1221   :version "21.1"
1222   :type 'boolean
1223   :group 'gnus-summary-marks)
1224
1225 (defcustom gnus-propagate-marks t
1226   "If non-nil, do not propagate marks to the backends."
1227   :version "23.1" ;; No Gnus
1228   :type 'boolean
1229   :group 'gnus-summary-marks)
1230
1231 (defcustom gnus-alter-articles-to-read-function nil
1232   "Function to be called to alter the list of articles to be selected."
1233   :type '(choice (const nil) function)
1234   :group 'gnus-summary)
1235
1236 (defcustom gnus-orphan-score nil
1237   "*All orphans get this score added.  Set in the score file."
1238   :group 'gnus-score-default
1239   :type '(choice (const nil)
1240                  integer))
1241
1242 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1243   "*A regexp to match MIME parts when saving multiple parts of a
1244 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1245 This regexp will be used by default when prompting the user for which
1246 type of files to save."
1247   :group 'gnus-summary
1248   :type 'regexp)
1249
1250 (defcustom gnus-read-all-available-headers nil
1251   "Whether Gnus should parse all headers made available to it.
1252 This is mostly relevant for slow back ends where the user may
1253 wish to widen the summary buffer to include all headers
1254 that were fetched.  Say, for nnultimate groups."
1255   :version "22.1"
1256   :group 'gnus-summary
1257   :type '(choice boolean regexp))
1258
1259 (defcustom gnus-summary-pipe-output-default-command nil
1260   "Command (and optional arguments) used to pipe article to subprocess.
1261 This will be used as the default command if it is non-nil.  The value
1262 will be updated if you modify it when executing the command
1263 `gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1264   :version "23.1" ;; No Gnus
1265   :group 'gnus-summary
1266   :type '(radio (const :tag "None" nil) (string :tag "Command")))
1267
1268 (defcustom gnus-summary-muttprint-program "muttprint"
1269   "Command (and optional arguments) used to run Muttprint.
1270 The value will be updated if you modify it when executing the command
1271 `gnus-summary-muttprint'."
1272   :version "22.1"
1273   :group 'gnus-summary
1274   :type 'string)
1275
1276 (defcustom gnus-article-loose-mime t
1277   "If non-nil, don't require MIME-Version header.
1278 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1279 supply the MIME-Version header or deliberately strip it from the mail.
1280 If non-nil (the default), Gnus will treat some articles as MIME
1281 even if the MIME-Version header is missing."
1282   :version "22.1"
1283   :type 'boolean
1284   :group 'gnus-article-mime)
1285
1286 (defcustom gnus-article-emulate-mime t
1287   "If non-nil, use MIME emulation for uuencode and the like.
1288 This means that Gnus will search message bodies for text that look
1289 like uuencoded bits, yEncoded bits, and so on, and present that using
1290 the normal Gnus MIME machinery."
1291   :version "22.1"
1292   :type 'boolean
1293   :group 'gnus-article-mime)
1294
1295 ;;; Internal variables
1296
1297 (defvar gnus-summary-display-cache nil)
1298 (defvar gnus-article-mime-handles nil)
1299 (defvar gnus-article-decoded-p nil)
1300 (defvar gnus-article-charset nil)
1301 (defvar gnus-article-ignored-charsets nil)
1302 (defvar gnus-scores-exclude-files nil)
1303 (defvar gnus-page-broken nil)
1304
1305 (defvar gnus-original-article nil)
1306 (defvar gnus-article-internal-prepare-hook nil)
1307 (defvar gnus-newsgroup-process-stack nil)
1308
1309 (defvar gnus-thread-indent-array nil)
1310 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1311 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1312   "Function called to sort the articles within a thread after it has been gathered together.")
1313
1314 (defvar gnus-summary-save-parts-type-history nil)
1315 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1316
1317 ;; Avoid highlighting in kill files.
1318 (defvar gnus-summary-inhibit-highlight nil)
1319 (defvar gnus-newsgroup-selected-overlay nil)
1320 (defvar gnus-inhibit-limiting nil)
1321 (defvar gnus-newsgroup-adaptive-score-file nil)
1322 (defvar gnus-current-score-file nil)
1323 (defvar gnus-current-move-group nil)
1324 (defvar gnus-current-copy-group nil)
1325 (defvar gnus-current-crosspost-group nil)
1326 (defvar gnus-newsgroup-display nil)
1327
1328 (defvar gnus-newsgroup-dependencies nil)
1329 (defvar gnus-newsgroup-adaptive nil)
1330 (defvar gnus-summary-display-article-function nil)
1331 (defvar gnus-summary-highlight-line-function nil
1332   "Function called after highlighting a summary line.")
1333
1334 (defvar gnus-summary-line-format-alist
1335   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1336     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1337     (?s gnus-tmp-subject-or-nil ?s)
1338     (?n gnus-tmp-name ?s)
1339     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1340         ?s)
1341     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1342             gnus-tmp-from) ?s)
1343     (?F gnus-tmp-from ?s)
1344     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1345     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1346     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1347     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1348     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1349     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1350     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1351     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1352     (?L gnus-tmp-lines ?s)
1353     (?O gnus-tmp-downloaded ?c)
1354     (?I gnus-tmp-indentation ?s)
1355     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1356     (?R gnus-tmp-replied ?c)
1357     (?\[ gnus-tmp-opening-bracket ?c)
1358     (?\] gnus-tmp-closing-bracket ?c)
1359     (?\> (make-string gnus-tmp-level ? ) ?s)
1360     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1361     (?i gnus-tmp-score ?d)
1362     (?z gnus-tmp-score-char ?c)
1363     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1364     (?U gnus-tmp-unread ?c)
1365     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1366         ?s)
1367     (?t (gnus-summary-number-of-articles-in-thread
1368          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1369         ?d)
1370     (?e (gnus-summary-number-of-articles-in-thread
1371          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1372         ?c)
1373     (?u gnus-tmp-user-defined ?s)
1374     (?P (gnus-pick-line-number) ?d)
1375     (?B gnus-tmp-thread-tree-header-string ?s)
1376     (user-date (gnus-user-date
1377                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1378   "An alist of format specifications that can appear in summary lines.
1379 These are paired with what variables they correspond with, along with
1380 the type of the variable (string, integer, character, etc).")
1381
1382 (defvar gnus-summary-dummy-line-format-alist
1383   `((?S gnus-tmp-subject ?s)
1384     (?N gnus-tmp-number ?d)
1385     (?u gnus-tmp-user-defined ?s)))
1386
1387 (defvar gnus-summary-mode-line-format-alist
1388   `((?G gnus-tmp-group-name ?s)
1389     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1390     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1391     (?A gnus-tmp-article-number ?d)
1392     (?Z gnus-tmp-unread-and-unselected ?s)
1393     (?V gnus-version ?s)
1394     (?U gnus-tmp-unread-and-unticked ?d)
1395     (?S gnus-tmp-subject ?s)
1396     (?e gnus-tmp-unselected ?d)
1397     (?u gnus-tmp-user-defined ?s)
1398     (?d (length gnus-newsgroup-dormant) ?d)
1399     (?t (length gnus-newsgroup-marked) ?d)
1400     (?h (length gnus-newsgroup-spam-marked) ?d)
1401     (?r (length gnus-newsgroup-reads) ?d)
1402     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1403     (?E gnus-newsgroup-expunged-tally ?d)
1404     (?s (gnus-current-score-file-nondirectory) ?s)))
1405
1406 ;; This is here rather than in gnus-art for compilation reasons.
1407 (defvar gnus-article-mode-line-format-alist
1408   (nconc '((?w (gnus-article-wash-status) ?s)
1409            (?m (gnus-article-mime-part-status) ?s))
1410          gnus-summary-mode-line-format-alist))
1411
1412 (defvar gnus-last-search-regexp nil
1413   "Default regexp for article search command.")
1414
1415 (defvar gnus-last-shell-command nil
1416   "Default shell command on article.")
1417
1418 (defvar gnus-newsgroup-agentized nil
1419   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1420 (defvar gnus-newsgroup-begin nil)
1421 (defvar gnus-newsgroup-end nil)
1422 (defvar gnus-newsgroup-last-rmail nil)
1423 (defvar gnus-newsgroup-last-mail nil)
1424 (defvar gnus-newsgroup-last-folder nil)
1425 (defvar gnus-newsgroup-last-file nil)
1426 (defvar gnus-newsgroup-last-directory nil)
1427 (defvar gnus-newsgroup-auto-expire nil)
1428 (defvar gnus-newsgroup-active nil)
1429
1430 (defvar gnus-newsgroup-data nil)
1431 (defvar gnus-newsgroup-data-reverse nil)
1432 (defvar gnus-newsgroup-limit nil)
1433 (defvar gnus-newsgroup-limits nil)
1434 (defvar gnus-summary-use-undownloaded-faces nil)
1435
1436 (defvar gnus-newsgroup-unreads nil
1437   "Sorted list of unread articles in the current newsgroup.")
1438
1439 (defvar gnus-newsgroup-unselected nil
1440   "Sorted list of unselected unread articles in the current newsgroup.")
1441
1442 (defvar gnus-newsgroup-reads nil
1443   "Alist of read articles and article marks in the current newsgroup.")
1444
1445 (defvar gnus-newsgroup-expunged-tally nil)
1446
1447 (defvar gnus-newsgroup-marked nil
1448   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1449
1450 (defvar gnus-newsgroup-spam-marked nil
1451   "List of ranges of articles that have been marked as spam.")
1452
1453 (defvar gnus-newsgroup-killed nil
1454   "List of ranges of articles that have been through the scoring process.")
1455
1456 (defvar gnus-newsgroup-cached nil
1457   "Sorted list of articles that come from the article cache.")
1458
1459 (defvar gnus-newsgroup-saved nil
1460   "List of articles that have been saved.")
1461
1462 (defvar gnus-newsgroup-kill-headers nil)
1463
1464 (defvar gnus-newsgroup-replied nil
1465   "List of articles that have been replied to in the current newsgroup.")
1466
1467 (defvar gnus-newsgroup-forwarded nil
1468   "List of articles that have been forwarded in the current newsgroup.")
1469
1470 (defvar gnus-newsgroup-recent nil
1471   "List of articles that have are recent in the current newsgroup.")
1472
1473 (defvar gnus-newsgroup-expirable nil
1474   "Sorted list of articles in the current newsgroup that can be expired.")
1475
1476 (defvar gnus-newsgroup-processable nil
1477   "List of articles in the current newsgroup that can be processed.")
1478
1479 (defvar gnus-newsgroup-downloadable nil
1480   "Sorted list of articles in the current newsgroup that can be processed.")
1481
1482 (defvar gnus-newsgroup-unfetched nil
1483   "Sorted list of articles in the current newsgroup whose headers have
1484 not been fetched into the agent.
1485
1486 This list will always be a subset of gnus-newsgroup-undownloaded.")
1487
1488 (defvar gnus-newsgroup-undownloaded nil
1489   "List of articles in the current newsgroup that haven't been downloaded.")
1490
1491 (defvar gnus-newsgroup-unsendable nil
1492   "List of articles in the current newsgroup that won't be sent.")
1493
1494 (defvar gnus-newsgroup-bookmarks nil
1495   "List of articles in the current newsgroup that have bookmarks.")
1496
1497 (defvar gnus-newsgroup-dormant nil
1498   "Sorted list of dormant articles in the current newsgroup.")
1499
1500 (defvar gnus-newsgroup-unseen nil
1501   "List of unseen articles in the current newsgroup.")
1502
1503 (defvar gnus-newsgroup-seen nil
1504   "Range of seen articles in the current newsgroup.")
1505
1506 (defvar gnus-newsgroup-articles nil
1507   "List of articles in the current newsgroup.")
1508
1509 (defvar gnus-newsgroup-scored nil
1510   "List of scored articles in the current newsgroup.")
1511
1512 (defvar gnus-newsgroup-headers nil
1513   "List of article headers in the current newsgroup.")
1514
1515 (defvar gnus-newsgroup-threads nil)
1516
1517 (defvar gnus-newsgroup-prepared nil
1518   "Whether the current group has been prepared properly.")
1519
1520 (defvar gnus-newsgroup-ancient nil
1521   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1522
1523 (defvar gnus-newsgroup-sparse nil)
1524
1525 (defvar gnus-current-article nil)
1526 (defvar gnus-article-current nil)
1527 (defvar gnus-current-headers nil)
1528 (defvar gnus-have-all-headers nil)
1529 (defvar gnus-last-article nil)
1530 (defvar gnus-newsgroup-history nil)
1531 (defvar gnus-newsgroup-charset nil)
1532 (defvar gnus-newsgroup-ephemeral-charset nil)
1533 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1534
1535 (defvar gnus-article-before-search nil)
1536
1537 (defvar gnus-summary-local-variables
1538   '(gnus-newsgroup-name
1539     gnus-newsgroup-begin gnus-newsgroup-end
1540     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1541     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1542     gnus-newsgroup-last-directory
1543     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1544     gnus-newsgroup-unselected gnus-newsgroup-marked
1545     gnus-newsgroup-spam-marked
1546     gnus-newsgroup-reads gnus-newsgroup-saved
1547     gnus-newsgroup-replied gnus-newsgroup-forwarded
1548     gnus-newsgroup-recent
1549     gnus-newsgroup-expirable
1550     gnus-newsgroup-processable gnus-newsgroup-killed
1551     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1552     gnus-newsgroup-unfetched
1553     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1554     gnus-newsgroup-seen gnus-newsgroup-articles
1555     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1556     gnus-newsgroup-headers gnus-newsgroup-threads
1557     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1558     gnus-current-article gnus-current-headers gnus-have-all-headers
1559     gnus-last-article gnus-article-internal-prepare-hook
1560     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1561     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1562     gnus-thread-expunge-below
1563     gnus-score-alist gnus-current-score-file
1564     (gnus-summary-expunge-below . global)
1565     (gnus-summary-mark-below . global)
1566     (gnus-orphan-score . global)
1567     gnus-newsgroup-active gnus-scores-exclude-files
1568     gnus-newsgroup-history gnus-newsgroup-ancient
1569     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1570     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1571     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1572     (gnus-newsgroup-expunged-tally . 0)
1573     gnus-cache-removable-articles gnus-newsgroup-cached
1574     gnus-newsgroup-data gnus-newsgroup-data-reverse
1575     gnus-newsgroup-limit gnus-newsgroup-limits
1576     gnus-newsgroup-charset gnus-newsgroup-display
1577     gnus-summary-use-undownloaded-faces)
1578   "Variables that are buffer-local to the summary buffers.")
1579
1580 (defvar gnus-newsgroup-variables nil
1581   "A list of variables that have separate values in different newsgroups.
1582 A list of newsgroup (summary buffer) local variables, or cons of
1583 variables and their default expressions to be evalled (when the default
1584 values are not nil), that should be made global while the summary buffer
1585 is active.
1586
1587 Note: The default expressions will be evaluated (using function `eval')
1588 before assignment to the local variable rather than just assigned to it.
1589 If the default expression is the symbol `global', that symbol will not
1590 be evaluated but the global value of the local variable will be used
1591 instead.
1592
1593 These variables can be used to set variables in the group parameters
1594 while still allowing them to affect operations done in other buffers.
1595 For example:
1596
1597 \(setq gnus-newsgroup-variables
1598      '(message-use-followup-to
1599        (gnus-visible-headers .
1600          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1601 ")
1602
1603 (eval-when-compile
1604   ;; Bind features so that require will believe that gnus-sum has
1605   ;; already been loaded (avoids infinite recursion)
1606   (let ((features (cons 'gnus-sum features)))
1607     (require 'gnus-art)))
1608
1609 ;; MIME stuff.
1610
1611 (defvar gnus-decode-encoded-word-methods
1612   '(mail-decode-encoded-word-string)
1613   "List of methods used to decode encoded words.
1614
1615 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1616 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1617 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1618 whose names match REGEXP.
1619
1620 For example:
1621 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1622  mail-decode-encoded-word-string
1623  (\"chinese\" . rfc1843-decode-string))")
1624
1625 (defvar gnus-decode-encoded-word-methods-cache nil)
1626
1627 (defun gnus-multi-decode-encoded-word-string (string)
1628   "Apply the functions from `gnus-encoded-word-methods' that match."
1629   (unless (and gnus-decode-encoded-word-methods-cache
1630                (eq gnus-newsgroup-name
1631                    (car gnus-decode-encoded-word-methods-cache)))
1632     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1633     (dolist (method gnus-decode-encoded-word-methods)
1634       (if (symbolp method)
1635           (nconc gnus-decode-encoded-word-methods-cache (list method))
1636         (if (and gnus-newsgroup-name
1637                  (string-match (car method) gnus-newsgroup-name))
1638             (nconc gnus-decode-encoded-word-methods-cache
1639                    (list (cdr method)))))))
1640   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1641     (setq string (funcall method string))))
1642
1643 ;; Subject simplification.
1644
1645 (defun gnus-simplify-whitespace (str)
1646   "Remove excessive whitespace from STR."
1647   ;; Multiple spaces.
1648   (while (string-match "[ \t][ \t]+" str)
1649     (setq str (concat (substring str 0 (match-beginning 0))
1650                         " "
1651                         (substring str (match-end 0)))))
1652   ;; Leading spaces.
1653   (when (string-match "^[ \t]+" str)
1654     (setq str (substring str (match-end 0))))
1655   ;; Trailing spaces.
1656   (when (string-match "[ \t]+$" str)
1657     (setq str (substring str 0 (match-beginning 0))))
1658   str)
1659
1660 (defun gnus-simplify-all-whitespace (str)
1661   "Remove all whitespace from STR."
1662   (while (string-match "[ \t\n]+" str)
1663     (setq str (replace-match "" nil nil str)))
1664   str)
1665
1666 (defsubst gnus-simplify-subject-re (subject)
1667   "Remove \"Re:\" from subject lines."
1668   (if (string-match message-subject-re-regexp subject)
1669       (substring subject (match-end 0))
1670     subject))
1671
1672 (defun gnus-simplify-subject (subject &optional re-only)
1673   "Remove `Re:' and words in parentheses.
1674 If RE-ONLY is non-nil, strip leading `Re:'s only."
1675   (let ((case-fold-search t))           ;Ignore case.
1676     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1677     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1678       (setq subject (substring subject (match-end 0))))
1679     ;; Remove uninteresting prefixes.
1680     (when (and (not re-only)
1681                gnus-simplify-ignored-prefixes
1682                (string-match gnus-simplify-ignored-prefixes subject))
1683       (setq subject (substring subject (match-end 0))))
1684     ;; Remove words in parentheses from end.
1685     (unless re-only
1686       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1687         (setq subject (substring subject 0 (match-beginning 0)))))
1688     ;; Return subject string.
1689     subject))
1690
1691 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1692 ;; all whitespace.
1693 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1694   (goto-char (point-min))
1695   (while (re-search-forward regexp nil t)
1696     (replace-match (or newtext ""))))
1697
1698 (defun gnus-simplify-buffer-fuzzy ()
1699   "Simplify string in the buffer fuzzily.
1700 The string in the accessible portion of the current buffer is simplified.
1701 It is assumed to be a single-line subject.
1702 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1703 matter is removed.  Additional things can be deleted by setting
1704 `gnus-simplify-subject-fuzzy-regexp'."
1705   (let ((case-fold-search t)
1706         (modified-tick))
1707     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1708
1709     (while (not (eq modified-tick (buffer-modified-tick)))
1710       (setq modified-tick (buffer-modified-tick))
1711       (cond
1712        ((listp gnus-simplify-subject-fuzzy-regexp)
1713         (mapc 'gnus-simplify-buffer-fuzzy-step
1714               gnus-simplify-subject-fuzzy-regexp))
1715        (gnus-simplify-subject-fuzzy-regexp
1716         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1717       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1718       (gnus-simplify-buffer-fuzzy-step
1719        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1720       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1721
1722     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1723     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1724     (gnus-simplify-buffer-fuzzy-step " $")
1725     (gnus-simplify-buffer-fuzzy-step "^ +")))
1726
1727 (defun gnus-simplify-subject-fuzzy (subject)
1728   "Simplify a subject string fuzzily.
1729 See `gnus-simplify-buffer-fuzzy' for details."
1730   (save-excursion
1731     (gnus-set-work-buffer)
1732     (let ((case-fold-search t))
1733       ;; Remove uninteresting prefixes.
1734       (when (and gnus-simplify-ignored-prefixes
1735                  (string-match gnus-simplify-ignored-prefixes subject))
1736         (setq subject (substring subject (match-end 0))))
1737       (insert subject)
1738       (inline (gnus-simplify-buffer-fuzzy))
1739       (buffer-string))))
1740
1741 (defsubst gnus-simplify-subject-fully (subject)
1742   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1743   (cond
1744    (gnus-simplify-subject-functions
1745     (gnus-map-function gnus-simplify-subject-functions subject))
1746    ((null gnus-summary-gather-subject-limit)
1747     (gnus-simplify-subject-re subject))
1748    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1749     (gnus-simplify-subject-fuzzy subject))
1750    ((numberp gnus-summary-gather-subject-limit)
1751     (truncate-string-to-width (gnus-simplify-subject-re subject)
1752                               gnus-summary-gather-subject-limit))
1753    (t
1754     subject)))
1755
1756 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1757   "Check whether two subjects are equal.
1758 If optional argument SIMPLE-FIRST is t, first argument is already
1759 simplified."
1760   (cond
1761    ((null simple-first)
1762     (equal (gnus-simplify-subject-fully s1)
1763            (gnus-simplify-subject-fully s2)))
1764    (t
1765     (equal s1
1766            (gnus-simplify-subject-fully s2)))))
1767
1768 (defun gnus-summary-bubble-group ()
1769   "Increase the score of the current group.
1770 This is a handy function to add to `gnus-summary-exit-hook' to
1771 increase the score of each group you read."
1772   (gnus-group-add-score gnus-newsgroup-name))
1773
1774 \f
1775 ;;;
1776 ;;; Gnus summary mode
1777 ;;;
1778
1779 (put 'gnus-summary-mode 'mode-class 'special)
1780
1781 (defvar gnus-article-commands-menu)
1782
1783 ;; Non-orthogonal keys
1784
1785 (gnus-define-keys gnus-summary-mode-map
1786   " " gnus-summary-next-page
1787   "\177" gnus-summary-prev-page
1788   [delete] gnus-summary-prev-page
1789   [backspace] gnus-summary-prev-page
1790   "\r" gnus-summary-scroll-up
1791   "\M-\r" gnus-summary-scroll-down
1792   "n" gnus-summary-next-unread-article
1793   "p" gnus-summary-prev-unread-article
1794   "N" gnus-summary-next-article
1795   "P" gnus-summary-prev-article
1796   "\M-\C-n" gnus-summary-next-same-subject
1797   "\M-\C-p" gnus-summary-prev-same-subject
1798   "\M-n" gnus-summary-next-unread-subject
1799   "\M-p" gnus-summary-prev-unread-subject
1800   "." gnus-summary-first-unread-article
1801   "," gnus-summary-best-unread-article
1802   "\M-s" gnus-summary-search-article-forward
1803   "\M-r" gnus-summary-search-article-backward
1804   "\M-S" gnus-summary-repeat-search-article-forward
1805   "\M-R" gnus-summary-repeat-search-article-backward
1806   "<" gnus-summary-beginning-of-article
1807   ">" gnus-summary-end-of-article
1808   "j" gnus-summary-goto-article
1809   "^" gnus-summary-refer-parent-article
1810   "\M-^" gnus-summary-refer-article
1811   "u" gnus-summary-tick-article-forward
1812   "!" gnus-summary-tick-article-forward
1813   "U" gnus-summary-tick-article-backward
1814   "d" gnus-summary-mark-as-read-forward
1815   "D" gnus-summary-mark-as-read-backward
1816   "E" gnus-summary-mark-as-expirable
1817   "\M-u" gnus-summary-clear-mark-forward
1818   "\M-U" gnus-summary-clear-mark-backward
1819   "k" gnus-summary-kill-same-subject-and-select
1820   "\C-k" gnus-summary-kill-same-subject
1821   "\M-\C-k" gnus-summary-kill-thread
1822   "\M-\C-l" gnus-summary-lower-thread
1823   "e" gnus-summary-edit-article
1824   "#" gnus-summary-mark-as-processable
1825   "\M-#" gnus-summary-unmark-as-processable
1826   "\M-\C-t" gnus-summary-toggle-threads
1827   "\M-\C-s" gnus-summary-show-thread
1828   "\M-\C-h" gnus-summary-hide-thread
1829   "\M-\C-f" gnus-summary-next-thread
1830   "\M-\C-b" gnus-summary-prev-thread
1831   [(meta down)] gnus-summary-next-thread
1832   [(meta up)] gnus-summary-prev-thread
1833   "\M-\C-u" gnus-summary-up-thread
1834   "\M-\C-d" gnus-summary-down-thread
1835   "&" gnus-summary-execute-command
1836   "c" gnus-summary-catchup-and-exit
1837   "\C-w" gnus-summary-mark-region-as-read
1838   "\C-t" gnus-summary-toggle-truncation
1839   "?" gnus-summary-mark-as-dormant
1840   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1841   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1842   "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
1843   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1844   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1845   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1846   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1847   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1848   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1849   "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
1850   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1851   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1852   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1853   "=" gnus-summary-expand-window
1854   "\C-x\C-s" gnus-summary-reselect-current-group
1855   "\M-g" gnus-summary-rescan-group
1856   "w" gnus-summary-stop-page-breaking
1857   "\C-c\C-r" gnus-summary-caesar-message
1858   "f" gnus-summary-followup
1859   "F" gnus-summary-followup-with-original
1860   "C" gnus-summary-cancel-article
1861   "r" gnus-summary-reply
1862   "R" gnus-summary-reply-with-original
1863   "\C-c\C-f" gnus-summary-mail-forward
1864   "o" gnus-summary-save-article
1865   "\C-o" gnus-summary-save-article-mail
1866   "|" gnus-summary-pipe-output
1867   "\M-k" gnus-summary-edit-local-kill
1868   "\M-K" gnus-summary-edit-global-kill
1869   ;; "V" gnus-version
1870   "\C-c\C-d" gnus-summary-describe-group
1871   "q" gnus-summary-exit
1872   "Q" gnus-summary-exit-no-update
1873   "\C-c\C-i" gnus-info-find-node
1874   gnus-mouse-2 gnus-mouse-pick-article
1875   [follow-link] mouse-face
1876   "m" gnus-summary-mail-other-window
1877   "a" gnus-summary-post-news
1878   "i" gnus-summary-news-other-window
1879   "x" gnus-summary-limit-to-unread
1880   "s" gnus-summary-isearch-article
1881   "t" gnus-summary-toggle-header
1882   "g" gnus-summary-show-article
1883   "l" gnus-summary-goto-last-article
1884   "\C-c\C-v\C-v" gnus-uu-decode-uu-view
1885   "\C-d" gnus-summary-enter-digest-group
1886   "\M-\C-d" gnus-summary-read-document
1887   "\M-\C-e" gnus-summary-edit-parameters
1888   "\M-\C-a" gnus-summary-customize-parameters
1889   "\C-c\C-b" gnus-bug
1890   "*" gnus-cache-enter-article
1891   "\M-*" gnus-cache-remove-article
1892   "\M-&" gnus-summary-universal-argument
1893   "\C-l" gnus-recenter
1894   "I" gnus-summary-increase-score
1895   "L" gnus-summary-lower-score
1896   "\M-i" gnus-symbolic-argument
1897   "h" gnus-summary-select-article-buffer
1898
1899   "b" gnus-article-view-part
1900   "\M-t" gnus-summary-toggle-display-buttonized
1901
1902   "V" gnus-summary-score-map
1903   "X" gnus-uu-extract-map
1904   "S" gnus-summary-send-map)
1905
1906 ;; Sort of orthogonal keymap
1907 (gnus-define-keys (gnus-summary-mark-map "M" gnus-summary-mode-map)
1908   "t" gnus-summary-tick-article-forward
1909   "!" gnus-summary-tick-article-forward
1910   "d" gnus-summary-mark-as-read-forward
1911   "r" gnus-summary-mark-as-read-forward
1912   "c" gnus-summary-clear-mark-forward
1913   " " gnus-summary-clear-mark-forward
1914   "e" gnus-summary-mark-as-expirable
1915   "x" gnus-summary-mark-as-expirable
1916   "?" gnus-summary-mark-as-dormant
1917   "b" gnus-summary-set-bookmark
1918   "B" gnus-summary-remove-bookmark
1919   "#" gnus-summary-mark-as-processable
1920   "\M-#" gnus-summary-unmark-as-processable
1921   "S" gnus-summary-limit-include-expunged
1922   "C" gnus-summary-catchup
1923   "H" gnus-summary-catchup-to-here
1924   "h" gnus-summary-catchup-from-here
1925   "\C-c" gnus-summary-catchup-all
1926   "k" gnus-summary-kill-same-subject-and-select
1927   "K" gnus-summary-kill-same-subject
1928   "P" gnus-uu-mark-map)
1929
1930 (gnus-define-keys (gnus-summary-mscore-map "V" gnus-summary-mark-map)
1931   "c" gnus-summary-clear-above
1932   "u" gnus-summary-tick-above
1933   "m" gnus-summary-mark-above
1934   "k" gnus-summary-kill-below)
1935
1936 (gnus-define-keys (gnus-summary-limit-map "/" gnus-summary-mode-map)
1937   "/" gnus-summary-limit-to-subject
1938   "n" gnus-summary-limit-to-articles
1939   "b" gnus-summary-limit-to-bodies
1940   "h" gnus-summary-limit-to-headers
1941   "w" gnus-summary-pop-limit
1942   "s" gnus-summary-limit-to-subject
1943   "a" gnus-summary-limit-to-author
1944   "u" gnus-summary-limit-to-unread
1945   "m" gnus-summary-limit-to-marks
1946   "M" gnus-summary-limit-exclude-marks
1947   "v" gnus-summary-limit-to-score
1948   "*" gnus-summary-limit-include-cached
1949   "D" gnus-summary-limit-include-dormant
1950   "T" gnus-summary-limit-include-thread
1951   "d" gnus-summary-limit-exclude-dormant
1952   "t" gnus-summary-limit-to-age
1953   "." gnus-summary-limit-to-unseen
1954   "x" gnus-summary-limit-to-extra
1955   "p" gnus-summary-limit-to-display-predicate
1956   "E" gnus-summary-limit-include-expunged
1957   "c" gnus-summary-limit-exclude-childless-dormant
1958   "C" gnus-summary-limit-mark-excluded-as-read
1959   "o" gnus-summary-insert-old-articles
1960   "N" gnus-summary-insert-new-articles
1961   "S" gnus-summary-limit-to-singletons
1962   "r" gnus-summary-limit-to-replied
1963   "R" gnus-summary-limit-to-recipient
1964   "A" gnus-summary-limit-to-address)
1965
1966 (gnus-define-keys (gnus-summary-goto-map "G" gnus-summary-mode-map)
1967   "n" gnus-summary-next-unread-article
1968   "p" gnus-summary-prev-unread-article
1969   "N" gnus-summary-next-article
1970   "P" gnus-summary-prev-article
1971   "\C-n" gnus-summary-next-same-subject
1972   "\C-p" gnus-summary-prev-same-subject
1973   "\M-n" gnus-summary-next-unread-subject
1974   "\M-p" gnus-summary-prev-unread-subject
1975   "f" gnus-summary-first-unread-article
1976   "b" gnus-summary-best-unread-article
1977   "j" gnus-summary-goto-article
1978   "g" gnus-summary-goto-subject
1979   "l" gnus-summary-goto-last-article
1980   "o" gnus-summary-pop-article)
1981
1982 (gnus-define-keys (gnus-summary-thread-map "T" gnus-summary-mode-map)
1983   "k" gnus-summary-kill-thread
1984   "E" gnus-summary-expire-thread
1985   "l" gnus-summary-lower-thread
1986   "i" gnus-summary-raise-thread
1987   "T" gnus-summary-toggle-threads
1988   "t" gnus-summary-rethread-current
1989   "^" gnus-summary-reparent-thread
1990   "\M-^" gnus-summary-reparent-children
1991   "s" gnus-summary-show-thread
1992   "S" gnus-summary-show-all-threads
1993   "h" gnus-summary-hide-thread
1994   "H" gnus-summary-hide-all-threads
1995   "n" gnus-summary-next-thread
1996   "p" gnus-summary-prev-thread
1997   "u" gnus-summary-up-thread
1998   "o" gnus-summary-top-thread
1999   "d" gnus-summary-down-thread
2000   "#" gnus-uu-mark-thread
2001   "\M-#" gnus-uu-unmark-thread)
2002
2003 (gnus-define-keys (gnus-summary-buffer-map "Y" gnus-summary-mode-map)
2004   "g" gnus-summary-prepare
2005   "c" gnus-summary-insert-cached-articles
2006   "d" gnus-summary-insert-dormant-articles
2007   "t" gnus-summary-insert-ticked-articles)
2008
2009 (gnus-define-keys (gnus-summary-exit-map "Z" gnus-summary-mode-map)
2010   "c" gnus-summary-catchup-and-exit
2011   "C" gnus-summary-catchup-all-and-exit
2012   "E" gnus-summary-exit-no-update
2013   "Q" gnus-summary-exit
2014   "Z" gnus-summary-exit
2015   "n" gnus-summary-catchup-and-goto-next-group
2016   "p" gnus-summary-catchup-and-goto-prev-group
2017   "R" gnus-summary-reselect-current-group
2018   "G" gnus-summary-rescan-group
2019   "N" gnus-summary-next-group
2020   "s" gnus-summary-save-newsrc
2021   "P" gnus-summary-prev-group)
2022
2023 (gnus-define-keys (gnus-summary-article-map "A" gnus-summary-mode-map)
2024   " " gnus-summary-next-page
2025   "n" gnus-summary-next-page
2026   "\177" gnus-summary-prev-page
2027   [delete] gnus-summary-prev-page
2028   "p" gnus-summary-prev-page
2029   "\r" gnus-summary-scroll-up
2030   "\M-\r" gnus-summary-scroll-down
2031   "<" gnus-summary-beginning-of-article
2032   ">" gnus-summary-end-of-article
2033   "b" gnus-summary-beginning-of-article
2034   "e" gnus-summary-end-of-article
2035   "^" gnus-summary-refer-parent-article
2036   "r" gnus-summary-refer-parent-article
2037   "D" gnus-summary-enter-digest-group
2038   "R" gnus-summary-refer-references
2039   "T" gnus-summary-refer-thread
2040   "g" gnus-summary-show-article
2041   "s" gnus-summary-isearch-article
2042   "P" gnus-summary-print-article
2043   "S" gnus-sticky-article
2044   "M" gnus-mailing-list-insinuate
2045   "t" gnus-article-babel)
2046
2047 (gnus-define-keys (gnus-summary-wash-map "W" gnus-summary-mode-map)
2048   "b" gnus-article-add-buttons
2049   "B" gnus-article-add-buttons-to-head
2050   "o" gnus-article-treat-overstrike
2051   "e" gnus-article-emphasize
2052   "w" gnus-article-fill-cited-article
2053   "Q" gnus-article-fill-long-lines
2054   "L" gnus-article-toggle-truncate-lines
2055   "C" gnus-article-capitalize-sentences
2056   "c" gnus-article-remove-cr
2057   "q" gnus-article-de-quoted-unreadable
2058   "6" gnus-article-de-base64-unreadable
2059   "Z" gnus-article-decode-HZ
2060   "A" gnus-article-treat-ansi-sequences
2061   "h" gnus-article-wash-html
2062   "u" gnus-article-unsplit-urls
2063   "s" gnus-summary-force-verify-and-decrypt
2064   "f" gnus-article-display-x-face
2065   "l" gnus-summary-stop-page-breaking
2066   "r" gnus-summary-caesar-message
2067   "m" gnus-summary-morse-message
2068   "t" gnus-summary-toggle-header
2069   "g" gnus-treat-smiley
2070   "v" gnus-summary-verbose-headers
2071   "a" gnus-article-strip-headers-in-body ;; mnemonic: wash archive
2072   "p" gnus-article-verify-x-pgp-sig
2073   "d" gnus-article-treat-dumbquotes
2074   "i" gnus-summary-idna-message)
2075
2076 (gnus-define-keys (gnus-summary-wash-deuglify-map "Y" gnus-summary-wash-map)
2077   ;; mnemonic: deuglif*Y*
2078   "u" gnus-article-outlook-unwrap-lines
2079   "a" gnus-article-outlook-repair-attribution
2080   "c" gnus-article-outlook-rearrange-citation
2081   "f" gnus-article-outlook-deuglify-article) ;; mnemonic: full deuglify
2082
2083 (gnus-define-keys (gnus-summary-wash-hide-map "W" gnus-summary-wash-map)
2084   "a" gnus-article-hide
2085   "h" gnus-article-hide-headers
2086   "b" gnus-article-hide-boring-headers
2087   "s" gnus-article-hide-signature
2088   "c" gnus-article-hide-citation
2089   "C" gnus-article-hide-citation-in-followups
2090   "l" gnus-article-hide-list-identifiers
2091   "B" gnus-article-strip-banner
2092   "P" gnus-article-hide-pem
2093   "\C-c" gnus-article-hide-citation-maybe)
2094
2095 (gnus-define-keys (gnus-summary-wash-highlight-map "H" gnus-summary-wash-map)
2096   "a" gnus-article-highlight
2097   "h" gnus-article-highlight-headers
2098   "c" gnus-article-highlight-citation
2099   "s" gnus-article-highlight-signature)
2100
2101 (gnus-define-keys (gnus-summary-wash-header-map "G" gnus-summary-wash-map)
2102   "f" gnus-article-treat-fold-headers
2103   "u" gnus-article-treat-unfold-headers
2104   "n" gnus-article-treat-fold-newsgroups)
2105
2106 (gnus-define-keys (gnus-summary-wash-display-map "D" gnus-summary-wash-map)
2107   "x" gnus-article-display-x-face
2108   "d" gnus-article-display-face
2109   "s" gnus-treat-smiley
2110   "D" gnus-article-remove-images
2111   "f" gnus-treat-from-picon
2112   "m" gnus-treat-mail-picon
2113   "n" gnus-treat-newsgroups-picon)
2114
2115 (gnus-define-keys (gnus-summary-wash-mime-map "M" gnus-summary-wash-map)
2116   "w" gnus-article-decode-mime-words
2117   "c" gnus-article-decode-charset
2118   "v" gnus-mime-view-all-parts
2119   "b" gnus-article-view-part)
2120
2121 (gnus-define-keys (gnus-summary-wash-time-map "T" gnus-summary-wash-map)
2122   "z" gnus-article-date-ut
2123   "u" gnus-article-date-ut
2124   "l" gnus-article-date-local
2125   "p" gnus-article-date-english
2126   "e" gnus-article-date-lapsed
2127   "o" gnus-article-date-original
2128   "i" gnus-article-date-iso8601
2129   "s" gnus-article-date-user)
2130
2131 (gnus-define-keys (gnus-summary-wash-empty-map "E" gnus-summary-wash-map)
2132   "t" gnus-article-remove-trailing-blank-lines
2133   "l" gnus-article-strip-leading-blank-lines
2134   "m" gnus-article-strip-multiple-blank-lines
2135   "a" gnus-article-strip-blank-lines
2136   "A" gnus-article-strip-all-blank-lines
2137   "s" gnus-article-strip-leading-space
2138   "e" gnus-article-strip-trailing-space
2139   "w" gnus-article-remove-leading-whitespace)
2140
2141 (gnus-define-keys (gnus-summary-help-map "H" gnus-summary-mode-map)
2142   "v" gnus-version
2143   "f" gnus-summary-fetch-faq
2144   "d" gnus-summary-describe-group
2145   "h" gnus-summary-describe-briefly
2146   "i" gnus-info-find-node
2147   "c" gnus-group-fetch-charter
2148   "C" gnus-group-fetch-control)
2149
2150 (gnus-define-keys (gnus-summary-backend-map "B" gnus-summary-mode-map)
2151   "e" gnus-summary-expire-articles
2152   "\M-\C-e" gnus-summary-expire-articles-now
2153   "\177" gnus-summary-delete-article
2154   [delete] gnus-summary-delete-article
2155   [backspace] gnus-summary-delete-article
2156   "m" gnus-summary-move-article
2157   "r" gnus-summary-respool-article
2158   "w" gnus-summary-edit-article
2159   "c" gnus-summary-copy-article
2160   "B" gnus-summary-crosspost-article
2161   "q" gnus-summary-respool-query
2162   "t" gnus-summary-respool-trace
2163   "i" gnus-summary-import-article
2164   "I" gnus-summary-create-article
2165   "p" gnus-summary-article-posted-p)
2166
2167 (gnus-define-keys (gnus-summary-save-map "O" gnus-summary-mode-map)
2168   "o" gnus-summary-save-article
2169   "m" gnus-summary-save-article-mail
2170   "F" gnus-summary-write-article-file
2171   "r" gnus-summary-save-article-rmail
2172   "f" gnus-summary-save-article-file
2173   "b" gnus-summary-save-article-body-file
2174   "B" gnus-summary-write-article-body-file
2175   "h" gnus-summary-save-article-folder
2176   "v" gnus-summary-save-article-vm
2177   "p" gnus-summary-pipe-output
2178   "P" gnus-summary-muttprint
2179   "s" gnus-soup-add-article)
2180
2181 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2182   "b" gnus-summary-display-buttonized
2183   "m" gnus-summary-repair-multipart
2184   "v" gnus-article-view-part
2185   "o" gnus-article-save-part
2186   "O" gnus-article-save-part-and-strip
2187   "r" gnus-article-replace-part
2188   "d" gnus-article-delete-part
2189   "t" gnus-article-view-part-as-type
2190   "j" gnus-article-jump-to-part
2191   "c" gnus-article-copy-part
2192   "C" gnus-article-view-part-as-charset
2193   "e" gnus-article-view-part-externally
2194   "H" gnus-article-browse-html-article
2195   "E" gnus-article-encrypt-body
2196   "i" gnus-article-inline-part
2197   "|" gnus-article-pipe-part)
2198
2199 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2200   "p" gnus-summary-mark-as-processable
2201   "u" gnus-summary-unmark-as-processable
2202   "U" gnus-summary-unmark-all-processable
2203   "v" gnus-uu-mark-over
2204   "s" gnus-uu-mark-series
2205   "r" gnus-uu-mark-region
2206   "g" gnus-uu-unmark-region
2207   "R" gnus-uu-mark-by-regexp
2208   "G" gnus-uu-unmark-by-regexp
2209   "t" gnus-uu-mark-thread
2210   "T" gnus-uu-unmark-thread
2211   "a" gnus-uu-mark-all
2212   "b" gnus-uu-mark-buffer
2213   "S" gnus-uu-mark-sparse
2214   "k" gnus-summary-kill-process-mark
2215   "y" gnus-summary-yank-process-mark
2216   "w" gnus-summary-save-process-mark
2217   "i" gnus-uu-invert-processable)
2218
2219 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2220   ;;"x" gnus-uu-extract-any
2221   "m" gnus-summary-save-parts
2222   "u" gnus-uu-decode-uu
2223   "U" gnus-uu-decode-uu-and-save
2224   "s" gnus-uu-decode-unshar
2225   "S" gnus-uu-decode-unshar-and-save
2226   "o" gnus-uu-decode-save
2227   "O" gnus-uu-decode-save
2228   "b" gnus-uu-decode-binhex
2229   "B" gnus-uu-decode-binhex
2230   "Y" gnus-uu-decode-yenc
2231   "p" gnus-uu-decode-postscript
2232   "P" gnus-uu-decode-postscript-and-save)
2233
2234 (gnus-define-keys
2235     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2236   "u" gnus-uu-decode-uu-view
2237   "U" gnus-uu-decode-uu-and-save-view
2238   "s" gnus-uu-decode-unshar-view
2239   "S" gnus-uu-decode-unshar-and-save-view
2240   "o" gnus-uu-decode-save-view
2241   "O" gnus-uu-decode-save-view
2242   "b" gnus-uu-decode-binhex-view
2243   "B" gnus-uu-decode-binhex-view
2244   "p" gnus-uu-decode-postscript-view
2245   "P" gnus-uu-decode-postscript-and-save-view)
2246
2247 (defvar gnus-article-post-menu nil)
2248
2249 (defconst gnus-summary-menu-maxlen 20)
2250
2251 (defun gnus-summary-menu-split (menu)
2252   ;; If we have lots of elements, divide them into groups of 20
2253   ;; and make a pane (or submenu) for each one.
2254   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2255       (let ((menu menu) sublists next
2256             (i 1))
2257         (while menu
2258           ;; Pull off the next gnus-summary-menu-maxlen elements
2259           ;; and make them the next element of sublist.
2260           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2261           (if next
2262               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2263                       nil))
2264           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2265                                              (aref (car (last menu)) 0)) menu)
2266                                sublists))
2267           (setq i (1+ i))
2268           (setq menu next))
2269         (nreverse sublists))
2270     ;; Few elements--put them all in one pane.
2271     menu))
2272
2273 (defun gnus-summary-make-menu-bar ()
2274   (gnus-turn-off-edit-menu 'summary)
2275
2276   (unless (boundp 'gnus-summary-misc-menu)
2277
2278     (easy-menu-define
2279       gnus-summary-kill-menu gnus-summary-mode-map ""
2280       (cons
2281        "Score"
2282        (nconc
2283         (list
2284          ["Customize" gnus-score-customize t])
2285         (gnus-make-score-map 'increase)
2286         (gnus-make-score-map 'lower)
2287         '(("Mark"
2288            ["Kill below" gnus-summary-kill-below t]
2289            ["Mark above" gnus-summary-mark-above t]
2290            ["Tick above" gnus-summary-tick-above t]
2291            ["Clear above" gnus-summary-clear-above t])
2292           ["Current score" gnus-summary-current-score t]
2293           ["Set score" gnus-summary-set-score t]
2294           ["Switch current score file..." gnus-score-change-score-file t]
2295           ["Set mark below..." gnus-score-set-mark-below t]
2296           ["Set expunge below..." gnus-score-set-expunge-below t]
2297           ["Edit current score file" gnus-score-edit-current-scores t]
2298           ["Edit score file..." gnus-score-edit-file t]
2299           ["Trace score" gnus-score-find-trace t]
2300           ["Find words" gnus-score-find-favourite-words t]
2301           ["Rescore buffer" gnus-summary-rescore t]
2302           ["Increase score..." gnus-summary-increase-score t]
2303           ["Lower score..." gnus-summary-lower-score t]))))
2304
2305     ;; Define both the Article menu in the summary buffer and the
2306     ;; equivalent Commands menu in the article buffer here for
2307     ;; consistency.
2308     (let ((innards
2309            `(("Hide"
2310               ["All" gnus-article-hide t]
2311               ["Headers" gnus-article-hide-headers t]
2312               ["Signature" gnus-article-hide-signature t]
2313               ["Citation" gnus-article-hide-citation t]
2314               ["List identifiers" gnus-article-hide-list-identifiers t]
2315               ["Banner" gnus-article-strip-banner t]
2316               ["Boring headers" gnus-article-hide-boring-headers t])
2317              ("Highlight"
2318               ["All" gnus-article-highlight t]
2319               ["Headers" gnus-article-highlight-headers t]
2320               ["Signature" gnus-article-highlight-signature t]
2321               ["Citation" gnus-article-highlight-citation t])
2322              ("MIME"
2323               ["Words" gnus-article-decode-mime-words t]
2324               ["Charset" gnus-article-decode-charset t]
2325               ["QP" gnus-article-de-quoted-unreadable t]
2326               ["Base64" gnus-article-de-base64-unreadable t]
2327               ["View MIME buttons" gnus-summary-display-buttonized t]
2328               ["View all" gnus-mime-view-all-parts t]
2329               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2330               ["Encrypt body" gnus-article-encrypt-body
2331                :active (not (gnus-group-read-only-p))
2332                ,@(if (featurep 'xemacs) nil
2333                    '(:help "Encrypt the message body on disk"))]
2334               ["Extract all parts..." gnus-summary-save-parts t]
2335               ("Multipart"
2336                ["Repair multipart" gnus-summary-repair-multipart t]
2337                ["Pipe part..." gnus-article-pipe-part t]
2338                ["Inline part" gnus-article-inline-part t]
2339                ["View part as type..." gnus-article-view-part-as-type t]
2340                ["Encrypt body" gnus-article-encrypt-body
2341                 :active (not (gnus-group-read-only-p))
2342                ,@(if (featurep 'xemacs) nil
2343                    '(:help "Encrypt the message body on disk"))]
2344                ["View part externally" gnus-article-view-part-externally t]
2345                ["View HTML parts in browser" gnus-article-browse-html-article t]
2346                ["View part with charset..." gnus-article-view-part-as-charset t]
2347                ["Copy part" gnus-article-copy-part t]
2348                ["Save part..." gnus-article-save-part t]
2349                ["View part" gnus-article-view-part t]))
2350              ("Date"
2351               ["Local" gnus-article-date-local t]
2352               ["ISO8601" gnus-article-date-iso8601 t]
2353               ["UT" gnus-article-date-ut t]
2354               ["Original" gnus-article-date-original t]
2355               ["Lapsed" gnus-article-date-lapsed t]
2356               ["User-defined" gnus-article-date-user t])
2357              ("Display"
2358               ["Remove images" gnus-article-remove-images t]
2359               ["Toggle smiley" gnus-treat-smiley t]
2360               ["Show X-Face" gnus-article-display-x-face t]
2361               ["Show picons in From" gnus-treat-from-picon t]
2362               ["Show picons in mail headers" gnus-treat-mail-picon t]
2363               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2364               ("View as different encoding"
2365                ,@(gnus-summary-menu-split
2366                   (mapcar
2367                    (lambda (cs)
2368                      ;; Since easymenu under Emacs doesn't allow
2369                      ;; lambda forms for menu commands, we should
2370                      ;; provide intern'ed function symbols.
2371                      (let ((command (intern (format "\
2372 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2373                        (fset command
2374                              `(lambda ()
2375                                 (interactive)
2376                                 (let ((gnus-summary-show-article-charset-alist
2377                                        '((1 . ,cs))))
2378                                   (gnus-summary-show-article 1))))
2379                        `[,(symbol-name cs) ,command t]))
2380                    (sort (if (fboundp 'coding-system-list)
2381                              (coding-system-list)
2382                            (mapcar 'car mm-mime-mule-charset-alist))
2383                          'string<)))))
2384              ("Washing"
2385               ("Remove Blanks"
2386                ["Leading" gnus-article-strip-leading-blank-lines t]
2387                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2388                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2389                ["All of the above" gnus-article-strip-blank-lines t]
2390                ["All" gnus-article-strip-all-blank-lines t]
2391                ["Leading space" gnus-article-strip-leading-space t]
2392                ["Trailing space" gnus-article-strip-trailing-space t]
2393                ["Leading space in headers"
2394                 gnus-article-remove-leading-whitespace t])
2395               ["Overstrike" gnus-article-treat-overstrike t]
2396               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2397               ["Emphasis" gnus-article-emphasize t]
2398               ["Word wrap" gnus-article-fill-cited-article t]
2399               ["Fill long lines" gnus-article-fill-long-lines t]
2400               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2401               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2402               ["Remove CR" gnus-article-remove-cr t]
2403               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2404               ["Base64" gnus-article-de-base64-unreadable t]
2405               ["Rot 13" gnus-summary-caesar-message
2406                ,@(if (featurep 'xemacs) '(t)
2407                    '(:help "\"Caesar rotate\" article by 13"))]
2408               ["De-IDNA" gnus-summary-idna-message t]
2409               ["Morse decode" gnus-summary-morse-message t]
2410               ["Unix pipe..." gnus-summary-pipe-message t]
2411               ["Add buttons" gnus-article-add-buttons t]
2412               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2413               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2414               ["Verbose header" gnus-summary-verbose-headers t]
2415               ["Toggle header" gnus-summary-toggle-header t]
2416               ["Unfold headers" gnus-article-treat-unfold-headers t]
2417               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2418               ["Html" gnus-article-wash-html t]
2419               ["Unsplit URLs" gnus-article-unsplit-urls t]
2420               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2421               ["Decode HZ" gnus-article-decode-HZ t]
2422               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2423               ("(Outlook) Deuglify"
2424                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2425                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2426                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2427                ["Full (Outlook) deuglify"
2428                 gnus-article-outlook-deuglify-article t])
2429               )
2430              ("Output"
2431               ["Save in default format..." gnus-summary-save-article
2432                ,@(if (featurep 'xemacs) '(t)
2433                    '(:help "Save article using default method"))]
2434               ["Save in file..." gnus-summary-save-article-file
2435                ,@(if (featurep 'xemacs) '(t)
2436                    '(:help "Save article in file"))]
2437               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2438               ["Save in MH folder..." gnus-summary-save-article-folder t]
2439               ["Save in VM folder..." gnus-summary-save-article-vm t]
2440               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2441               ["Save body in file..." gnus-summary-save-article-body-file t]
2442               ["Pipe through a filter..." gnus-summary-pipe-output t]
2443               ["Add to SOUP packet" gnus-soup-add-article t]
2444               ["Print with Muttprint..." gnus-summary-muttprint t]
2445               ["Print" gnus-summary-print-article
2446                ,@(if (featurep 'xemacs) '(t)
2447                    '(:help "Generate and print a PostScript image"))])
2448              ("Copy, move,... (Backend)"
2449               ,@(if (featurep 'xemacs) nil
2450                   '(:help "Copying, moving, expiring articles..."))
2451               ["Respool article..." gnus-summary-respool-article t]
2452               ["Move article..." gnus-summary-move-article
2453                (gnus-check-backend-function
2454                 'request-move-article gnus-newsgroup-name)]
2455               ["Copy article..." gnus-summary-copy-article t]
2456               ["Crosspost article..." gnus-summary-crosspost-article
2457                (gnus-check-backend-function
2458                 'request-replace-article gnus-newsgroup-name)]
2459               ["Import file..." gnus-summary-import-article
2460                (gnus-check-backend-function
2461                 'request-accept-article gnus-newsgroup-name)]
2462               ["Create article..." gnus-summary-create-article
2463                (gnus-check-backend-function
2464                 'request-accept-article gnus-newsgroup-name)]
2465               ["Check if posted" gnus-summary-article-posted-p t]
2466               ["Edit article" gnus-summary-edit-article
2467                (not (gnus-group-read-only-p))]
2468               ["Delete article" gnus-summary-delete-article
2469                (gnus-check-backend-function
2470                 'request-expire-articles gnus-newsgroup-name)]
2471               ["Query respool" gnus-summary-respool-query t]
2472               ["Trace respool" gnus-summary-respool-trace t]
2473               ["Delete expirable articles" gnus-summary-expire-articles-now
2474                (gnus-check-backend-function
2475                 'request-expire-articles gnus-newsgroup-name)])
2476              ("Extract"
2477               ["Uudecode" gnus-uu-decode-uu
2478                ,@(if (featurep 'xemacs) '(t)
2479                    '(:help "Decode uuencoded article(s)"))]
2480               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2481               ["Unshar" gnus-uu-decode-unshar t]
2482               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2483               ["Save" gnus-uu-decode-save t]
2484               ["Binhex" gnus-uu-decode-binhex t]
2485               ["Postscript" gnus-uu-decode-postscript t]
2486               ["All MIME parts" gnus-summary-save-parts t])
2487              ("Cache"
2488               ["Enter article" gnus-cache-enter-article t]
2489               ["Remove article" gnus-cache-remove-article t])
2490              ["Translate" gnus-article-babel t]
2491              ["Select article buffer" gnus-summary-select-article-buffer t]
2492              ["Make article buffer sticky" gnus-sticky-article t]
2493              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2494              ["Isearch article..." gnus-summary-isearch-article t]
2495              ["Beginning of the article" gnus-summary-beginning-of-article t]
2496              ["End of the article" gnus-summary-end-of-article t]
2497              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2498              ["Fetch referenced articles" gnus-summary-refer-references t]
2499              ["Fetch current thread" gnus-summary-refer-thread t]
2500              ["Fetch article with id..." gnus-summary-refer-article t]
2501              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2502              ["Redisplay" gnus-summary-show-article t]
2503              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2504       (easy-menu-define
2505         gnus-summary-article-menu gnus-summary-mode-map ""
2506         (cons "Article" innards))
2507
2508       (if (not (keymapp gnus-summary-article-menu))
2509           (easy-menu-define
2510             gnus-article-commands-menu gnus-article-mode-map ""
2511             (cons "Commands" innards))
2512         ;; in Emacs, don't share menu.
2513         (setq gnus-article-commands-menu
2514               (copy-keymap gnus-summary-article-menu))
2515         (define-key gnus-article-mode-map [menu-bar commands]
2516           (cons "Commands" gnus-article-commands-menu))))
2517
2518     (easy-menu-define
2519       gnus-summary-thread-menu gnus-summary-mode-map ""
2520       '("Threads"
2521         ["Find all messages in thread" gnus-summary-refer-thread t]
2522         ["Toggle threading" gnus-summary-toggle-threads t]
2523         ["Hide threads" gnus-summary-hide-all-threads t]
2524         ["Show threads" gnus-summary-show-all-threads t]
2525         ["Hide thread" gnus-summary-hide-thread t]
2526         ["Show thread" gnus-summary-show-thread t]
2527         ["Go to next thread" gnus-summary-next-thread t]
2528         ["Go to previous thread" gnus-summary-prev-thread t]
2529         ["Go down thread" gnus-summary-down-thread t]
2530         ["Go up thread" gnus-summary-up-thread t]
2531         ["Top of thread" gnus-summary-top-thread t]
2532         ["Mark thread as read" gnus-summary-kill-thread t]
2533         ["Mark thread as expired" gnus-summary-expire-thread t]
2534         ["Lower thread score" gnus-summary-lower-thread t]
2535         ["Raise thread score" gnus-summary-raise-thread t]
2536         ["Rethread current" gnus-summary-rethread-current t]))
2537
2538     (easy-menu-define
2539       gnus-summary-post-menu gnus-summary-mode-map ""
2540       `("Post"
2541         ["Send a message (mail or news)" gnus-summary-post-news
2542          ,@(if (featurep 'xemacs) '(t)
2543              '(:help "Compose a new message (mail or news)"))]
2544         ["Followup" gnus-summary-followup
2545          ,@(if (featurep 'xemacs) '(t)
2546              '(:help "Post followup to this article"))]
2547         ["Followup and yank" gnus-summary-followup-with-original
2548          ,@(if (featurep 'xemacs) '(t)
2549              '(:help "Post followup to this article, quoting its contents"))]
2550         ["Supersede article" gnus-summary-supersede-article t]
2551         ["Cancel article" gnus-summary-cancel-article
2552          ,@(if (featurep 'xemacs) '(t)
2553              '(:help "Cancel an article you posted"))]
2554         ["Reply" gnus-summary-reply t]
2555         ["Reply and yank" gnus-summary-reply-with-original t]
2556         ["Wide reply" gnus-summary-wide-reply t]
2557         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2558          ,@(if (featurep 'xemacs) '(t)
2559              '(:help "Mail a reply, quoting this article"))]
2560         ["Very wide reply" gnus-summary-very-wide-reply t]
2561         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2562          ,@(if (featurep 'xemacs) '(t)
2563              '(:help "Mail a very wide reply, quoting this article"))]
2564         ["Mail forward" gnus-summary-mail-forward t]
2565         ["Post forward" gnus-summary-post-forward t]
2566         ["Digest and mail" gnus-uu-digest-mail-forward t]
2567         ["Digest and post" gnus-uu-digest-post-forward t]
2568         ["Resend message" gnus-summary-resend-message t]
2569         ["Resend message edit" gnus-summary-resend-message-edit t]
2570         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2571         ["Send a mail" gnus-summary-mail-other-window t]
2572         ["Create a local message" gnus-summary-news-other-window t]
2573         ["Uuencode and post" gnus-uu-post-news
2574          ,@(if (featurep 'xemacs) '(t)
2575              '(:help "Post a uuencoded article"))]
2576         ["Followup via news" gnus-summary-followup-to-mail t]
2577         ["Followup via news and yank"
2578          gnus-summary-followup-to-mail-with-original t]
2579         ["Strip signature on reply"
2580          (lambda ()
2581            (interactive)
2582            (if (not (memq message-cite-function
2583                           '(message-cite-original-without-signature
2584                             message-cite-original)))
2585                ;; Stupid workaround for XEmacs not honoring :visible.
2586                (message "Can't toggle this value of `message-cite-function'")
2587              (setq message-cite-function
2588                    (if (eq message-cite-function
2589                            'message-cite-original-without-signature)
2590                        'message-cite-original
2591                      'message-cite-original-without-signature))))
2592          ;; XEmacs barfs on :visible.
2593          ,@(if (featurep 'xemacs) nil
2594              '(:visible (memq message-cite-function
2595                               '(message-cite-original-without-signature
2596                                 message-cite-original))))
2597          :style toggle
2598          :selected (eq message-cite-function
2599                        'message-cite-original-without-signature)
2600          ,@(if (featurep 'xemacs) nil
2601              '(:help "Strip signature from cited article when replying."))]
2602         ;;("Draft"
2603         ;;["Send" gnus-summary-send-draft t]
2604         ;;["Send bounced" gnus-resend-bounced-mail t])
2605         ))
2606
2607     (cond
2608      ((not (keymapp gnus-summary-post-menu))
2609       (setq gnus-article-post-menu gnus-summary-post-menu))
2610      ((not gnus-article-post-menu)
2611       ;; Don't share post menu.
2612       (setq gnus-article-post-menu
2613             (copy-keymap gnus-summary-post-menu))))
2614     (define-key gnus-article-mode-map [menu-bar post]
2615       (cons "Post" gnus-article-post-menu))
2616
2617     (easy-menu-define
2618       gnus-summary-misc-menu gnus-summary-mode-map ""
2619       `("Gnus"
2620         ("Mark Read"
2621          ["Mark as read" gnus-summary-mark-as-read-forward t]
2622          ["Mark same subject and select"
2623           gnus-summary-kill-same-subject-and-select t]
2624          ["Mark same subject" gnus-summary-kill-same-subject t]
2625          ["Catchup" gnus-summary-catchup
2626           ,@(if (featurep 'xemacs) '(t)
2627               '(:help "Mark unread articles in this group as read"))]
2628          ["Catchup all" gnus-summary-catchup-all t]
2629          ["Catchup to here" gnus-summary-catchup-to-here t]
2630          ["Catchup from here" gnus-summary-catchup-from-here t]
2631          ["Catchup region" gnus-summary-mark-region-as-read
2632           (gnus-mark-active-p)]
2633          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2634         ("Mark Various"
2635          ["Tick" gnus-summary-tick-article-forward t]
2636          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2637          ["Remove marks" gnus-summary-clear-mark-forward t]
2638          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2639          ["Set bookmark" gnus-summary-set-bookmark t]
2640          ["Remove bookmark" gnus-summary-remove-bookmark t])
2641         ("Limit to"
2642          ["Marks..." gnus-summary-limit-to-marks t]
2643          ["Subject..." gnus-summary-limit-to-subject t]
2644          ["Author..." gnus-summary-limit-to-author t]
2645          ["Recipient..." gnus-summary-limit-to-recipient t]
2646          ["Address..." gnus-summary-limit-to-address t]
2647          ["Age..." gnus-summary-limit-to-age t]
2648          ["Extra..." gnus-summary-limit-to-extra t]
2649          ["Score..." gnus-summary-limit-to-score t]
2650          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2651          ["Unread" gnus-summary-limit-to-unread t]
2652          ["Unseen" gnus-summary-limit-to-unseen t]
2653          ["Singletons" gnus-summary-limit-to-singletons t]
2654          ["Replied" gnus-summary-limit-to-replied t]
2655          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2656          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2657          ["Pop limit" gnus-summary-pop-limit t]
2658          ["Show dormant" gnus-summary-limit-include-dormant t]
2659          ["Hide childless dormant"
2660           gnus-summary-limit-exclude-childless-dormant t]
2661          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2662          ["Hide marked" gnus-summary-limit-exclude-marks t]
2663          ["Show expunged" gnus-summary-limit-include-expunged t])
2664         ("Process Mark"
2665          ["Set mark" gnus-summary-mark-as-processable t]
2666          ["Remove mark" gnus-summary-unmark-as-processable t]
2667          ["Remove all marks" gnus-summary-unmark-all-processable t]
2668          ["Invert marks" gnus-uu-invert-processable t]
2669          ["Mark above" gnus-uu-mark-over t]
2670          ["Mark series" gnus-uu-mark-series t]
2671          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2672          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2673          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2674          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2675          ["Mark all" gnus-uu-mark-all t]
2676          ["Mark buffer" gnus-uu-mark-buffer t]
2677          ["Mark sparse" gnus-uu-mark-sparse t]
2678          ["Mark thread" gnus-uu-mark-thread t]
2679          ["Unmark thread" gnus-uu-unmark-thread t]
2680          ("Process Mark Sets"
2681           ["Kill" gnus-summary-kill-process-mark t]
2682           ["Yank" gnus-summary-yank-process-mark
2683            gnus-newsgroup-process-stack]
2684           ["Save" gnus-summary-save-process-mark t]
2685           ["Run command on marked..." gnus-summary-universal-argument t]))
2686         ("Registry Marks")
2687         ("Scroll article"
2688          ["Page forward" gnus-summary-next-page
2689           ,@(if (featurep 'xemacs) '(t)
2690               '(:help "Show next page of article"))]
2691          ["Page backward" gnus-summary-prev-page
2692           ,@(if (featurep 'xemacs) '(t)
2693               '(:help "Show previous page of article"))]
2694          ["Line forward" gnus-summary-scroll-up t])
2695         ("Move"
2696          ["Next unread article" gnus-summary-next-unread-article t]
2697          ["Previous unread article" gnus-summary-prev-unread-article t]
2698          ["Next article" gnus-summary-next-article t]
2699          ["Previous article" gnus-summary-prev-article t]
2700          ["Next unread subject" gnus-summary-next-unread-subject t]
2701          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2702          ["Next article same subject" gnus-summary-next-same-subject t]
2703          ["Previous article same subject" gnus-summary-prev-same-subject t]
2704          ["First unread article" gnus-summary-first-unread-article t]
2705          ["Best unread article" gnus-summary-best-unread-article t]
2706          ["Go to subject number..." gnus-summary-goto-subject t]
2707          ["Go to article number..." gnus-summary-goto-article t]
2708          ["Go to the last article" gnus-summary-goto-last-article t]
2709          ["Pop article off history" gnus-summary-pop-article t])
2710         ("Sort"
2711          ["Sort by number" gnus-summary-sort-by-number t]
2712          ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
2713          ["Sort by author" gnus-summary-sort-by-author t]
2714          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2715          ["Sort by subject" gnus-summary-sort-by-subject t]
2716          ["Sort by date" gnus-summary-sort-by-date t]
2717          ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
2718          ["Sort by score" gnus-summary-sort-by-score t]
2719          ["Sort by lines" gnus-summary-sort-by-lines t]
2720          ["Sort by characters" gnus-summary-sort-by-chars t]
2721          ["Randomize" gnus-summary-sort-by-random t]
2722          ["Original sort" gnus-summary-sort-by-original t])
2723         ("Help"
2724          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2725          ["Describe group" gnus-summary-describe-group t]
2726          ["Fetch charter" gnus-group-fetch-charter
2727           ,@(if (featurep 'xemacs) nil
2728               '(:help "Display the charter of the current group"))]
2729          ["Fetch control message" gnus-group-fetch-control
2730           ,@(if (featurep 'xemacs) nil
2731               '(:help "Display the archived control message for the current group"))]
2732          ["Read manual" gnus-info-find-node t])
2733         ("Modes"
2734          ["Pick and read" gnus-pick-mode t]
2735          ["Binary" gnus-binary-mode t])
2736         ("Regeneration"
2737          ["Regenerate" gnus-summary-prepare t]
2738          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2739          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2740          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2741          ["Toggle threading" gnus-summary-toggle-threads t])
2742         ["See old articles" gnus-summary-insert-old-articles t]
2743         ["See new articles" gnus-summary-insert-new-articles t]
2744         ["Filter articles..." gnus-summary-execute-command t]
2745         ["Run command on articles..." gnus-summary-universal-argument t]
2746         ["Search articles forward..." gnus-summary-search-article-forward t]
2747         ["Search articles backward..." gnus-summary-search-article-backward t]
2748         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2749         ["Expand window" gnus-summary-expand-window t]
2750         ["Expire expirable articles" gnus-summary-expire-articles
2751          (gnus-check-backend-function
2752           'request-expire-articles gnus-newsgroup-name)]
2753         ["Edit local kill file" gnus-summary-edit-local-kill t]
2754         ["Edit main kill file" gnus-summary-edit-global-kill t]
2755         ["Edit group parameters" gnus-summary-edit-parameters t]
2756         ["Customize group parameters" gnus-summary-customize-parameters t]
2757         ["Send a bug report" gnus-bug t]
2758         ("Exit"
2759          ["Catchup and exit" gnus-summary-catchup-and-exit
2760           ,@(if (featurep 'xemacs) '(t)
2761               '(:help "Mark unread articles in this group as read, then exit"))]
2762          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2763          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2764          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2765          ["Exit group" gnus-summary-exit
2766           ,@(if (featurep 'xemacs) '(t)
2767               '(:help "Exit current group, return to group selection mode"))]
2768          ["Exit group without updating" gnus-summary-exit-no-update t]
2769          ["Exit and goto next group" gnus-summary-next-group t]
2770          ["Exit and goto prev group" gnus-summary-prev-group t]
2771          ["Reselect group" gnus-summary-reselect-current-group t]
2772          ["Rescan group" gnus-summary-rescan-group t]
2773          ["Update dribble" gnus-summary-save-newsrc t])))
2774
2775     (gnus-run-hooks 'gnus-summary-menu-hook)))
2776
2777 (defvar gnus-summary-tool-bar-map nil)
2778
2779 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2780 ;; affect _new_ message buffers.  We might add a function that walks thru all
2781 ;; summary-mode buffers and force the update.
2782 (defun gnus-summary-tool-bar-update (&optional symbol value)
2783   "Update summary mode toolbar.
2784 Setter function for custom variables."
2785   (setq-default gnus-summary-tool-bar-map nil)
2786   (when symbol
2787     ;; When used as ":set" function:
2788     (set-default symbol value))
2789   (when (gnus-buffer-live-p gnus-summary-buffer)
2790     (with-current-buffer gnus-summary-buffer
2791       (gnus-summary-make-tool-bar))))
2792
2793 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2794                                      'gnus-summary-tool-bar-gnome
2795                                    'gnus-summary-tool-bar-retro)
2796   "Specifies the Gnus summary tool bar.
2797
2798 It can be either a list or a symbol refering to a list.  See
2799 `gmm-tool-bar-from-list' for the format of the list.  The
2800 default key map is `gnus-summary-mode-map'.
2801
2802 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2803 `gnus-summary-tool-bar-retro'."
2804   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2805                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2806                  (repeat :tag "User defined list" gmm-tool-bar-item)
2807                  (symbol))
2808   :version "23.1" ;; No Gnus
2809   :initialize 'custom-initialize-default
2810   :set 'gnus-summary-tool-bar-update
2811   :group 'gnus-summary)
2812
2813 (defcustom gnus-summary-tool-bar-gnome
2814   '((gnus-summary-post-news "mail/compose" nil)
2815     (gnus-summary-insert-new-articles "mail/inbox" nil
2816                                       :visible (or (not gnus-agent)
2817                                                    gnus-plugged))
2818     (gnus-summary-reply-with-original "mail/reply")
2819     (gnus-summary-reply "mail/reply" nil :visible nil)
2820     (gnus-summary-followup-with-original "mail/reply-all")
2821     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2822     (gnus-summary-mail-forward "mail/forward")
2823     (gnus-summary-save-article "mail/save")
2824     (gnus-summary-search-article-forward "search" nil :visible nil)
2825     (gnus-summary-print-article "print")
2826     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2827     ;; Some new commands that may need more suitable icons:
2828     (gnus-summary-save-newsrc "save" nil :visible nil)
2829     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2830     (gnus-summary-prev-article "left-arrow")
2831     (gnus-summary-next-article "right-arrow")
2832     (gnus-summary-next-page "next-page")
2833     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2834     ;;
2835     ;; Maybe some sort-by-... could be added:
2836     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2837     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2838     (gnus-summary-mark-as-expirable
2839      "delete" nil
2840      :visible (gnus-check-backend-function 'request-expire-articles
2841                                            gnus-newsgroup-name))
2842     (gnus-summary-mark-as-spam
2843      "mail/spam" t
2844      :visible (and (fboundp 'spam-group-ham-contents-p)
2845                    (spam-group-ham-contents-p gnus-newsgroup-name))
2846      :help "Mark as spam")
2847     (gnus-summary-mark-as-read-forward
2848      "mail/not-spam" nil
2849      :visible (and (fboundp 'spam-group-spam-contents-p)
2850                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2851     ;;
2852     (gnus-summary-exit "exit")
2853     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2854     (gnus-info-find-node "help"))
2855   "List of functions for the summary tool bar (GNOME style).
2856
2857 See `gmm-tool-bar-from-list' for the format of the list."
2858   :type '(repeat gmm-tool-bar-item)
2859   :version "23.1" ;; No Gnus
2860   :initialize 'custom-initialize-default
2861   :set 'gnus-summary-tool-bar-update
2862   :group 'gnus-summary)
2863
2864 (defcustom gnus-summary-tool-bar-retro
2865   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2866     (gnus-summary-next-unread-article "gnus/next-ur")
2867     (gnus-summary-post-news "gnus/post")
2868     (gnus-summary-followup-with-original "gnus/fuwo")
2869     (gnus-summary-followup "gnus/followup")
2870     (gnus-summary-reply-with-original "gnus/reply-wo")
2871     (gnus-summary-reply "gnus/reply")
2872     (gnus-summary-caesar-message "gnus/rot13")
2873     (gnus-uu-decode-uu "gnus/uu-decode")
2874     (gnus-summary-save-article-file "gnus/save-aif")
2875     (gnus-summary-save-article "gnus/save-art")
2876     (gnus-uu-post-news "gnus/uu-post")
2877     (gnus-summary-catchup "gnus/catchup")
2878     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2879     (gnus-summary-exit "gnus/exit-summ")
2880     ;; Some new command that may need more suitable icons:
2881     (gnus-summary-print-article "gnus/print" nil :visible nil)
2882     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2883     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2884     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2885     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2886     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2887     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2888     ;;
2889     (gnus-info-find-node "gnus/help" nil :visible nil))
2890   "List of functions for the summary tool bar (retro look).
2891
2892 See `gmm-tool-bar-from-list' for the format of the list."
2893   :type '(repeat gmm-tool-bar-item)
2894   :version "23.1" ;; No Gnus
2895   :initialize 'custom-initialize-default
2896   :set 'gnus-summary-tool-bar-update
2897   :group 'gnus-summary)
2898
2899 (defcustom gnus-summary-tool-bar-zap-list t
2900   "List of icon items from the global tool bar.
2901 These items are not displayed in the Gnus summary mode tool bar.
2902
2903 See `gmm-tool-bar-from-list' for the format of the list."
2904   :type 'gmm-tool-bar-zap-list
2905   :version "23.1" ;; No Gnus
2906   :initialize 'custom-initialize-default
2907   :set 'gnus-summary-tool-bar-update
2908   :group 'gnus-summary)
2909
2910 (defvar image-load-path)
2911 (defvar tool-bar-map)
2912
2913 (defun gnus-summary-make-tool-bar (&optional force)
2914   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2915 When FORCE, rebuild the tool bar."
2916   (when (and (not (featurep 'xemacs))
2917              (boundp 'tool-bar-mode)
2918              tool-bar-mode
2919              (or (not gnus-summary-tool-bar-map) force))
2920     (let* ((load-path
2921             (gmm-image-load-path-for-library "gnus"
2922                                              "mail/save.xpm"
2923                                              nil t))
2924            (image-load-path (cons (car load-path)
2925                                   (when (boundp 'image-load-path)
2926                                     image-load-path)))
2927            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2928                                         gnus-summary-tool-bar-zap-list
2929                                         'gnus-summary-mode-map)))
2930       (when map
2931         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2932         ;; uses it's value.
2933         (setq gnus-summary-tool-bar-map map))))
2934   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2935
2936 (defun gnus-score-set-default (var value)
2937   "A version of set that updates the GNU Emacs menu-bar."
2938   (set var value)
2939   ;; It is the message that forces the active status to be updated.
2940   (message ""))
2941
2942 (defun gnus-make-score-map (type)
2943   "Make a summary score map of type TYPE."
2944   (if t
2945       nil
2946     (let ((headers '(("author" "from" string)
2947                      ("subject" "subject" string)
2948                      ("article body" "body" string)
2949                      ("article head" "head" string)
2950                      ("xref" "xref" string)
2951                      ("extra header" "extra" string)
2952                      ("lines" "lines" number)
2953                      ("followups to author" "followup" string)))
2954           (types '((number ("less than" <)
2955                            ("greater than" >)
2956                            ("equal" =))
2957                    (string ("substring" s)
2958                            ("exact string" e)
2959                            ("fuzzy string" f)
2960                            ("regexp" r))))
2961           (perms '(("temporary" (current-time-string))
2962                    ("permanent" nil)
2963                    ("immediate" now)))
2964           header)
2965       (list
2966        (apply
2967         'nconc
2968         (list
2969          (if (eq type 'lower)
2970              "Lower score"
2971            "Increase score"))
2972         (let (outh)
2973           (while headers
2974             (setq header (car headers))
2975             (setq outh
2976                   (cons
2977                    (apply
2978                     'nconc
2979                     (list (car header))
2980                     (let ((ts (cdr (assoc (nth 2 header) types)))
2981                           outt)
2982                       (while ts
2983                         (setq outt
2984                               (cons
2985                                (apply
2986                                 'nconc
2987                                 (list (caar ts))
2988                                 (let ((ps perms)
2989                                       outp)
2990                                   (while ps
2991                                     (setq outp
2992                                           (cons
2993                                            (vector
2994                                             (caar ps)
2995                                             (list
2996                                              'gnus-summary-score-entry
2997                                              (nth 1 header)
2998                                              (if (or (string= (nth 1 header)
2999                                                               "head")
3000                                                      (string= (nth 1 header)
3001                                                               "body"))
3002                                                  ""
3003                                                (list 'gnus-summary-header
3004                                                      (nth 1 header)))
3005                                              (list 'quote (nth 1 (car ts)))
3006                                              (list 'gnus-score-delta-default
3007                                                    nil)
3008                                              (nth 1 (car ps))
3009                                              t)
3010                                             t)
3011                                            outp))
3012                                     (setq ps (cdr ps)))
3013                                   (list (nreverse outp))))
3014                                outt))
3015                         (setq ts (cdr ts)))
3016                       (list (nreverse outt))))
3017                    outh))
3018             (setq headers (cdr headers)))
3019           (list (nreverse outh))))))))
3020
3021
3022 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3023 (defvar bookmark-make-record-function)
3024 \f
3025
3026 (defun gnus-summary-mode (&optional group)
3027   "Major mode for reading articles.
3028
3029 All normal editing commands are switched off.
3030 \\<gnus-summary-mode-map>
3031 Each line in this buffer represents one article.  To read an
3032 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3033 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3034 respectively.
3035
3036 You can also post articles and send mail from this buffer.  To
3037 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3038 of an article, type `\\[gnus-summary-reply]'.
3039
3040 There are approx. one gazillion commands you can execute in this
3041 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3042
3043 The following commands are available:
3044
3045 \\{gnus-summary-mode-map}"
3046   (interactive)
3047   (kill-all-local-variables)
3048   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3049     (gnus-summary-make-local-variables))
3050   (gnus-summary-make-local-variables)
3051   (setq gnus-newsgroup-name group)
3052   (when (gnus-visual-p 'summary-menu 'menu)
3053     (gnus-summary-make-menu-bar)
3054     (gnus-summary-make-tool-bar))
3055   (gnus-make-thread-indent-array)
3056   (gnus-simplify-mode-line)
3057   (setq major-mode 'gnus-summary-mode)
3058   (setq mode-name "Summary")
3059   (make-local-variable 'minor-mode-alist)
3060   (use-local-map gnus-summary-mode-map)
3061   (buffer-disable-undo)
3062   (setq buffer-read-only t              ;Disable modification
3063         show-trailing-whitespace nil)
3064   (setq truncate-lines t)
3065   (add-to-invisibility-spec '(gnus-sum . t))
3066   (gnus-summary-set-display-table)
3067   (gnus-set-default-directory)
3068   (make-local-variable 'gnus-summary-line-format)
3069   (make-local-variable 'gnus-summary-line-format-spec)
3070   (make-local-variable 'gnus-summary-dummy-line-format)
3071   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3072   (make-local-variable 'gnus-summary-mark-positions)
3073   (gnus-make-local-hook 'pre-command-hook)
3074   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3075   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3076   (turn-on-gnus-mailing-list-mode)
3077   (mm-enable-multibyte)
3078   (set (make-local-variable 'bookmark-make-record-function)
3079        'gnus-summary-bookmark-make-record)
3080   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3081   (gnus-update-summary-mark-positions))
3082
3083 (defun gnus-summary-make-local-variables ()
3084   "Make all the local summary buffer variables."
3085   (let (global)
3086     (dolist (local gnus-summary-local-variables)
3087       (if (consp local)
3088           (progn
3089             (if (eq (cdr local) 'global)
3090                 ;; Copy the global value of the variable.
3091                 (setq global (symbol-value (car local)))
3092               ;; Use the value from the list.
3093               (setq global (eval (cdr local))))
3094             (set (make-local-variable (car local)) global))
3095         ;; Simple nil-valued local variable.
3096         (set (make-local-variable local) nil)))))
3097
3098 (defun gnus-summary-clear-local-variables ()
3099   (let ((locals gnus-summary-local-variables))
3100     (while locals
3101       (if (consp (car locals))
3102           (and (symbolp (caar locals))
3103                (set (caar locals) nil))
3104         (and (symbolp (car locals))
3105              (set (car locals) nil)))
3106       (setq locals (cdr locals)))))
3107
3108 ;; Summary data functions.
3109
3110 (defmacro gnus-data-number (data)
3111   `(car ,data))
3112
3113 (defmacro gnus-data-set-number (data number)
3114   `(setcar ,data ,number))
3115
3116 (defmacro gnus-data-mark (data)
3117   `(nth 1 ,data))
3118
3119 (defmacro gnus-data-set-mark (data mark)
3120   `(setcar (nthcdr 1 ,data) ,mark))
3121
3122 (defmacro gnus-data-pos (data)
3123   `(nth 2 ,data))
3124
3125 (defmacro gnus-data-set-pos (data pos)
3126   `(setcar (nthcdr 2 ,data) ,pos))
3127
3128 (defmacro gnus-data-header (data)
3129   `(nth 3 ,data))
3130
3131 (defmacro gnus-data-set-header (data header)
3132   `(setf (nth 3 ,data) ,header))
3133
3134 (defmacro gnus-data-level (data)
3135   `(nth 4 ,data))
3136
3137 (defmacro gnus-data-unread-p (data)
3138   `(= (nth 1 ,data) gnus-unread-mark))
3139
3140 (defmacro gnus-data-read-p (data)
3141   `(/= (nth 1 ,data) gnus-unread-mark))
3142
3143 (defmacro gnus-data-pseudo-p (data)
3144   `(consp (nth 3 ,data)))
3145
3146 (defmacro gnus-data-find (number)
3147   `(assq ,number gnus-newsgroup-data))
3148
3149 (defmacro gnus-data-find-list (number &optional data)
3150   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3151      (memq (assq ,number bdata)
3152            bdata)))
3153
3154 (defmacro gnus-data-make (number mark pos header level)
3155   `(list ,number ,mark ,pos ,header ,level))
3156
3157 (defun gnus-data-enter (after-article number mark pos header level offset)
3158   (let ((data (gnus-data-find-list after-article)))
3159     (unless data
3160       (error "No such article: %d" after-article))
3161     (setcdr data (cons (gnus-data-make number mark pos header level)
3162                        (cdr data)))
3163     (setq gnus-newsgroup-data-reverse nil)
3164     (gnus-data-update-list (cddr data) offset)))
3165
3166 (defun gnus-data-enter-list (after-article list &optional offset)
3167   (when list
3168     (let ((data (and after-article (gnus-data-find-list after-article)))
3169           (ilist list))
3170       (if (not (or data
3171                    after-article))
3172           (let ((odata gnus-newsgroup-data))
3173             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3174             (when offset
3175               (gnus-data-update-list odata offset)))
3176         ;; Find the last element in the list to be spliced into the main
3177         ;; list.
3178         (setq list (last list))
3179         (if (not data)
3180             (progn
3181               (setcdr list gnus-newsgroup-data)
3182               (setq gnus-newsgroup-data ilist)
3183               (when offset
3184                 (gnus-data-update-list (cdr list) offset)))
3185           (setcdr list (cdr data))
3186           (setcdr data ilist)
3187           (when offset
3188             (gnus-data-update-list (cdr list) offset))))
3189       (setq gnus-newsgroup-data-reverse nil))))
3190
3191 (defun gnus-data-remove (article &optional offset)
3192   (let ((data gnus-newsgroup-data))
3193     (if (= (gnus-data-number (car data)) article)
3194         (progn
3195           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3196                 gnus-newsgroup-data-reverse nil)
3197           (when offset
3198             (gnus-data-update-list gnus-newsgroup-data offset)))
3199       (while (cdr data)
3200         (when (= (gnus-data-number (cadr data)) article)
3201           (setcdr data (cddr data))
3202           (when offset
3203             (gnus-data-update-list (cdr data) offset))
3204           (setq data nil
3205                 gnus-newsgroup-data-reverse nil))
3206         (setq data (cdr data))))))
3207
3208 (defmacro gnus-data-list (backward)
3209   `(if ,backward
3210        (or gnus-newsgroup-data-reverse
3211            (setq gnus-newsgroup-data-reverse
3212                  (reverse gnus-newsgroup-data)))
3213      gnus-newsgroup-data))
3214
3215 (defun gnus-data-update-list (data offset)
3216   "Add OFFSET to the POS of all data entries in DATA."
3217   (setq gnus-newsgroup-data-reverse nil)
3218   (while data
3219     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3220     (setq data (cdr data))))
3221
3222 (defun gnus-summary-article-pseudo-p (article)
3223   "Say whether this article is a pseudo article or not."
3224   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3225
3226 (defmacro gnus-summary-article-sparse-p (article)
3227   "Say whether this article is a sparse article or not."
3228   `(memq ,article gnus-newsgroup-sparse))
3229
3230 (defmacro gnus-summary-article-ancient-p (article)
3231   "Say whether this article is a sparse article or not."
3232   `(memq ,article gnus-newsgroup-ancient))
3233
3234 (defun gnus-article-parent-p (number)
3235   "Say whether this article is a parent or not."
3236   (let ((data (gnus-data-find-list number)))
3237     (and (cdr data)              ; There has to be an article after...
3238          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3239             (gnus-data-level (nth 1 data))))))
3240
3241 (defun gnus-article-children (number)
3242   "Return a list of all children to NUMBER."
3243   (let* ((data (gnus-data-find-list number))
3244          (level (gnus-data-level (car data)))
3245          children)
3246     (setq data (cdr data))
3247     (while (and data
3248                 (= (gnus-data-level (car data)) (1+ level)))
3249       (push (gnus-data-number (car data)) children)
3250       (setq data (cdr data)))
3251     children))
3252
3253 (defmacro gnus-summary-skip-intangible ()
3254   "If the current article is intangible, then jump to a different article."
3255   '(let ((to (get-text-property (point) 'gnus-intangible)))
3256      (and to (gnus-summary-goto-subject to))))
3257
3258 (defmacro gnus-summary-article-intangible-p ()
3259   "Say whether this article is intangible or not."
3260   '(get-text-property (point) 'gnus-intangible))
3261
3262 (defun gnus-article-read-p (article)
3263   "Say whether ARTICLE is read or not."
3264   (not (or (memq article gnus-newsgroup-marked)
3265            (memq article gnus-newsgroup-spam-marked)
3266            (memq article gnus-newsgroup-unreads)
3267            (memq article gnus-newsgroup-unselected)
3268            (memq article gnus-newsgroup-dormant))))
3269
3270 ;; Some summary mode macros.
3271
3272 (defmacro gnus-summary-article-number ()
3273   "The article number of the article on the current line.
3274 If there isn't an article number here, then we return the current
3275 article number."
3276   '(progn
3277      (gnus-summary-skip-intangible)
3278      (or (get-text-property (point) 'gnus-number)
3279          (gnus-summary-last-subject))))
3280
3281 (defmacro gnus-summary-article-header (&optional number)
3282   "Return the header of article NUMBER."
3283   `(gnus-data-header (gnus-data-find
3284                       ,(or number '(gnus-summary-article-number)))))
3285
3286 (defmacro gnus-summary-thread-level (&optional number)
3287   "Return the level of thread that starts with article NUMBER."
3288   `(if (and (eq gnus-summary-make-false-root 'dummy)
3289             (get-text-property (point) 'gnus-intangible))
3290        0
3291      (gnus-data-level (gnus-data-find
3292                        ,(or number '(gnus-summary-article-number))))))
3293
3294 (defmacro gnus-summary-article-mark (&optional number)
3295   "Return the mark of article NUMBER."
3296   `(gnus-data-mark (gnus-data-find
3297                     ,(or number '(gnus-summary-article-number)))))
3298
3299 (defmacro gnus-summary-article-pos (&optional number)
3300   "Return the position of the line of article NUMBER."
3301   `(gnus-data-pos (gnus-data-find
3302                    ,(or number '(gnus-summary-article-number)))))
3303
3304 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3305 (defmacro gnus-summary-article-subject (&optional number)
3306   "Return current subject string or nil if nothing."
3307   `(let ((headers
3308           ,(if number
3309                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3310              '(gnus-data-header (assq (gnus-summary-article-number)
3311                                       gnus-newsgroup-data)))))
3312      (and headers
3313           (vectorp headers)
3314           (mail-header-subject headers))))
3315
3316 (defmacro gnus-summary-article-score (&optional number)
3317   "Return current article score."
3318   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3319                   gnus-newsgroup-scored))
3320        gnus-summary-default-score 0))
3321
3322 (defun gnus-summary-article-children (&optional number)
3323   "Return a list of article numbers that are children of article NUMBER."
3324   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3325          (level (gnus-data-level (car data)))
3326          l children)
3327     (while (and (setq data (cdr data))
3328                 (> (setq l (gnus-data-level (car data))) level))
3329       (and (= (1+ level) l)
3330            (push (gnus-data-number (car data))
3331                  children)))
3332     (nreverse children)))
3333
3334 (defun gnus-summary-article-parent (&optional number)
3335   "Return the article number of the parent of article NUMBER."
3336   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3337                                     (gnus-data-list t)))
3338          (level (gnus-data-level (car data))))
3339     (if (zerop level)
3340         ()                              ; This is a root.
3341       ;; We search until we find an article with a level less than
3342       ;; this one.  That function has to be the parent.
3343       (while (and (setq data (cdr data))
3344                   (not (< (gnus-data-level (car data)) level))))
3345       (and data (gnus-data-number (car data))))))
3346
3347 (defun gnus-unread-mark-p (mark)
3348   "Say whether MARK is the unread mark."
3349   (= mark gnus-unread-mark))
3350
3351 (defun gnus-read-mark-p (mark)
3352   "Say whether MARK is one of the marks that mark as read.
3353 This is all marks except unread, ticked, dormant, and expirable."
3354   (not (or (= mark gnus-unread-mark)
3355            (= mark gnus-ticked-mark)
3356            (= mark gnus-spam-mark)
3357            (= mark gnus-dormant-mark)
3358            (= mark gnus-expirable-mark))))
3359
3360 (defmacro gnus-article-mark (number)
3361   "Return the MARK of article NUMBER.
3362 This macro should only be used when computing the mark the \"first\"
3363 time; i.e., when generating the summary lines.  After that,
3364 `gnus-summary-article-mark' should be used to examine the
3365 marks of articles."
3366   `(cond
3367     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3368     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3369     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3370     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3371     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3372     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3373     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3374     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3375            gnus-ancient-mark))))
3376
3377 ;; Saving hidden threads.
3378
3379 (defmacro gnus-save-hidden-threads (&rest forms)
3380   "Save hidden threads, eval FORMS, and restore the hidden threads."
3381   (let ((config (make-symbol "config")))
3382     `(let ((,config (gnus-hidden-threads-configuration)))
3383        (unwind-protect
3384            (save-excursion
3385              ,@forms)
3386          (gnus-restore-hidden-threads-configuration ,config)))))
3387 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3388 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3389
3390 (defun gnus-data-compute-positions ()
3391   "Compute the positions of all articles."
3392   (setq gnus-newsgroup-data-reverse nil)
3393   (let ((data gnus-newsgroup-data))
3394     (save-excursion
3395       (gnus-save-hidden-threads
3396         (gnus-summary-show-all-threads)
3397         (goto-char (point-min))
3398         (while data
3399           (while (get-text-property (point) 'gnus-intangible)
3400             (forward-line 1))
3401           (gnus-data-set-pos (car data) (+ (point) 3))
3402           (setq data (cdr data))
3403           (forward-line 1))))))
3404
3405 (defun gnus-hidden-threads-configuration ()
3406   "Return the current hidden threads configuration."
3407   (save-excursion
3408     (let (config)
3409       (goto-char (point-min))
3410       (while (search-forward "\r" nil t)
3411         (push (1- (point)) config))
3412       config)))
3413
3414 (defun gnus-restore-hidden-threads-configuration (config)
3415   "Restore hidden threads configuration from CONFIG."
3416   (save-excursion
3417     (let (point (inhibit-read-only t))
3418       (while (setq point (pop config))
3419         (when (and (< point (point-max))
3420                    (goto-char point)
3421                    (eq (char-after) ?\n))
3422           (subst-char-in-region point (1+ point) ?\n ?\r))))))
3423
3424 ;; Various summary mode internalish functions.
3425
3426 (defun gnus-mouse-pick-article (e)
3427   (interactive "e")
3428   (mouse-set-point e)
3429   (gnus-summary-next-page nil t))
3430
3431 (defun gnus-summary-set-display-table ()
3432   "Change the display table.
3433 Odd characters have a tendency to mess
3434 up nicely formatted displays - we make all possible glyphs
3435 display only a single character."
3436
3437   ;; We start from the standard display table, if any.
3438   (let ((table (or (copy-sequence standard-display-table)
3439                    (make-display-table)))
3440         (i 32))
3441     ;; Nix out all the control chars...
3442     (while (>= (setq i (1- i)) 0)
3443       (gnus-put-display-table i [??] table))
3444    ;; ... but not newline and cr, of course.  (cr is necessary for the
3445     ;; selective display).
3446     (gnus-put-display-table ?\n nil table)
3447     (gnus-put-display-table ?\r nil table)
3448     ;; We keep TAB as well.
3449     (gnus-put-display-table ?\t nil table)
3450     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3451     ;; Emacs 23 (unicode), that are not set already.
3452     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3453                  160
3454                256)))
3455       (while (>= (setq i (1- i)) 127)
3456         ;; Only modify if the entry is nil.
3457         (unless (gnus-get-display-table i table)
3458           (gnus-put-display-table i [??] table))))
3459     (setq buffer-display-table table)))
3460
3461 (defun gnus-summary-set-article-display-arrow (pos)
3462   "Update the overlay arrow to point to line at position POS."
3463   (when gnus-summary-display-arrow
3464     (make-local-variable 'overlay-arrow-position)
3465     (make-local-variable 'overlay-arrow-string)
3466     (save-excursion
3467       (goto-char pos)
3468       (beginning-of-line)
3469       (unless overlay-arrow-position
3470         (setq overlay-arrow-position (make-marker)))
3471       (setq overlay-arrow-string "=>"
3472             overlay-arrow-position (set-marker overlay-arrow-position
3473                                                (point)
3474                                                (current-buffer))))))
3475
3476 (defun gnus-summary-setup-buffer (group)
3477   "Initialize summary buffer."
3478   (let ((buffer (gnus-summary-buffer-name group))
3479         (dead-name (concat "*Dead Summary "
3480                            (gnus-group-decoded-name group) "*")))
3481     ;; If a dead summary buffer exists, we kill it.
3482     (when (gnus-buffer-live-p dead-name)
3483       (gnus-kill-buffer dead-name))
3484     (if (get-buffer buffer)
3485         (progn
3486           (set-buffer buffer)
3487           (setq gnus-summary-buffer (current-buffer))
3488           (not gnus-newsgroup-prepared))
3489       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3490       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3491       (gnus-summary-mode group)
3492       (when gnus-carpal
3493         (gnus-carpal-setup-buffer 'summary))
3494       (when (gnus-group-quit-config group)
3495         (set (make-local-variable 'gnus-single-article-buffer) nil))
3496       (make-local-variable 'gnus-article-buffer)
3497       (make-local-variable 'gnus-article-current)
3498       (make-local-variable 'gnus-original-article-buffer)
3499       (setq gnus-newsgroup-name group)
3500       ;; Set any local variables in the group parameters.
3501       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3502       t)))
3503
3504 (defun gnus-set-global-variables ()
3505   "Set the global equivalents of the buffer-local variables.
3506 They are set to the latest values they had.  These reflect the summary
3507 buffer that was in action when the last article was fetched."
3508   (when (eq major-mode 'gnus-summary-mode)
3509     (setq gnus-summary-buffer (current-buffer))
3510     (let ((name gnus-newsgroup-name)
3511           (marked gnus-newsgroup-marked)
3512           (spam gnus-newsgroup-spam-marked)
3513           (unread gnus-newsgroup-unreads)
3514           (headers gnus-current-headers)
3515           (data gnus-newsgroup-data)
3516           (summary gnus-summary-buffer)
3517           (article-buffer gnus-article-buffer)
3518           (original gnus-original-article-buffer)
3519           (gac gnus-article-current)
3520           (reffed gnus-reffed-article-number)
3521           (score-file gnus-current-score-file)
3522           (default-charset gnus-newsgroup-charset)
3523           vlist)
3524       (let ((locals gnus-newsgroup-variables))
3525         (while locals
3526           (if (consp (car locals))
3527               (push (eval (caar locals)) vlist)
3528             (push (eval (car locals)) vlist))
3529           (setq locals (cdr locals)))
3530         (setq vlist (nreverse vlist)))
3531       (with-current-buffer gnus-group-buffer
3532         (setq gnus-newsgroup-name name
3533               gnus-newsgroup-marked marked
3534               gnus-newsgroup-spam-marked spam
3535               gnus-newsgroup-unreads unread
3536               gnus-current-headers headers
3537               gnus-newsgroup-data data
3538               gnus-article-current gac
3539               gnus-summary-buffer summary
3540               gnus-article-buffer article-buffer
3541               gnus-original-article-buffer original
3542               gnus-reffed-article-number reffed
3543               gnus-current-score-file score-file
3544               gnus-newsgroup-charset default-charset)
3545         (let ((locals gnus-newsgroup-variables))
3546           (while locals
3547             (if (consp (car locals))
3548                 (set (caar locals) (pop vlist))
3549               (set (car locals) (pop vlist)))
3550             (setq locals (cdr locals))))
3551         ;; The article buffer also has local variables.
3552         (when (gnus-buffer-live-p gnus-article-buffer)
3553           (set-buffer gnus-article-buffer)
3554           (setq gnus-summary-buffer summary))))))
3555
3556 (defun gnus-summary-article-unread-p (article)
3557   "Say whether ARTICLE is unread or not."
3558   (memq article gnus-newsgroup-unreads))
3559
3560 (defun gnus-summary-first-article-p (&optional article)
3561   "Return whether ARTICLE is the first article in the buffer."
3562   (if (not (setq article (or article (gnus-summary-article-number))))
3563       nil
3564     (eq article (caar gnus-newsgroup-data))))
3565
3566 (defun gnus-summary-last-article-p (&optional article)
3567   "Return whether ARTICLE is the last article in the buffer."
3568   (if (not (setq article (or article (gnus-summary-article-number))))
3569       ;; All non-existent numbers are the last article.  :-)
3570       t
3571     (not (cdr (gnus-data-find-list article)))))
3572
3573 (defun gnus-make-thread-indent-array (&optional n)
3574   (when (or n
3575             (progn (setq n 200) nil)
3576             (null gnus-thread-indent-array)
3577             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3578     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3579           gnus-thread-indent-array-level gnus-thread-indent-level)
3580     (while (>= n 0)
3581       (aset gnus-thread-indent-array n
3582             (make-string (* n gnus-thread-indent-level) ? ))
3583       (setq n (1- n)))))
3584
3585 (defun gnus-update-summary-mark-positions ()
3586   "Compute where the summary marks are to go."
3587   (save-excursion
3588     (when (gnus-buffer-exists-p gnus-summary-buffer)
3589       (set-buffer gnus-summary-buffer))
3590     (let ((spec gnus-summary-line-format-spec)
3591           pos)
3592       (save-excursion
3593         (gnus-set-work-buffer)
3594         (let ((gnus-tmp-unread ?Z)
3595               (gnus-replied-mark ?Z)
3596               (gnus-score-below-mark ?Z)
3597               (gnus-score-over-mark ?Z)
3598               (gnus-undownloaded-mark ?Z)
3599               (gnus-summary-line-format-spec spec)
3600               (gnus-newsgroup-downloadable '(0))
3601               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3602               case-fold-search ignores)
3603           ;; Here, all marks are bound to Z.
3604           (gnus-summary-insert-line header
3605                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3606           (goto-char (point-min))
3607           ;; Memorize the positions of the same characters as dummy marks.
3608           (while (re-search-forward "[A-D]" nil t)
3609             (push (point) ignores))
3610           (erase-buffer)
3611           ;; We use A-D as dummy marks in order to know column positions
3612           ;; where marks should be inserted.
3613           (setq gnus-tmp-unread ?A
3614                 gnus-replied-mark ?B
3615                 gnus-score-below-mark ?C
3616                 gnus-score-over-mark ?C
3617                 gnus-undownloaded-mark ?D)
3618           (gnus-summary-insert-line header
3619                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3620           ;; Ignore characters which aren't dummy marks.
3621           (dolist (p ignores)
3622             (delete-region (goto-char (1- p)) p)
3623             (insert ?Z))
3624           (goto-char (point-min))
3625           (setq pos (list (cons 'unread
3626                                 (and (search-forward "A" nil t)
3627                                      (- (point) (point-min) 1)))))
3628           (goto-char (point-min))
3629           (push (cons 'replied (and (search-forward "B" nil t)
3630                                     (- (point) (point-min) 1)))
3631                 pos)
3632           (goto-char (point-min))
3633           (push (cons 'score (and (search-forward "C" nil t)
3634                                   (- (point) (point-min) 1)))
3635                 pos)
3636           (goto-char (point-min))
3637           (push (cons 'download (and (search-forward "D" nil t)
3638                                      (- (point) (point-min) 1)))
3639                 pos)))
3640       (setq gnus-summary-mark-positions pos))))
3641
3642 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3643   "Insert a dummy root in the summary buffer."
3644   (beginning-of-line)
3645   (gnus-add-text-properties
3646    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3647    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3648
3649 (defun gnus-summary-extract-address-component (from)
3650   (or (car (funcall gnus-extract-address-components from))
3651       from))
3652
3653 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3654   (let ((mail-parse-charset gnus-newsgroup-charset)
3655         (ignored-from-addresses (gnus-ignored-from-addresses))
3656         ; Is it really necessary to do this next part for each summary line?
3657         ; Luckily, doesn't seem to slow things down much.
3658         (mail-parse-ignored-charsets
3659          (with-current-buffer gnus-summary-buffer
3660            gnus-newsgroup-ignored-charsets)))
3661     (or
3662      (and ignored-from-addresses
3663           (string-match ignored-from-addresses gnus-tmp-from)
3664           (let ((extra-headers (mail-header-extra header))
3665                 to
3666                 newsgroups)
3667             (cond
3668              ((setq to (cdr (assq 'To extra-headers)))
3669               (concat gnus-summary-to-prefix
3670                       (inline
3671                         (gnus-summary-extract-address-component
3672                          (funcall gnus-decode-encoded-address-function to)))))
3673              ((setq newsgroups
3674                     (or
3675                      (cdr (assq 'Newsgroups extra-headers))
3676                      (and
3677                       (memq 'Newsgroups gnus-extra-headers)
3678                       (eq (car (gnus-find-method-for-group
3679                                 gnus-newsgroup-name)) 'nntp)
3680                       (gnus-group-real-name gnus-newsgroup-name))))
3681               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3682      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3683
3684 (defun gnus-summary-insert-line (gnus-tmp-header
3685                                  gnus-tmp-level gnus-tmp-current
3686                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3687                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3688                                  &optional gnus-tmp-dummy gnus-tmp-score
3689                                  gnus-tmp-process)
3690   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3691       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3692                                           gnus-tmp-level)))
3693   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3694          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3695          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3696          (gnus-tmp-score-char
3697           (if (or (null gnus-summary-default-score)
3698                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3699                       gnus-summary-zcore-fuzz))
3700               ?                         ;Whitespace
3701             (if (< gnus-tmp-score gnus-summary-default-score)
3702                 gnus-score-below-mark gnus-score-over-mark)))
3703          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3704          (gnus-tmp-replied
3705           (cond (gnus-tmp-process gnus-process-mark)
3706                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3707                  gnus-cached-mark)
3708                 (gnus-tmp-replied gnus-replied-mark)
3709                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3710                  gnus-forwarded-mark)
3711                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3712                  gnus-saved-mark)
3713                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3714                  gnus-recent-mark)
3715                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3716                  gnus-unseen-mark)
3717                 (t gnus-no-mark)))
3718          (gnus-tmp-downloaded
3719           (cond (undownloaded
3720                  gnus-undownloaded-mark)
3721                 (gnus-newsgroup-agentized
3722                  gnus-downloaded-mark)
3723                 (t
3724                  gnus-no-mark)))
3725          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3726          (gnus-tmp-name
3727           (cond
3728            ((string-match "<[^>]+> *$" gnus-tmp-from)
3729             (let ((beg (match-beginning 0)))
3730               (or (and (string-match "^\".+\"" gnus-tmp-from)
3731                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3732                   (substring gnus-tmp-from 0 beg))))
3733            ((string-match "(.+)" gnus-tmp-from)
3734             (substring gnus-tmp-from
3735                        (1+ (match-beginning 0)) (1- (match-end 0))))
3736            (t gnus-tmp-from)))
3737          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3738          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3739          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3740          (inhibit-read-only t))
3741     (when (string= gnus-tmp-name "")
3742       (setq gnus-tmp-name gnus-tmp-from))
3743     (unless (numberp gnus-tmp-lines)
3744       (setq gnus-tmp-lines -1))
3745     (if (= gnus-tmp-lines -1)
3746         (setq gnus-tmp-lines "?")
3747       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3748     (condition-case ()
3749         (gnus-put-text-property
3750          (point)
3751          (progn (eval gnus-summary-line-format-spec) (point))
3752          'gnus-number gnus-tmp-number)
3753       (error (gnus-message 5 "Error updating the summary line")))
3754     (when (gnus-visual-p 'summary-highlight 'highlight)
3755       (forward-line -1)
3756       (gnus-run-hooks 'gnus-summary-update-hook)
3757       (forward-line 1))))
3758
3759 (defun gnus-summary-update-line (&optional dont-update)
3760   "Update summary line after change."
3761   (when (and gnus-summary-default-score
3762              (not gnus-summary-inhibit-highlight))
3763     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3764            (article (gnus-summary-article-number))
3765            (score (gnus-summary-article-score article)))
3766       (unless dont-update
3767         (if (and gnus-summary-mark-below
3768                  (< (gnus-summary-article-score)
3769                     gnus-summary-mark-below))
3770             ;; This article has a low score, so we mark it as read.
3771             (when (memq article gnus-newsgroup-unreads)
3772               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3773           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3774             ;; This article was previously marked as read on account
3775             ;; of a low score, but now it has risen, so we mark it as
3776             ;; unread.
3777             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3778         (gnus-summary-update-mark
3779          (if (or (null gnus-summary-default-score)
3780                  (<= (abs (- score gnus-summary-default-score))
3781                      gnus-summary-zcore-fuzz))
3782              ?                          ;Whitespace
3783            (if (< score gnus-summary-default-score)
3784                gnus-score-below-mark gnus-score-over-mark))
3785          'score))
3786       ;; Do visual highlighting.
3787       (when (gnus-visual-p 'summary-highlight 'highlight)
3788         (gnus-run-hooks 'gnus-summary-update-hook)))))
3789
3790 (defvar gnus-tmp-new-adopts nil)
3791
3792 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3793   "Return the number of articles in THREAD.
3794 This may be 0 in some cases -- if none of the articles in
3795 the thread are to be displayed."
3796   (let* ((number
3797          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3798           (cond
3799            ((not (listp thread))
3800             1)
3801            ((and (consp thread) (cdr thread))
3802             (apply
3803              '+ 1 (mapcar
3804                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3805            ((null thread)
3806             1)
3807            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3808             1)
3809            (t 0))))
3810     (when (and level (zerop level) gnus-tmp-new-adopts)
3811       (incf number
3812             (apply '+ (mapcar
3813                        'gnus-summary-number-of-articles-in-thread
3814                        gnus-tmp-new-adopts))))
3815     (if char
3816         (if (> number 1) gnus-not-empty-thread-mark
3817           gnus-empty-thread-mark)
3818       number)))
3819
3820 (defsubst gnus-summary-line-message-size (head)
3821   "Return pretty-printed version of message size.
3822 This function is intended to be used in
3823 `gnus-summary-line-format-alist'."
3824   (let ((c (or (mail-header-chars head) -1)))
3825     (cond ((< c 0) "n/a")               ; chars not available
3826           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3827           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3828           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3829           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3830
3831
3832 (defun gnus-summary-set-local-parameters (group)
3833   "Go through the local params of GROUP and set all variable specs in that list."
3834   (let ((vars '(quit-config)))          ; Ignore quit-config.
3835     (dolist (elem (gnus-group-find-parameter group))
3836       (and (consp elem)                 ; Has to be a cons.
3837            (consp (cdr elem))           ; The cdr has to be a list.
3838            (symbolp (car elem))         ; Has to be a symbol in there.
3839            (not (memq (car elem) vars))
3840            (ignore-errors
3841              (push (car elem) vars)
3842              ;; Variables like `gnus-show-threads' that are globally
3843              ;; bound, if used as group parameters, need to get to be
3844              ;; buffer-local, whereas just parameters like `gcc-self',
3845              ;; `timestamp', etc. should not be bound as variables.
3846              (if (boundp (car elem))
3847                  (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3848                (eval (nth 1 elem))))))))
3849
3850 (defun gnus-summary-read-group (group &optional show-all no-article
3851                                       kill-buffer no-display backward
3852                                       select-articles)
3853   "Start reading news in newsgroup GROUP.
3854 If SHOW-ALL is non-nil, already read articles are also listed.
3855 If NO-ARTICLE is non-nil, no article is selected initially.
3856 If NO-DISPLAY, don't generate a summary buffer."
3857   (let (result)
3858     (while (and group
3859                 (null (setq result
3860                             (let ((gnus-auto-select-next nil))
3861                               (or (gnus-summary-read-group-1
3862                                    group show-all no-article
3863                                    kill-buffer no-display
3864                                    select-articles)
3865                                   (setq show-all nil
3866                                         select-articles nil)))))
3867                 (eq gnus-auto-select-next 'quietly))
3868       (set-buffer gnus-group-buffer)
3869       ;; The entry function called above goes to the next
3870       ;; group automatically, so we go two groups back
3871       ;; if we are searching for the previous group.
3872       (when backward
3873         (gnus-group-prev-unread-group 2))
3874       (if (not (equal group (gnus-group-group-name)))
3875           (setq group (gnus-group-group-name))
3876         (setq group nil)))
3877     result))
3878
3879 (defun gnus-summary-read-group-1 (group show-all no-article
3880                                         kill-buffer no-display
3881                                         &optional select-articles)
3882   ;; Killed foreign groups can't be entered.
3883   ;;  (when (and (not (gnus-group-native-p group))
3884   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3885   ;;    (error "Dead non-native groups can't be entered"))
3886   (gnus-message 5 "Retrieving newsgroup: %s..."
3887                 (gnus-group-decoded-name group))
3888   (let* ((new-group (gnus-summary-setup-buffer group))
3889          (quit-config (gnus-group-quit-config group))
3890          (did-select (and new-group (gnus-select-newsgroup
3891                                      group show-all select-articles))))
3892     (cond
3893      ;; This summary buffer exists already, so we just select it.
3894      ((not new-group)
3895       (gnus-set-global-variables)
3896       (when kill-buffer
3897         (gnus-kill-or-deaden-summary kill-buffer))
3898       (gnus-configure-windows 'summary 'force)
3899       (gnus-set-mode-line 'summary)
3900       (gnus-summary-position-point)
3901       (message "")
3902       t)
3903      ;; We couldn't select this group.
3904      ((null did-select)
3905       (when (and (eq major-mode 'gnus-summary-mode)
3906                  (not (equal (current-buffer) kill-buffer)))
3907         (kill-buffer (current-buffer))
3908         (if (not quit-config)
3909             (progn
3910               ;; Update the info -- marks might need to be removed,
3911               ;; for instance.
3912               (gnus-summary-update-info)
3913               (set-buffer gnus-group-buffer)
3914               (gnus-group-jump-to-group group)
3915               (gnus-group-next-unread-group 1))
3916           (gnus-handle-ephemeral-exit quit-config)))
3917       (let ((grpinfo (gnus-get-info group)))
3918         (if (null (gnus-info-read grpinfo))
3919             (gnus-message 3 "Group %s contains no messages"
3920                           (gnus-group-decoded-name group))
3921           (gnus-message 3 "Can't select group")))
3922       nil)
3923      ;; The user did a `C-g' while prompting for number of articles,
3924      ;; so we exit this group.
3925      ((eq did-select 'quit)
3926       (and (eq major-mode 'gnus-summary-mode)
3927            (not (equal (current-buffer) kill-buffer))
3928            (kill-buffer (current-buffer)))
3929       (when kill-buffer
3930         (gnus-kill-or-deaden-summary kill-buffer))
3931       (if (not quit-config)
3932           (progn
3933             (set-buffer gnus-group-buffer)
3934             (gnus-group-jump-to-group group)
3935             (gnus-group-next-unread-group 1)
3936             (gnus-configure-windows 'group 'force))
3937         (gnus-handle-ephemeral-exit quit-config))
3938       ;; Finally signal the quit.
3939       (signal 'quit nil))
3940      ;; The group was successfully selected.
3941      (t
3942       (gnus-set-global-variables)
3943       ;; Save the active value in effect when the group was entered.
3944       (setq gnus-newsgroup-active
3945             (gnus-copy-sequence
3946              (gnus-active gnus-newsgroup-name)))
3947       ;; You can change the summary buffer in some way with this hook.
3948       (gnus-run-hooks 'gnus-select-group-hook)
3949       (when (memq 'summary (gnus-update-format-specifications
3950                             nil 'summary 'summary-mode 'summary-dummy))
3951         ;; The format specification for the summary line was updated,
3952         ;; so we need to update the mark positions as well.
3953         (gnus-update-summary-mark-positions))
3954       ;; Do score processing.
3955       (when gnus-use-scoring
3956         (gnus-possibly-score-headers))
3957       ;; Check whether to fill in the gaps in the threads.
3958       (when gnus-build-sparse-threads
3959         (gnus-build-sparse-threads))
3960       ;; Find the initial limit.
3961       (if show-all
3962           (let ((gnus-newsgroup-dormant nil))
3963             (gnus-summary-initial-limit show-all))
3964         (gnus-summary-initial-limit show-all))
3965       ;; Generate the summary buffer.
3966       (unless no-display
3967         (gnus-summary-prepare))
3968       (when gnus-use-trees
3969         (gnus-tree-open group)
3970         (setq gnus-summary-highlight-line-function
3971               'gnus-tree-highlight-article))
3972       ;; If the summary buffer is empty, but there are some low-scored
3973       ;; articles or some excluded dormants, we include these in the
3974       ;; buffer.
3975       (when (and (zerop (buffer-size))
3976                  (not no-display))
3977         (cond (gnus-newsgroup-dormant
3978                (gnus-summary-limit-include-dormant))
3979               ((and gnus-newsgroup-scored show-all)
3980                (gnus-summary-limit-include-expunged t))))
3981       ;; Function `gnus-apply-kill-file' must be called in this hook.
3982       (gnus-run-hooks 'gnus-apply-kill-hook)
3983       (if (and (zerop (buffer-size))
3984                (not no-display))
3985           (progn
3986             ;; This newsgroup is empty.
3987             (gnus-summary-catchup-and-exit nil t)
3988             (gnus-message 6 "No unread news")
3989             (when kill-buffer
3990               (gnus-kill-or-deaden-summary kill-buffer))
3991             ;; Return nil from this function.
3992             nil)
3993         ;; Hide conversation thread subtrees.  We cannot do this in
3994         ;; gnus-summary-prepare-hook since kill processing may not
3995         ;; work with hidden articles.
3996         (gnus-summary-maybe-hide-threads)
3997         (when kill-buffer
3998           (gnus-kill-or-deaden-summary kill-buffer))
3999         (gnus-summary-auto-select-subject)
4000         ;; Show first unread article if requested.
4001         (if (and (not no-article)
4002                  (not no-display)
4003                  gnus-newsgroup-unreads
4004                  gnus-auto-select-first)
4005             (progn
4006               (gnus-configure-windows 'summary)
4007               (let ((art (gnus-summary-article-number)))
4008                 (unless (and (not gnus-plugged)
4009                              (or (memq art gnus-newsgroup-undownloaded)
4010                                  (memq art gnus-newsgroup-downloadable)))
4011                   (gnus-summary-goto-article art))))
4012           ;; Don't select any articles.
4013           (gnus-summary-position-point)
4014           (gnus-configure-windows 'summary 'force)
4015           (gnus-set-mode-line 'summary))
4016         (when (and gnus-auto-center-group
4017                    (get-buffer-window gnus-group-buffer t))
4018           ;; Gotta use windows, because recenter does weird stuff if
4019           ;; the current buffer ain't the displayed window.
4020           (let ((owin (selected-window)))
4021             (select-window (get-buffer-window gnus-group-buffer t))
4022             (when (gnus-group-goto-group group)
4023               (recenter))
4024             (select-window owin)))
4025         ;; Mark this buffer as "prepared".
4026         (setq gnus-newsgroup-prepared t)
4027         (gnus-run-hooks 'gnus-summary-prepared-hook)
4028         (unless (gnus-ephemeral-group-p group)
4029           (gnus-group-update-group group))
4030         t)))))
4031
4032 (defun gnus-summary-auto-select-subject ()
4033   "Select the subject line on initial group entry."
4034   (goto-char (point-min))
4035   (cond
4036    ((eq gnus-auto-select-subject 'best)
4037     (gnus-summary-best-unread-subject))
4038    ((eq gnus-auto-select-subject 'unread)
4039     (gnus-summary-first-unread-subject))
4040    ((eq gnus-auto-select-subject 'unseen)
4041     (gnus-summary-first-unseen-subject))
4042    ((eq gnus-auto-select-subject 'unseen-or-unread)
4043     (gnus-summary-first-unseen-or-unread-subject))
4044    ((eq gnus-auto-select-subject 'first)
4045     ;; Do nothing.
4046     )
4047    ((functionp gnus-auto-select-subject)
4048     (funcall gnus-auto-select-subject))))
4049
4050 (defun gnus-summary-prepare ()
4051   "Generate the summary buffer."
4052   (interactive)
4053   (let ((inhibit-read-only t))
4054     (erase-buffer)
4055     (setq gnus-newsgroup-data nil
4056           gnus-newsgroup-data-reverse nil)
4057     (gnus-run-hooks 'gnus-summary-generate-hook)
4058     ;; Generate the buffer, either with threads or without.
4059     (when gnus-newsgroup-headers
4060       (gnus-summary-prepare-threads
4061        (if gnus-show-threads
4062            (gnus-sort-gathered-threads
4063             (funcall gnus-summary-thread-gathering-function
4064                      (gnus-sort-threads
4065                       (gnus-cut-threads (gnus-make-threads)))))
4066          ;; Unthreaded display.
4067          (gnus-sort-articles gnus-newsgroup-headers))))
4068     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4069     ;; Call hooks for modifying summary buffer.
4070     (goto-char (point-min))
4071     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4072
4073 (defsubst gnus-general-simplify-subject (subject)
4074   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4075   (setq subject
4076         (cond
4077          ;; Truncate the subject.
4078          (gnus-simplify-subject-functions
4079           (gnus-map-function gnus-simplify-subject-functions subject))
4080          ((numberp gnus-summary-gather-subject-limit)
4081           (setq subject (gnus-simplify-subject-re subject))
4082           (if (> (length subject) gnus-summary-gather-subject-limit)
4083               (substring subject 0 gnus-summary-gather-subject-limit)
4084             subject))
4085          ;; Fuzzily simplify it.
4086          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4087           (gnus-simplify-subject-fuzzy subject))
4088          ;; Just remove the leading "Re:".
4089          (t
4090           (gnus-simplify-subject-re subject))))
4091
4092   (if (and gnus-summary-gather-exclude-subject
4093            (string-match gnus-summary-gather-exclude-subject subject))
4094       nil                         ; This article shouldn't be gathered
4095     subject))
4096
4097 (defun gnus-summary-simplify-subject-query ()
4098   "Query where the respool algorithm would put this article."
4099   (interactive)
4100   (gnus-summary-select-article)
4101   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4102
4103 (defun gnus-gather-threads-by-subject (threads)
4104   "Gather threads by looking at Subject headers."
4105   (if (not gnus-summary-make-false-root)
4106       threads
4107     (let ((hashtb (gnus-make-hashtable 1024))
4108           (prev threads)
4109           (result threads)
4110           subject hthread whole-subject)
4111       (while threads
4112         (setq subject (gnus-general-simplify-subject
4113                        (setq whole-subject (mail-header-subject
4114                                             (caar threads)))))
4115         (when subject
4116           (if (setq hthread (gnus-gethash subject hashtb))
4117               (progn
4118                 ;; We enter a dummy root into the thread, if we
4119                 ;; haven't done that already.
4120                 (unless (stringp (caar hthread))
4121                   (setcar hthread (list whole-subject (car hthread))))
4122                 ;; We add this new gathered thread to this gathered
4123                 ;; thread.
4124                 (setcdr (car hthread)
4125                         (nconc (cdar hthread) (list (car threads))))
4126                 ;; Remove it from the list of threads.
4127                 (setcdr prev (cdr threads))
4128                 (setq threads prev))
4129             ;; Enter this thread into the hash table.
4130             (gnus-sethash subject
4131                           (if gnus-summary-make-false-root-always
4132                               (progn
4133                                 ;; If you want a dummy root above all
4134                                 ;; threads...
4135                                 (setcar threads (list whole-subject
4136                                                       (car threads)))
4137                                 threads)
4138                             threads)
4139                           hashtb)))
4140         (setq prev threads)
4141         (setq threads (cdr threads)))
4142       result)))
4143
4144 (defun gnus-gather-threads-by-references (threads)
4145   "Gather threads by looking at References headers."
4146   (let ((idhashtb (gnus-make-hashtable 1024))
4147         (thhashtb (gnus-make-hashtable 1024))
4148         (prev threads)
4149         (result threads)
4150         ids references id gthread gid entered ref)
4151     (while threads
4152       (when (setq references (mail-header-references (caar threads)))
4153         (setq id (mail-header-id (caar threads))
4154               ids (inline (gnus-split-references references))
4155               entered nil)
4156         (while (setq ref (pop ids))
4157           (setq ids (delete ref ids))
4158           (if (not (setq gid (gnus-gethash ref idhashtb)))
4159               (progn
4160                 (gnus-sethash ref id idhashtb)
4161                 (gnus-sethash id threads thhashtb))
4162             (setq gthread (gnus-gethash gid thhashtb))
4163             (unless entered
4164               ;; We enter a dummy root into the thread, if we
4165               ;; haven't done that already.
4166               (unless (stringp (caar gthread))
4167                 (setcar gthread (list (mail-header-subject (caar gthread))
4168                                       (car gthread))))
4169               ;; We add this new gathered thread to this gathered
4170               ;; thread.
4171               (setcdr (car gthread)
4172                       (nconc (cdar gthread) (list (car threads)))))
4173             ;; Add it into the thread hash table.
4174             (gnus-sethash id gthread thhashtb)
4175             (setq entered t)
4176             ;; Remove it from the list of threads.
4177             (setcdr prev (cdr threads))
4178             (setq threads prev))))
4179       (setq prev threads)
4180       (setq threads (cdr threads)))
4181     result))
4182
4183 (defun gnus-sort-gathered-threads (threads)
4184   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4185   (let ((result threads))
4186     (while threads
4187       (when (stringp (caar threads))
4188         (setcdr (car threads)
4189                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4190       (setq threads (cdr threads)))
4191     result))
4192
4193 (defun gnus-thread-loop-p (root thread)
4194   "Say whether ROOT is in THREAD."
4195   (let ((stack (list thread))
4196         (infloop 0)
4197         th)
4198     (while (setq thread (pop stack))
4199       (setq th (cdr thread))
4200       (while (and th
4201                   (not (eq (caar th) root)))
4202         (pop th))
4203       (if th
4204           ;; We have found a loop.
4205           (let (ref-dep)
4206             (setcdr thread (delq (car th) (cdr thread)))
4207             (if (boundp (setq ref-dep (intern "none"
4208                                               gnus-newsgroup-dependencies)))
4209                 (setcdr (symbol-value ref-dep)
4210                         (nconc (cdr (symbol-value ref-dep))
4211                                (list (car th))))
4212               (set ref-dep (list nil (car th))))
4213             (setq infloop 1
4214                   stack nil))
4215         ;; Push all the subthreads onto the stack.
4216         (push (cdr thread) stack)))
4217     infloop))
4218
4219 (defun gnus-make-threads ()
4220   "Go through the dependency hashtb and find the roots.  Return all threads."
4221   (let (threads)
4222     (while (catch 'infloop
4223              (mapatoms
4224               (lambda (refs)
4225                 ;; Deal with self-referencing References loops.
4226                 (when (and (car (symbol-value refs))
4227                            (not (zerop
4228                                  (apply
4229                                   '+
4230                                   (mapcar
4231                                    (lambda (thread)
4232                                      (gnus-thread-loop-p
4233                                       (car (symbol-value refs)) thread))
4234                                    (cdr (symbol-value refs)))))))
4235                   (setq threads nil)
4236                   (throw 'infloop t))
4237                 (unless (car (symbol-value refs))
4238                   ;; These threads do not refer back to any other
4239                   ;; articles, so they're roots.
4240                   (setq threads (append (cdr (symbol-value refs)) threads))))
4241               gnus-newsgroup-dependencies)))
4242     threads))
4243
4244 ;; Build the thread tree.
4245 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4246   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4247
4248 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4249 if it was already present.
4250
4251 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4252 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4253 Message-IDs will be renamed to a unique Message-ID before being
4254 entered.
4255
4256 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4257   (let* ((id (mail-header-id header))
4258          (id-dep (and id (intern id dependencies)))
4259          parent-id ref ref-dep ref-header replaced)
4260     ;; Enter this `header' in the `dependencies' table.
4261     (cond
4262      ((not id-dep)
4263       (setq header nil))
4264      ;; The first two cases do the normal part: enter a new `header'
4265      ;; in the `dependencies' table.
4266      ((not (boundp id-dep))
4267       (set id-dep (list header)))
4268      ((null (car (symbol-value id-dep)))
4269       (setcar (symbol-value id-dep) header))
4270
4271      ;; From here the `header' was already present in the
4272      ;; `dependencies' table.
4273      (force-new
4274       ;; Overrides an existing entry;
4275       ;; just set the header part of the entry.
4276       (setcar (symbol-value id-dep) header)
4277       (setq replaced t))
4278
4279      ;; Renames the existing `header' to a unique Message-ID.
4280      ((not gnus-summary-ignore-duplicates)
4281       ;; An article with this Message-ID has already been seen.
4282       ;; We rename the Message-ID.
4283       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4284            (list header))
4285       (mail-header-set-id header id))
4286
4287      ;; The last case ignores an existing entry, except it adds any
4288      ;; additional Xrefs (in case the two articles came from different
4289      ;; servers.
4290      ;; Also sets `header' to `nil' meaning that the `dependencies'
4291      ;; table was *not* modified.
4292      (t
4293       (mail-header-set-xref
4294        (car (symbol-value id-dep))
4295        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4296                    "")
4297                (or (mail-header-xref header) "")))
4298       (setq header nil)))
4299
4300     (when (and header (not replaced))
4301       ;; First check that we are not creating a References loop.
4302       (setq parent-id (gnus-parent-id (mail-header-references header)))
4303       (setq ref parent-id)
4304       (while (and ref
4305                   (setq ref-dep (intern-soft ref dependencies))
4306                   (boundp ref-dep)
4307                   (setq ref-header (car (symbol-value ref-dep))))
4308         (if (string= id ref)
4309             ;; Yuk!  This is a reference loop.  Make the article be a
4310             ;; root article.
4311             (progn
4312               (mail-header-set-references (car (symbol-value id-dep)) "none")
4313               (setq ref nil)
4314               (setq parent-id nil))
4315           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4316       (setq ref-dep (intern (or parent-id "none") dependencies))
4317       (if (boundp ref-dep)
4318           (setcdr (symbol-value ref-dep)
4319                   (nconc (cdr (symbol-value ref-dep))
4320                          (list (symbol-value id-dep))))
4321         (set ref-dep (list nil (symbol-value id-dep)))))
4322     header))
4323
4324 (defun gnus-extract-message-id-from-in-reply-to (string)
4325   (if (string-match "<[^>]+>" string)
4326       (substring string (match-beginning 0) (match-end 0))
4327     nil))
4328
4329 (defun gnus-build-sparse-threads ()
4330   (let ((headers gnus-newsgroup-headers)
4331         (mail-parse-charset gnus-newsgroup-charset)
4332         (gnus-summary-ignore-duplicates t)
4333         header references generation relations
4334         subject child end new-child date)
4335     ;; First we create an alist of generations/relations, where
4336     ;; generations is how much we trust the relation, and the relation
4337     ;; is parent/child.
4338     (gnus-message 7 "Making sparse threads...")
4339     (save-excursion
4340       (nnheader-set-temp-buffer " *gnus sparse threads*")
4341       (while (setq header (pop headers))
4342         (when (and (setq references (mail-header-references header))
4343                    (not (string= references "")))
4344           (insert references)
4345           (setq child (mail-header-id header)
4346                 subject (mail-header-subject header)
4347                 date (mail-header-date header)
4348                 generation 0)
4349           (while (search-backward ">" nil t)
4350             (setq end (1+ (point)))
4351             (when (search-backward "<" nil t)
4352               (setq new-child (buffer-substring (point) end))
4353               (push (list (incf generation)
4354                           child (setq child new-child)
4355                           subject date)
4356                     relations)))
4357           (when child
4358             (push (list (1+ generation) child nil subject) relations))
4359           (erase-buffer)))
4360       (kill-buffer (current-buffer)))
4361     ;; Sort over trustworthiness.
4362     (dolist (relation (sort relations 'car-less-than-car))
4363       (when (gnus-dependencies-add-header
4364              (make-full-mail-header
4365               gnus-reffed-article-number
4366               (nth 3 relation) "" (or (nth 4 relation) "")
4367               (nth 1 relation)
4368               (or (nth 2 relation) "") 0 0 "")
4369              gnus-newsgroup-dependencies nil)
4370         (push gnus-reffed-article-number gnus-newsgroup-limit)
4371         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4372         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4373               gnus-newsgroup-reads)
4374         (decf gnus-reffed-article-number)))
4375     (gnus-message 7 "Making sparse threads...done")))
4376
4377 (defun gnus-build-old-threads ()
4378   ;; Look at all the articles that refer back to old articles, and
4379   ;; fetch the headers for the articles that aren't there.  This will
4380   ;; build complete threads - if the roots haven't been expired by the
4381   ;; server, that is.
4382   (let ((mail-parse-charset gnus-newsgroup-charset)
4383         id heads)
4384     (mapatoms
4385      (lambda (refs)
4386        (when (not (car (symbol-value refs)))
4387          (setq heads (cdr (symbol-value refs)))
4388          (while heads
4389            (if (memq (mail-header-number (caar heads))
4390                      gnus-newsgroup-dormant)
4391                (setq heads (cdr heads))
4392              (setq id (symbol-name refs))
4393              (while (and (setq id (gnus-build-get-header id))
4394                          (not (car (gnus-id-to-thread id)))))
4395              (setq heads nil)))))
4396      gnus-newsgroup-dependencies)))
4397
4398 (defsubst gnus-remove-odd-characters (string)
4399   "Translate STRING into something that doesn't contain weird characters."
4400   (mm-subst-char-in-string
4401    ?\r ?\-
4402    (mm-subst-char-in-string ?\n ?\- string t) t))
4403
4404 ;; This function has to be called with point after the article number
4405 ;; on the beginning of the line.
4406 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4407   (let ((eol (point-at-eol))
4408         (buffer (current-buffer))
4409         header references in-reply-to)
4410
4411     ;; overview: [num subject from date id refs chars lines misc]
4412     (unwind-protect
4413         (let (x)
4414           (narrow-to-region (point) eol)
4415           (unless (eobp)
4416             (forward-char))
4417
4418           (setq header
4419                 (make-full-mail-header
4420                  number                 ; number
4421                  (condition-case ()     ; subject
4422                      (gnus-remove-odd-characters
4423                       (funcall gnus-decode-encoded-word-function
4424                                (setq x (nnheader-nov-field))))
4425                    (error x))
4426                  (condition-case ()     ; from
4427                      (gnus-remove-odd-characters
4428                       (funcall gnus-decode-encoded-address-function
4429                                (setq x (nnheader-nov-field))))
4430                    (error x))
4431                  (nnheader-nov-field)   ; date
4432                  (nnheader-nov-read-message-id number)  ; id
4433                  (setq references (nnheader-nov-field)) ; refs
4434                  (nnheader-nov-read-integer) ; chars
4435                  (nnheader-nov-read-integer) ; lines
4436                  (unless (eobp)
4437                    (if (looking-at "Xref: ")
4438                        (goto-char (match-end 0)))
4439                    (nnheader-nov-field)) ; Xref
4440                  (nnheader-nov-parse-extra)))) ; extra
4441
4442       (widen))
4443
4444     (when (and (string= references "")
4445                (setq in-reply-to (mail-header-extra header))
4446                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4447       (mail-header-set-references
4448        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4449
4450     (when gnus-alter-header-function
4451       (funcall gnus-alter-header-function header))
4452     (gnus-dependencies-add-header header dependencies force-new)))
4453
4454 (defun gnus-build-get-header (id)
4455   "Look through the buffer of NOV lines and find the header to ID.
4456 Enter this line into the dependencies hash table, and return
4457 the id of the parent article (if any)."
4458   (let ((deps gnus-newsgroup-dependencies)
4459         found header)
4460     (prog1
4461         (with-current-buffer nntp-server-buffer
4462           (let ((case-fold-search nil))
4463             (goto-char (point-min))
4464             (while (and (not found)
4465                         (search-forward id nil t))
4466               (beginning-of-line)
4467               (setq found (looking-at
4468                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4469                                    (regexp-quote id))))
4470               (or found (beginning-of-line 2)))
4471             (when found
4472               (beginning-of-line)
4473               (and
4474                (setq header (gnus-nov-parse-line
4475                              (read (current-buffer)) deps))
4476                (gnus-parent-id (mail-header-references header))))))
4477       (when header
4478         (let ((number (mail-header-number header)))
4479           (push number gnus-newsgroup-limit)
4480           (push header gnus-newsgroup-headers)
4481           (if (memq number gnus-newsgroup-unselected)
4482               (progn
4483                 (setq gnus-newsgroup-unreads
4484                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4485                                                number))
4486                 (setq gnus-newsgroup-unselected
4487                       (delq number gnus-newsgroup-unselected)))
4488             (push number gnus-newsgroup-ancient)))))))
4489
4490 (defun gnus-build-all-threads ()
4491   "Read all the headers."
4492   (let ((gnus-summary-ignore-duplicates t)
4493         (mail-parse-charset gnus-newsgroup-charset)
4494         (dependencies gnus-newsgroup-dependencies)
4495         header article)
4496     (with-current-buffer nntp-server-buffer
4497       (let ((case-fold-search nil))
4498         (goto-char (point-min))
4499         (while (not (eobp))
4500           (ignore-errors
4501             (setq article (read (current-buffer))
4502                   header (gnus-nov-parse-line article dependencies)))
4503           (when header
4504             (with-current-buffer gnus-summary-buffer
4505               (push header gnus-newsgroup-headers)
4506               (if (memq (setq article (mail-header-number header))
4507                         gnus-newsgroup-unselected)
4508                   (progn
4509                     (setq gnus-newsgroup-unreads
4510                           (gnus-add-to-sorted-list
4511                            gnus-newsgroup-unreads article))
4512                     (setq gnus-newsgroup-unselected
4513                           (delq article gnus-newsgroup-unselected)))
4514                 (push article gnus-newsgroup-ancient)))
4515             (forward-line 1)))))))
4516
4517 (defun gnus-summary-update-article-line (article header)
4518   "Update the line for ARTICLE using HEADER."
4519   (let* ((id (mail-header-id header))
4520          (thread (gnus-id-to-thread id)))
4521     (unless thread
4522       (error "Article in no thread"))
4523     ;; Update the thread.
4524     (setcar thread header)
4525     (gnus-summary-goto-subject article)
4526     (let* ((datal (gnus-data-find-list article))
4527            (data (car datal))
4528            (inhibit-read-only t)
4529            (level (gnus-summary-thread-level)))
4530       (gnus-delete-line)
4531       (let ((inserted (- (point)
4532                          (progn
4533                            (gnus-summary-insert-line
4534                             header level nil
4535                             (memq article gnus-newsgroup-undownloaded)
4536                             (gnus-article-mark article)
4537                             (memq article gnus-newsgroup-replied)
4538                             (memq article gnus-newsgroup-expirable)
4539                             ;; Only insert the Subject string when it's different
4540                             ;; from the previous Subject string.
4541                             (if (and
4542                                  gnus-show-threads
4543                                  (gnus-subject-equal
4544                                   (condition-case ()
4545                                       (mail-header-subject
4546                                        (gnus-data-header
4547                                         (cadr
4548                                          (gnus-data-find-list
4549                                           article
4550                                           (gnus-data-list t)))))
4551                                     ;; Error on the side of excessive subjects.
4552                                     (error ""))
4553                                   (mail-header-subject header)))
4554                                 ""
4555                               (mail-header-subject header))
4556                             nil (cdr (assq article gnus-newsgroup-scored))
4557                             (memq article gnus-newsgroup-processable))
4558                            (point)))))
4559         (when (cdr datal)
4560           (gnus-data-update-list
4561            (cdr datal)
4562            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4563
4564 (defun gnus-summary-update-article (article &optional iheader)
4565   "Update ARTICLE in the summary buffer."
4566   (set-buffer gnus-summary-buffer)
4567   (let* ((header (gnus-summary-article-header article))
4568          (id (mail-header-id header))
4569          (data (gnus-data-find article))
4570          (thread (gnus-id-to-thread id))
4571          (references (mail-header-references header))
4572          (parent
4573           (gnus-id-to-thread
4574            (or (gnus-parent-id
4575                 (when (and references
4576                            (not (equal "" references)))
4577                   references))
4578                "none")))
4579          (inhibit-read-only t)
4580          (old (car thread)))
4581     (when thread
4582       (unless iheader
4583         (setcar thread nil)
4584         (when parent
4585           (delq thread parent)))
4586       (if (gnus-summary-insert-subject id header)
4587           ;; Set the (possibly) new article number in the data structure.
4588           (gnus-data-set-number data (gnus-id-to-article id))
4589         (setcar thread old)
4590         nil))))
4591
4592 (defun gnus-rebuild-thread (id &optional line)
4593   "Rebuild the thread containing ID.
4594 If LINE, insert the rebuilt thread starting on line LINE."
4595   (let ((inhibit-read-only t)
4596         old-pos current thread data)
4597     (if (not gnus-show-threads)
4598         (setq thread (list (car (gnus-id-to-thread id))))
4599       ;; Get the thread this article is part of.
4600       (setq thread (gnus-remove-thread id)))
4601     (setq old-pos (point-at-bol))
4602     (setq current (save-excursion
4603                     (and (re-search-backward "[\r\n]" nil t)
4604                          (gnus-summary-article-number))))
4605     ;; If this is a gathered thread, we have to go some re-gathering.
4606     (when (stringp (car thread))
4607       (let ((subject (car thread))
4608             roots thr)
4609         (setq thread (cdr thread))
4610         (while thread
4611           (unless (memq (setq thr (gnus-id-to-thread
4612                                    (gnus-root-id
4613                                     (mail-header-id (caar thread)))))
4614                         roots)
4615             (push thr roots))
4616           (setq thread (cdr thread)))
4617         ;; We now have all (unique) roots.
4618         (if (= (length roots) 1)
4619             ;; All the loose roots are now one solid root.
4620             (setq thread (car roots))
4621           (setq thread (cons subject (gnus-sort-threads roots))))))
4622     (let (threads)
4623       ;; We then insert this thread into the summary buffer.
4624       (when line
4625         (goto-char (point-min))
4626         (forward-line (1- line)))
4627       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4628         (if gnus-show-threads
4629             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4630           (gnus-summary-prepare-unthreaded thread))
4631         (setq data (nreverse gnus-newsgroup-data))
4632         (setq threads gnus-newsgroup-threads))
4633       ;; We splice the new data into the data structure.
4634       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4635       ;;!!! then we want to insert at the beginning of the buffer.
4636       ;;!!! That happens to be true with Gnus now, but that may
4637       ;;!!! change in the future.  Perhaps.
4638       (gnus-data-enter-list
4639        (if line nil current) data (- (point) old-pos))
4640       (setq gnus-newsgroup-threads
4641             (nconc threads gnus-newsgroup-threads))
4642       (gnus-data-compute-positions))))
4643
4644 (defun gnus-number-to-header (number)
4645   "Return the header for article NUMBER."
4646   (let ((headers gnus-newsgroup-headers))
4647     (while (and headers
4648                 (not (= number (mail-header-number (car headers)))))
4649       (pop headers))
4650     (when headers
4651       (car headers))))
4652
4653 (defun gnus-parent-headers (in-headers &optional generation)
4654   "Return the headers of the GENERATIONeth parent of HEADERS."
4655   (unless generation
4656     (setq generation 1))
4657   (let ((parent t)
4658         (headers in-headers)
4659         references)
4660     (while (and parent
4661                 (not (zerop generation))
4662                 (setq references (mail-header-references headers)))
4663       (setq headers (if (and references
4664                              (setq parent (gnus-parent-id references)))
4665                         (car (gnus-id-to-thread parent))
4666                       nil))
4667       (decf generation))
4668     (and (not (eq headers in-headers))
4669          headers)))
4670
4671 (defun gnus-id-to-thread (id)
4672   "Return the (sub-)thread where ID appears."
4673   (gnus-gethash id gnus-newsgroup-dependencies))
4674
4675 (defun gnus-id-to-article (id)
4676   "Return the article number of ID."
4677   (let ((thread (gnus-id-to-thread id)))
4678     (when (and thread
4679                (car thread))
4680       (mail-header-number (car thread)))))
4681
4682 (defun gnus-id-to-header (id)
4683   "Return the article headers of ID."
4684   (car (gnus-id-to-thread id)))
4685
4686 (defun gnus-article-displayed-root-p (article)
4687   "Say whether ARTICLE is a root(ish) article."
4688   (let ((level (gnus-summary-thread-level article))
4689         (refs (mail-header-references  (gnus-summary-article-header article)))
4690         particle)
4691     (cond
4692      ((null level) nil)
4693      ((zerop level) t)
4694      ((null refs) t)
4695      ((null (gnus-parent-id refs)) t)
4696      ((and (= 1 level)
4697            (null (setq particle (gnus-id-to-article
4698                                  (gnus-parent-id refs))))
4699            (null (gnus-summary-thread-level particle)))))))
4700
4701 (defun gnus-root-id (id)
4702   "Return the id of the root of the thread where ID appears."
4703   (let (last-id prev)
4704     (while (and id (setq prev (car (gnus-id-to-thread id))))
4705       (setq last-id id
4706             id (gnus-parent-id (mail-header-references prev))))
4707     last-id))
4708
4709 (defun gnus-articles-in-thread (thread)
4710   "Return the list of articles in THREAD."
4711   (cons (mail-header-number (car thread))
4712         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4713
4714 (defun gnus-remove-thread (id &optional dont-remove)
4715   "Remove the thread that has ID in it."
4716   (let (headers thread last-id)
4717     ;; First go up in this thread until we find the root.
4718     (setq last-id (gnus-root-id id)
4719           headers (message-flatten-list (gnus-id-to-thread last-id)))
4720     ;; We have now found the real root of this thread.  It might have
4721     ;; been gathered into some loose thread, so we have to search
4722     ;; through the threads to find the thread we wanted.
4723     (let ((threads gnus-newsgroup-threads)
4724           sub)
4725       (while threads
4726         (setq sub (car threads))
4727         (if (stringp (car sub))
4728             ;; This is a gathered thread, so we look at the roots
4729             ;; below it to find whether this article is in this
4730             ;; gathered root.
4731             (progn
4732               (setq sub (cdr sub))
4733               (while sub
4734                 (when (member (caar sub) headers)
4735                   (setq thread (car threads)
4736                         threads nil
4737                         sub nil))
4738                 (setq sub (cdr sub))))
4739           ;; It's an ordinary thread, so we check it.
4740           (when (eq (car sub) (car headers))
4741             (setq thread sub
4742                   threads nil)))
4743         (setq threads (cdr threads)))
4744       ;; If this article is in no thread, then it's a root.
4745       (if thread
4746           (unless dont-remove
4747             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4748         (setq thread (gnus-id-to-thread last-id)))
4749       (when thread
4750         (prog1
4751             thread                      ; We return this thread.
4752           (unless dont-remove
4753             (if (stringp (car thread))
4754                 (progn
4755                   ;; If we use dummy roots, then we have to remove the
4756                   ;; dummy root as well.
4757                   (when (eq gnus-summary-make-false-root 'dummy)
4758                     ;; We go to the dummy root by going to
4759                     ;; the first sub-"thread", and then one line up.
4760                     (gnus-summary-goto-article
4761                      (mail-header-number (caadr thread)))
4762                     (forward-line -1)
4763                     (gnus-delete-line)
4764                     (gnus-data-compute-positions))
4765                   (setq thread (cdr thread))
4766                   (while thread
4767                     (gnus-remove-thread-1 (car thread))
4768                     (setq thread (cdr thread))))
4769               (gnus-remove-thread-1 thread))))))))
4770
4771 (defun gnus-remove-thread-1 (thread)
4772   "Remove the thread THREAD recursively."
4773   (let ((number (mail-header-number (pop thread)))
4774         d)
4775     (setq thread (reverse thread))
4776     (while thread
4777       (gnus-remove-thread-1 (pop thread)))
4778     (when (setq d (gnus-data-find number))
4779       (goto-char (gnus-data-pos d))
4780       (gnus-summary-show-thread)
4781       (gnus-data-remove
4782        number
4783        (- (point-at-bol)
4784           (prog1
4785               (1+ (point-at-eol))
4786             (gnus-delete-line)))))))
4787
4788 (defun gnus-sort-threads-recursive (threads func)
4789   (sort (mapcar (lambda (thread)
4790                   (cons (car thread)
4791                         (and (cdr thread)
4792                              (gnus-sort-threads-recursive (cdr thread) func))))
4793                 threads) func))
4794
4795 (defun gnus-sort-threads-loop (threads func)
4796   (let* ((superthread (cons nil threads))
4797          (stack (list (cons superthread threads)))
4798          remaining-threads thread)
4799     (while stack
4800       (setq remaining-threads (cdr (car stack)))
4801       (if remaining-threads
4802           (progn (setq thread (car remaining-threads))
4803                  (setcdr (car stack) (cdr remaining-threads))
4804                  (if (cdr thread)
4805                      (push (cons thread (cdr thread)) stack)))
4806         (setq thread (caar stack))
4807         (setcdr thread (sort (cdr thread) func))
4808         (pop stack)))
4809     (cdr superthread)))
4810
4811 (defun gnus-sort-threads (threads)
4812   "Sort THREADS."
4813   (if (not gnus-thread-sort-functions)
4814       threads
4815     (gnus-message 8 "Sorting threads...")
4816     (prog1
4817         (condition-case nil
4818             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4819               (gnus-sort-threads-recursive
4820                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4821           ;; Even after binding max-lisp-eval-depth, the recursive
4822           ;; sorter might fail for very long threads.  In that case,
4823           ;; try using a (less well-tested) non-recursive sorter.
4824           (error (gnus-sort-threads-loop
4825                   threads (gnus-make-sort-function
4826                            gnus-thread-sort-functions))))
4827       (gnus-message 8 "Sorting threads...done"))))
4828
4829 (defun gnus-sort-articles (articles)
4830   "Sort ARTICLES."
4831   (when gnus-article-sort-functions
4832     (gnus-message 7 "Sorting articles...")
4833     (prog1
4834         (setq gnus-newsgroup-headers
4835               (sort articles (gnus-make-sort-function
4836                               gnus-article-sort-functions)))
4837       (gnus-message 7 "Sorting articles...done"))))
4838
4839 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4840 (defmacro gnus-thread-header (thread)
4841   "Return header of first article in THREAD.
4842 Note that THREAD must never, ever be anything else than a variable -
4843 using some other form will lead to serious barfage."
4844   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4845   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4846   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4847         (vector thread) 2))
4848
4849 (defsubst gnus-article-sort-by-number (h1 h2)
4850   "Sort articles by article number."
4851   (< (mail-header-number h1)
4852      (mail-header-number h2)))
4853
4854 (defun gnus-thread-sort-by-number (h1 h2)
4855   "Sort threads by root article number."
4856   (gnus-article-sort-by-number
4857    (gnus-thread-header h1) (gnus-thread-header h2)))
4858
4859 (defsubst gnus-article-sort-by-random (h1 h2)
4860   "Sort articles randomly."
4861   (zerop (random 2)))
4862
4863 (defun gnus-thread-sort-by-random (h1 h2)
4864   "Sort threads randomly."
4865   (gnus-article-sort-by-random
4866    (gnus-thread-header h1) (gnus-thread-header h2)))
4867
4868 (defsubst gnus-article-sort-by-lines (h1 h2)
4869   "Sort articles by article Lines header."
4870   (< (mail-header-lines h1)
4871      (mail-header-lines h2)))
4872
4873 (defun gnus-thread-sort-by-lines (h1 h2)
4874   "Sort threads by root article Lines header."
4875   (gnus-article-sort-by-lines
4876    (gnus-thread-header h1) (gnus-thread-header h2)))
4877
4878 (defsubst gnus-article-sort-by-chars (h1 h2)
4879   "Sort articles by octet length."
4880   (< (mail-header-chars h1)
4881      (mail-header-chars h2)))
4882
4883 (defun gnus-thread-sort-by-chars (h1 h2)
4884   "Sort threads by root article octet length."
4885   (gnus-article-sort-by-chars
4886    (gnus-thread-header h1) (gnus-thread-header h2)))
4887
4888 (defsubst gnus-article-sort-by-author (h1 h2)
4889   "Sort articles by root author."
4890   (gnus-string<
4891    (let ((extract (funcall
4892                    gnus-extract-address-components
4893                    (mail-header-from h1))))
4894      (or (car extract) (cadr extract) ""))
4895    (let ((extract (funcall
4896                    gnus-extract-address-components
4897                    (mail-header-from h2))))
4898      (or (car extract) (cadr extract) ""))))
4899
4900 (defun gnus-thread-sort-by-author (h1 h2)
4901   "Sort threads by root author."
4902   (gnus-article-sort-by-author
4903    (gnus-thread-header h1)  (gnus-thread-header h2)))
4904
4905 (defsubst gnus-article-sort-by-recipient (h1 h2)
4906   "Sort articles by recipient."
4907   (gnus-string<
4908    (let ((extract (funcall
4909                    gnus-extract-address-components
4910                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4911      (or (car extract) (cadr extract)))
4912    (let ((extract (funcall
4913                    gnus-extract-address-components
4914                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4915      (or (car extract) (cadr extract)))))
4916
4917 (defun gnus-thread-sort-by-recipient (h1 h2)
4918   "Sort threads by root recipient."
4919   (gnus-article-sort-by-recipient
4920    (gnus-thread-header h1) (gnus-thread-header h2)))
4921
4922 (defsubst gnus-article-sort-by-subject (h1 h2)
4923   "Sort articles by root subject."
4924   (gnus-string<
4925    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4926    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4927
4928 (defun gnus-thread-sort-by-subject (h1 h2)
4929   "Sort threads by root subject."
4930   (gnus-article-sort-by-subject
4931    (gnus-thread-header h1) (gnus-thread-header h2)))
4932
4933 (defsubst gnus-article-sort-by-date (h1 h2)
4934   "Sort articles by root article date."
4935   (time-less-p
4936    (gnus-date-get-time (mail-header-date h1))
4937    (gnus-date-get-time (mail-header-date h2))))
4938
4939 (defun gnus-thread-sort-by-date (h1 h2)
4940   "Sort threads by root article date."
4941   (gnus-article-sort-by-date
4942    (gnus-thread-header h1) (gnus-thread-header h2)))
4943
4944 (defsubst gnus-article-sort-by-score (h1 h2)
4945   "Sort articles by root article score.
4946 Unscored articles will be counted as having a score of zero."
4947   (> (or (cdr (assq (mail-header-number h1)
4948                     gnus-newsgroup-scored))
4949          gnus-summary-default-score 0)
4950      (or (cdr (assq (mail-header-number h2)
4951                     gnus-newsgroup-scored))
4952          gnus-summary-default-score 0)))
4953
4954 (defun gnus-thread-sort-by-score (h1 h2)
4955   "Sort threads by root article score."
4956   (gnus-article-sort-by-score
4957    (gnus-thread-header h1) (gnus-thread-header h2)))
4958
4959 (defun gnus-thread-sort-by-total-score (h1 h2)
4960   "Sort threads by the sum of all scores in the thread.
4961 Unscored articles will be counted as having a score of zero."
4962   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4963
4964 (defun gnus-thread-total-score (thread)
4965   ;; This function find the total score of THREAD.
4966   (cond
4967    ((null thread)
4968     0)
4969    ((consp thread)
4970     (if (stringp (car thread))
4971         (apply gnus-thread-score-function 0
4972                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4973       (gnus-thread-total-score-1 thread)))
4974    (t
4975     (gnus-thread-total-score-1 (list thread)))))
4976
4977 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4978   "Sort threads such that the thread with the most recently arrived article comes first."
4979   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4980
4981 (defun gnus-thread-highest-number (thread)
4982   "Return the highest article number in THREAD."
4983   (apply 'max (mapcar (lambda (header)
4984                         (mail-header-number header))
4985                       (message-flatten-list thread))))
4986
4987 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4988   "Sort threads such that the thread with the most recently dated article comes first."
4989   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4990
4991 (defun gnus-thread-latest-date (thread)
4992   "Return the highest article date in THREAD."
4993   (let ((previous-time 0))
4994     (apply 'max
4995            (mapcar
4996             (lambda (header)
4997               (setq previous-time
4998                     (condition-case ()
4999                         (gnus-float-time (mail-header-parse-date
5000                                           (mail-header-date header)))
5001                       (error previous-time))))
5002             (sort
5003              (message-flatten-list thread)
5004              (lambda (h1 h2)
5005                (< (mail-header-number h1)
5006                   (mail-header-number h2))))))))
5007
5008 (defun gnus-thread-total-score-1 (root)
5009   ;; This function find the total score of the thread below ROOT.
5010   (setq root (car root))
5011   (apply gnus-thread-score-function
5012          (or (append
5013               (mapcar 'gnus-thread-total-score
5014                       (cdr (gnus-id-to-thread (mail-header-id root))))
5015               (when (> (mail-header-number root) 0)
5016                 (list (or (cdr (assq (mail-header-number root)
5017                                      gnus-newsgroup-scored))
5018                           gnus-summary-default-score 0))))
5019              (list gnus-summary-default-score)
5020              '(0))))
5021
5022 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5023 (defvar gnus-tmp-prev-subject nil)
5024 (defvar gnus-tmp-false-parent nil)
5025 (defvar gnus-tmp-root-expunged nil)
5026 (defvar gnus-tmp-dummy-line nil)
5027
5028 (defun gnus-extra-header (type &optional header)
5029   "Return the extra header of TYPE."
5030   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5031       ""))
5032
5033 (defvar gnus-tmp-thread-tree-header-string "")
5034
5035 (defcustom gnus-sum-thread-tree-root "> "
5036   "With %B spec, used for the root of a thread.
5037 If nil, use subject instead."
5038   :version "22.1"
5039   :type '(radio (const :format "%v  " nil) string)
5040   :group 'gnus-thread)
5041
5042 (defcustom gnus-sum-thread-tree-false-root "> "
5043   "With %B spec, used for a false root of a thread.
5044 If nil, use subject instead."
5045   :version "22.1"
5046   :type '(radio (const :format "%v  " nil) string)
5047   :group 'gnus-thread)
5048
5049 (defcustom gnus-sum-thread-tree-single-indent ""
5050   "With %B spec, used for a thread with just one message.
5051 If nil, use subject instead."
5052   :version "22.1"
5053   :type '(radio (const :format "%v  " nil) string)
5054   :group 'gnus-thread)
5055
5056 (defcustom gnus-sum-thread-tree-vertical "| "
5057   "With %B spec, used for drawing a vertical line."
5058   :version "22.1"
5059   :type 'string
5060   :group 'gnus-thread)
5061
5062 (defcustom gnus-sum-thread-tree-indent "  "
5063   "With %B spec, used for indenting."
5064   :version "22.1"
5065   :type 'string
5066   :group 'gnus-thread)
5067
5068 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5069   "With %B spec, used for a leaf with brothers."
5070   :version "22.1"
5071   :type 'string
5072   :group 'gnus-thread)
5073
5074 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5075   "With %B spec, used for a leaf without brothers."
5076   :version "22.1"
5077   :type 'string
5078   :group 'gnus-thread)
5079
5080 (defcustom gnus-summary-display-while-building nil
5081   "If non-nil, show and update the summary buffer as it's being built.
5082 If the value is t, update the buffer after every line is inserted.  If
5083 the value is an integer (N), update the display every N lines."
5084   :version "22.1"
5085   :group 'gnus-thread
5086   :type '(choice (const :tag "off" nil)
5087                  number
5088                  (const :tag "frequently" t)))
5089
5090 (defun gnus-summary-prepare-threads (threads)
5091   "Prepare summary buffer from THREADS and indentation LEVEL.
5092 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5093 or a straight list of headers."
5094   (gnus-message 7 "Generating summary...")
5095
5096   (setq gnus-newsgroup-threads threads)
5097   (beginning-of-line)
5098
5099   (let ((gnus-tmp-level 0)
5100         (default-score (or gnus-summary-default-score 0))
5101         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5102         (building-line-count gnus-summary-display-while-building)
5103         (building-count (integerp gnus-summary-display-while-building))
5104         thread number subject stack state gnus-tmp-gathered beg-match
5105         new-roots gnus-tmp-new-adopts thread-end simp-subject
5106         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5107         gnus-tmp-replied gnus-tmp-subject-or-nil
5108         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5109         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5110         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5111         tree-stack)
5112
5113     (setq gnus-tmp-prev-subject nil
5114           gnus-tmp-thread-tree-header-string "")
5115
5116     (if (vectorp (car threads))
5117         ;; If this is a straight (sic) list of headers, then a
5118         ;; threaded summary display isn't required, so we just create
5119         ;; an unthreaded one.
5120         (gnus-summary-prepare-unthreaded threads)
5121
5122       ;; Do the threaded display.
5123
5124       (if gnus-summary-display-while-building
5125           (switch-to-buffer (buffer-name)))
5126       (while (or threads stack gnus-tmp-new-adopts new-roots)
5127
5128         (if (and (= gnus-tmp-level 0)
5129                  (or (not stack)
5130                      (= (caar stack) 0))
5131                  (not gnus-tmp-false-parent)
5132                  (or gnus-tmp-new-adopts new-roots))
5133             (if gnus-tmp-new-adopts
5134                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5135                       thread (list (car gnus-tmp-new-adopts))
5136                       gnus-tmp-header (caar thread)
5137                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5138               (when new-roots
5139                 (setq thread (list (car new-roots))
5140                       gnus-tmp-header (caar thread)
5141                       new-roots (cdr new-roots))))
5142
5143           (if threads
5144               ;; If there are some threads, we do them before the
5145               ;; threads on the stack.
5146               (setq thread threads
5147                     gnus-tmp-header (caar thread))
5148             ;; There were no current threads, so we pop something off
5149             ;; the stack.
5150             (setq state (car stack)
5151                   gnus-tmp-level (car state)
5152                   tree-stack (cadr state)
5153                   thread (caddr state)
5154                   stack (cdr stack)
5155                   gnus-tmp-header (caar thread))))
5156
5157         (setq gnus-tmp-false-parent nil)
5158         (setq gnus-tmp-root-expunged nil)
5159         (setq thread-end nil)
5160
5161         (if (stringp gnus-tmp-header)
5162             ;; The header is a dummy root.
5163             (cond
5164              ((eq gnus-summary-make-false-root 'adopt)
5165               ;; We let the first article adopt the rest.
5166               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5167                                                (cddar thread)))
5168               (setq gnus-tmp-gathered
5169                     (nconc (mapcar
5170                             (lambda (h) (mail-header-number (car h)))
5171                             (cddar thread))
5172                            gnus-tmp-gathered))
5173               (setq thread (cons (list (caar thread)
5174                                        (cadar thread))
5175                                  (cdr thread)))
5176               (setq gnus-tmp-level -1
5177                     gnus-tmp-false-parent t))
5178              ((eq gnus-summary-make-false-root 'empty)
5179               ;; We print adopted articles with empty subject fields.
5180               (setq gnus-tmp-gathered
5181                     (nconc (mapcar
5182                             (lambda (h) (mail-header-number (car h)))
5183                             (cddar thread))
5184                            gnus-tmp-gathered))
5185               (setq gnus-tmp-level -1))
5186              ((eq gnus-summary-make-false-root 'dummy)
5187               ;; We remember that we probably want to output a dummy
5188               ;; root.
5189               (setq gnus-tmp-dummy-line gnus-tmp-header)
5190               (setq gnus-tmp-prev-subject gnus-tmp-header))
5191              (t
5192               ;; We do not make a root for the gathered
5193               ;; sub-threads at all.
5194               (setq gnus-tmp-level -1)))
5195
5196           (setq number (mail-header-number gnus-tmp-header)
5197                 subject (mail-header-subject gnus-tmp-header)
5198                 simp-subject (gnus-simplify-subject-fully subject))
5199
5200           (cond
5201            ;; If the thread has changed subject, we might want to make
5202            ;; this subthread into a root.
5203            ((and (null gnus-thread-ignore-subject)
5204                  (not (zerop gnus-tmp-level))
5205                  gnus-tmp-prev-subject
5206                  (not (string= gnus-tmp-prev-subject simp-subject)))
5207             (setq new-roots (nconc new-roots (list (car thread)))
5208                   thread-end t
5209                   gnus-tmp-header nil))
5210            ;; If the article lies outside the current limit,
5211            ;; then we do not display it.
5212            ((not (memq number gnus-newsgroup-limit))
5213             (setq gnus-tmp-gathered
5214                   (nconc (mapcar
5215                           (lambda (h) (mail-header-number (car h)))
5216                           (cdar thread))
5217                          gnus-tmp-gathered))
5218             (setq gnus-tmp-new-adopts (if (cdar thread)
5219                                           (append gnus-tmp-new-adopts
5220                                                   (cdar thread))
5221                                         gnus-tmp-new-adopts)
5222                   thread-end t
5223                   gnus-tmp-header nil)
5224             (when (zerop gnus-tmp-level)
5225               (setq gnus-tmp-root-expunged t)))
5226            ;; Perhaps this article is to be marked as read?
5227            ((and gnus-summary-mark-below
5228                  (< (or (cdr (assq number gnus-newsgroup-scored))
5229                         default-score)
5230                     gnus-summary-mark-below)
5231                  ;; Don't touch sparse articles.
5232                  (not (gnus-summary-article-sparse-p number))
5233                  (not (gnus-summary-article-ancient-p number)))
5234             (setq gnus-newsgroup-unreads
5235                   (delq number gnus-newsgroup-unreads))
5236             (if gnus-newsgroup-auto-expire
5237                 (setq gnus-newsgroup-expirable
5238                       (gnus-add-to-sorted-list
5239                        gnus-newsgroup-expirable number))
5240               (push (cons number gnus-low-score-mark)
5241                     gnus-newsgroup-reads))))
5242
5243           (when gnus-tmp-header
5244             ;; We may have an old dummy line to output before this
5245             ;; article.
5246             (when (and gnus-tmp-dummy-line
5247                        (gnus-subject-equal
5248                         gnus-tmp-dummy-line
5249                         (mail-header-subject gnus-tmp-header)))
5250               (gnus-summary-insert-dummy-line
5251                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5252               (setq gnus-tmp-dummy-line nil))
5253
5254             ;; Compute the mark.
5255             (setq gnus-tmp-unread (gnus-article-mark number))
5256
5257             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5258                                   gnus-tmp-header gnus-tmp-level)
5259                   gnus-newsgroup-data)
5260
5261             ;; Actually insert the line.
5262             (setq
5263              gnus-tmp-subject-or-nil
5264              (cond
5265               ((and gnus-thread-ignore-subject
5266                     gnus-tmp-prev-subject
5267                     (not (string= gnus-tmp-prev-subject simp-subject)))
5268                subject)
5269               ((zerop gnus-tmp-level)
5270                (if (and (eq gnus-summary-make-false-root 'empty)
5271                         (memq number gnus-tmp-gathered)
5272                         gnus-tmp-prev-subject
5273                         (string= gnus-tmp-prev-subject simp-subject))
5274                    gnus-summary-same-subject
5275                  subject))
5276               (t gnus-summary-same-subject)))
5277             (if (and (eq gnus-summary-make-false-root 'adopt)
5278                      (= gnus-tmp-level 1)
5279                      (memq number gnus-tmp-gathered))
5280                 (setq gnus-tmp-opening-bracket ?\<
5281                       gnus-tmp-closing-bracket ?\>)
5282               (setq gnus-tmp-opening-bracket ?\[
5283                     gnus-tmp-closing-bracket ?\]))
5284             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5285                 (gnus-make-thread-indent-array
5286                  (max (* 2 (length gnus-thread-indent-array))
5287                       gnus-tmp-level)))
5288             (setq
5289              gnus-tmp-indentation
5290              (aref gnus-thread-indent-array gnus-tmp-level)
5291              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5292              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5293                                 gnus-summary-default-score 0)
5294              gnus-tmp-score-char
5295              (if (or (null gnus-summary-default-score)
5296                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5297                          gnus-summary-zcore-fuzz))
5298                  ?                      ;Whitespace
5299                (if (< gnus-tmp-score gnus-summary-default-score)
5300                    gnus-score-below-mark gnus-score-over-mark))
5301              gnus-tmp-replied
5302              (cond ((memq number gnus-newsgroup-processable)
5303                     gnus-process-mark)
5304                    ((memq number gnus-newsgroup-cached)
5305                     gnus-cached-mark)
5306                    ((memq number gnus-newsgroup-replied)
5307                     gnus-replied-mark)
5308                    ((memq number gnus-newsgroup-forwarded)
5309                     gnus-forwarded-mark)
5310                    ((memq number gnus-newsgroup-saved)
5311                     gnus-saved-mark)
5312                    ((memq number gnus-newsgroup-recent)
5313                     gnus-recent-mark)
5314                    ((memq number gnus-newsgroup-unseen)
5315                     gnus-unseen-mark)
5316                    (t gnus-no-mark))
5317              gnus-tmp-downloaded
5318              (cond ((memq number gnus-newsgroup-undownloaded)
5319                     gnus-undownloaded-mark)
5320                    (gnus-newsgroup-agentized
5321                     gnus-downloaded-mark)
5322                    (t
5323                     gnus-no-mark))
5324              gnus-tmp-from (mail-header-from gnus-tmp-header)
5325              gnus-tmp-name
5326              (cond
5327               ((string-match "<[^>]+> *$" gnus-tmp-from)
5328                (setq beg-match (match-beginning 0))
5329                (or (and (string-match "^\".+\"" gnus-tmp-from)
5330                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5331                    (substring gnus-tmp-from 0 beg-match)))
5332               ((string-match "(.+)" gnus-tmp-from)
5333                (substring gnus-tmp-from
5334                           (1+ (match-beginning 0)) (1- (match-end 0))))
5335               (t gnus-tmp-from))
5336
5337              ;; Do the %B string
5338              gnus-tmp-thread-tree-header-string
5339              (cond
5340               ((not gnus-show-threads) "")
5341               ((zerop gnus-tmp-level)
5342                (cond ((cdar thread)
5343                       (or gnus-sum-thread-tree-root subject))
5344                      (gnus-tmp-new-adopts
5345                       (or gnus-sum-thread-tree-false-root subject))
5346                      (t
5347                       (or gnus-sum-thread-tree-single-indent subject))))
5348               (t
5349                (concat (apply 'concat
5350                               (mapcar (lambda (item)
5351                                         (if (= item 1)
5352                                             gnus-sum-thread-tree-vertical
5353                                           gnus-sum-thread-tree-indent))
5354                                       (cdr (reverse tree-stack))))
5355                        (if (nth 1 thread)
5356                            gnus-sum-thread-tree-leaf-with-other
5357                          gnus-sum-thread-tree-single-leaf)))))
5358             (when (string= gnus-tmp-name "")
5359               (setq gnus-tmp-name gnus-tmp-from))
5360             (unless (numberp gnus-tmp-lines)
5361               (setq gnus-tmp-lines -1))
5362             (if (= gnus-tmp-lines -1)
5363                 (setq gnus-tmp-lines "?")
5364               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5365               (gnus-put-text-property
5366                (point)
5367                (progn (eval gnus-summary-line-format-spec) (point))
5368                'gnus-number number)
5369               (when gnus-visual-p
5370                 (forward-line -1)
5371                 (gnus-run-hooks 'gnus-summary-update-hook)
5372                 (forward-line 1))
5373
5374               (setq gnus-tmp-prev-subject simp-subject)))
5375
5376         (when (nth 1 thread)
5377           (push (list (max 0 gnus-tmp-level)
5378                       (copy-sequence tree-stack)
5379                       (nthcdr 1 thread))
5380                 stack))
5381         (push (if (nth 1 thread) 1 0) tree-stack)
5382         (incf gnus-tmp-level)
5383         (setq threads (if thread-end nil (cdar thread)))
5384         (if gnus-summary-display-while-building
5385             (if building-count
5386                 (progn
5387                   ;; use a set frequency
5388                   (setq building-line-count (1- building-line-count))
5389                   (when (= building-line-count 0)
5390                     (sit-for 0)
5391                     (setq building-line-count
5392                           gnus-summary-display-while-building)))
5393               ;; always
5394               (sit-for 0)))
5395         (unless threads
5396           (setq gnus-tmp-level 0)))))
5397   (gnus-message 7 "Generating summary...done"))
5398
5399 (defun gnus-summary-prepare-unthreaded (headers)
5400   "Generate an unthreaded summary buffer based on HEADERS."
5401   (let (header number mark)
5402
5403     (beginning-of-line)
5404
5405     (while headers
5406       ;; We may have to root out some bad articles...
5407       (when (memq (setq number (mail-header-number
5408                                 (setq header (pop headers))))
5409                   gnus-newsgroup-limit)
5410         ;; Mark article as read when it has a low score.
5411         (when (and gnus-summary-mark-below
5412                    (< (or (cdr (assq number gnus-newsgroup-scored))
5413                           gnus-summary-default-score 0)
5414                       gnus-summary-mark-below)
5415                    (not (gnus-summary-article-ancient-p number)))
5416           (setq gnus-newsgroup-unreads
5417                 (delq number gnus-newsgroup-unreads))
5418           (if gnus-newsgroup-auto-expire
5419               (push number gnus-newsgroup-expirable)
5420             (push (cons number gnus-low-score-mark)
5421                   gnus-newsgroup-reads)))
5422
5423         (setq mark (gnus-article-mark number))
5424         (push (gnus-data-make number mark (1+ (point)) header 0)
5425               gnus-newsgroup-data)
5426         (gnus-summary-insert-line
5427          header 0 number
5428          (memq number gnus-newsgroup-undownloaded)
5429          mark (memq number gnus-newsgroup-replied)
5430          (memq number gnus-newsgroup-expirable)
5431          (mail-header-subject header) nil
5432          (cdr (assq number gnus-newsgroup-scored))
5433          (memq number gnus-newsgroup-processable))))))
5434
5435 (defun gnus-summary-remove-list-identifiers ()
5436   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5437   (let ((regexp (if (consp gnus-list-identifiers)
5438                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5439                   gnus-list-identifiers))
5440         changed subject)
5441     (when regexp
5442       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5443       (dolist (header gnus-newsgroup-headers)
5444         (setq subject (mail-header-subject header)
5445               changed nil)
5446         (while (string-match regexp subject)
5447           (setq subject
5448                 (concat (substring subject 0 (match-beginning 1))
5449                         (substring subject (match-end 0)))
5450                 changed t))
5451         (when changed
5452           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5453             (setq subject
5454                   (concat (substring subject 0 (match-beginning 1))
5455                           (substring subject (match-end 1)))))
5456           (mail-header-set-subject header subject))))))
5457
5458 (defun gnus-fetch-headers (articles)
5459   "Fetch headers of ARTICLES."
5460   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5461     (gnus-message 5 "Fetching headers for %s..." name)
5462     (prog1
5463         (if (eq 'nov
5464                 (setq gnus-headers-retrieved-by
5465                       (gnus-retrieve-headers
5466                        articles gnus-newsgroup-name
5467                        ;; We might want to fetch old headers, but
5468                        ;; not if there is only 1 article.
5469                        (and (or (and
5470                                  (not (eq gnus-fetch-old-headers 'some))
5471                                  (not (numberp gnus-fetch-old-headers)))
5472                                 (> (length articles) 1))
5473                             gnus-fetch-old-headers))))
5474             (gnus-get-newsgroup-headers-xover
5475              articles nil nil gnus-newsgroup-name t)
5476           (gnus-get-newsgroup-headers))
5477       (gnus-message 5 "Fetching headers for %s...done" name))))
5478
5479 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5480   "Select newsgroup GROUP.
5481 If READ-ALL is non-nil, all articles in the group are selected.
5482 If SELECT-ARTICLES, only select those articles from GROUP."
5483   (let* ((entry (gnus-group-entry group))
5484          ;;!!! Dirty hack; should be removed.
5485          (gnus-summary-ignore-duplicates
5486           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5487               t
5488             gnus-summary-ignore-duplicates))
5489          (info (nth 2 entry))
5490          charset articles fetched-articles cached)
5491
5492     (unless (gnus-check-server
5493              (set (make-local-variable 'gnus-current-select-method)
5494                   (gnus-find-method-for-group group)))
5495       (error "Couldn't open server"))
5496     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5497
5498     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5499         (gnus-activate-group group)     ; Or we can activate it...
5500         (progn                          ; Or we bug out.
5501           (when (equal major-mode 'gnus-summary-mode)
5502             (gnus-kill-buffer (current-buffer)))
5503           (error
5504            "Couldn't activate group %s: %s"
5505            (mm-decode-coding-string group charset)
5506            (mm-decode-coding-string (gnus-status-message group) charset))))
5507
5508     (unless (gnus-request-group group t)
5509         (when (equal major-mode 'gnus-summary-mode)
5510           (gnus-kill-buffer (current-buffer)))
5511         (error "Couldn't request group %s: %s"
5512                (mm-decode-coding-string group charset)
5513                (mm-decode-coding-string (gnus-status-message group) charset)))
5514
5515     (when gnus-agent
5516       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5517
5518       (setq gnus-summary-use-undownloaded-faces
5519             (gnus-agent-find-parameter
5520              group
5521              'agent-enable-undownloaded-faces)))
5522
5523     (setq gnus-newsgroup-name group
5524           gnus-newsgroup-unselected nil
5525           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5526
5527     (let ((display (gnus-group-find-parameter group 'display)))
5528       (setq gnus-newsgroup-display
5529             (cond
5530              ((not (zerop (or (car-safe read-all) 0)))
5531               ;; The user entered the group with C-u SPC/RET, let's show
5532               ;; all articles.
5533               'gnus-not-ignore)
5534              ((eq display 'all)
5535               'gnus-not-ignore)
5536              ((arrayp display)
5537               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5538              ((numberp display)
5539               ;; The following is probably the "correct" solution, but
5540               ;; it makes Gnus fetch all headers and then limit the
5541               ;; articles (which is slow), so instead we hack the
5542               ;; select-articles parameter instead. -- Simon Josefsson
5543               ;; <jas@kth.se>
5544               ;;
5545               ;; (gnus-byte-compile
5546               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5547               ;;                         display)))))
5548               (setq select-articles
5549                     (gnus-uncompress-range
5550                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5551                              (if (> tmp 0)
5552                                  tmp
5553                                1))
5554                            (cdr (gnus-active group)))))
5555               nil)
5556              (t
5557               nil))))
5558
5559     (gnus-summary-setup-default-charset)
5560
5561     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5562     (when (gnus-virtual-group-p group)
5563       (setq cached gnus-newsgroup-cached))
5564
5565     (setq gnus-newsgroup-unreads
5566           (gnus-sorted-ndifference
5567            (gnus-sorted-ndifference gnus-newsgroup-unreads
5568                                     gnus-newsgroup-marked)
5569            gnus-newsgroup-dormant))
5570
5571     (setq gnus-newsgroup-processable nil)
5572
5573     (gnus-update-read-articles group gnus-newsgroup-unreads)
5574
5575     ;; Adjust and set lists of article marks.
5576     (when info
5577       (gnus-adjust-marked-articles info))
5578     (if (setq articles select-articles)
5579         (setq gnus-newsgroup-unselected
5580               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5581       (setq articles (gnus-articles-to-read group read-all)))
5582
5583     (cond
5584      ((null articles)
5585       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5586       'quit)
5587      ((eq articles 0) nil)
5588      (t
5589       ;; Init the dependencies hash table.
5590       (setq gnus-newsgroup-dependencies
5591             (gnus-make-hashtable (length articles)))
5592       (gnus-set-global-variables)
5593       ;; Retrieve the headers and read them in.
5594
5595       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5596
5597       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5598       (when cached
5599         (setq gnus-newsgroup-cached cached))
5600
5601       ;; Suppress duplicates?
5602       (when gnus-suppress-duplicates
5603         (gnus-dup-suppress-articles))
5604
5605       ;; Set the initial limit.
5606       (setq gnus-newsgroup-limit (copy-sequence articles))
5607       ;; Remove canceled articles from the list of unread articles.
5608       (setq fetched-articles
5609             (mapcar (lambda (headers) (mail-header-number headers))
5610                     gnus-newsgroup-headers))
5611       (setq gnus-newsgroup-articles fetched-articles)
5612       (setq gnus-newsgroup-unreads
5613             (gnus-sorted-nintersection
5614              gnus-newsgroup-unreads fetched-articles))
5615       (gnus-compute-unseen-list)
5616
5617       ;; Removed marked articles that do not exist.
5618       (gnus-update-missing-marks
5619        (gnus-sorted-difference articles fetched-articles))
5620       ;; We might want to build some more threads first.
5621       (when (and gnus-fetch-old-headers
5622                  (eq gnus-headers-retrieved-by 'nov))
5623         (if (eq gnus-fetch-old-headers 'invisible)
5624             (gnus-build-all-threads)
5625           (gnus-build-old-threads)))
5626       ;; Let the Gnus agent mark articles as read.
5627       (when gnus-agent
5628         (gnus-agent-get-undownloaded-list))
5629       ;; Remove list identifiers from subject
5630       (when gnus-list-identifiers
5631         (gnus-summary-remove-list-identifiers))
5632       ;; Check whether auto-expire is to be done in this group.
5633       (setq gnus-newsgroup-auto-expire
5634             (gnus-group-auto-expirable-p group))
5635       ;; Set up the article buffer now, if necessary.
5636       (unless (and gnus-single-article-buffer
5637                    (equal gnus-article-buffer "*Article*"))
5638         (gnus-article-setup-buffer))
5639       ;; First and last article in this newsgroup.
5640       (when gnus-newsgroup-headers
5641         (setq gnus-newsgroup-begin
5642               (mail-header-number (car gnus-newsgroup-headers))
5643               gnus-newsgroup-end
5644               (mail-header-number
5645                (gnus-last-element gnus-newsgroup-headers))))
5646       ;; GROUP is successfully selected.
5647       (or gnus-newsgroup-headers t)))))
5648
5649 (defun gnus-compute-unseen-list ()
5650   ;; The `seen' marks are treated specially.
5651   (if (not gnus-newsgroup-seen)
5652       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5653     (setq gnus-newsgroup-unseen
5654           (gnus-inverse-list-range-intersection
5655            gnus-newsgroup-articles gnus-newsgroup-seen))))
5656
5657 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5658
5659 (defun gnus-summary-display-make-predicate (display)
5660   (require 'gnus-agent)
5661   (when (= (length display) 1)
5662     (setq display (car display)))
5663   (unless gnus-summary-display-cache
5664     (dolist (elem (append '((unread . unread)
5665                             (read . read)
5666                             (unseen . unseen))
5667                           gnus-article-mark-lists))
5668       (push (cons (cdr elem)
5669                   (gnus-byte-compile
5670                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5671             gnus-summary-display-cache)))
5672   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5673         (gnus-category-predicate-cache gnus-summary-display-cache))
5674     (gnus-get-predicate display)))
5675
5676 ;; Uses the dynamically bound `number' variable.
5677 (defvar number)
5678 (defun gnus-article-marked-p (type &optional article)
5679   (let ((article (or article number)))
5680     (cond
5681      ((eq type 'tick)
5682       (memq article gnus-newsgroup-marked))
5683      ((eq type 'spam)
5684       (memq article gnus-newsgroup-spam-marked))
5685      ((eq type 'unsend)
5686       (memq article gnus-newsgroup-unsendable))
5687      ((eq type 'undownload)
5688       (memq article gnus-newsgroup-undownloaded))
5689      ((eq type 'download)
5690       (memq article gnus-newsgroup-downloadable))
5691      ((eq type 'unread)
5692       (memq article gnus-newsgroup-unreads))
5693      ((eq type 'read)
5694       (memq article gnus-newsgroup-reads))
5695      ((eq type 'dormant)
5696       (memq article gnus-newsgroup-dormant) )
5697      ((eq type 'expire)
5698       (memq article gnus-newsgroup-expirable))
5699      ((eq type 'reply)
5700       (memq article gnus-newsgroup-replied))
5701      ((eq type 'killed)
5702       (memq article gnus-newsgroup-killed))
5703      ((eq type 'bookmark)
5704       (assq article gnus-newsgroup-bookmarks))
5705      ((eq type 'score)
5706       (assq article gnus-newsgroup-scored))
5707      ((eq type 'save)
5708       (memq article gnus-newsgroup-saved))
5709      ((eq type 'cache)
5710       (memq article gnus-newsgroup-cached))
5711      ((eq type 'forward)
5712       (memq article gnus-newsgroup-forwarded))
5713      ((eq type 'seen)
5714       (not (memq article gnus-newsgroup-unseen)))
5715      ((eq type 'recent)
5716       (memq article gnus-newsgroup-recent))
5717      (t t))))
5718
5719 (defun gnus-articles-to-read (group &optional read-all)
5720   "Find out what articles the user wants to read."
5721   (let* ((articles
5722           ;; Select all articles if `read-all' is non-nil, or if there
5723           ;; are no unread articles.
5724           (if (or read-all
5725                   (and (zerop (length gnus-newsgroup-marked))
5726                        (zerop (length gnus-newsgroup-unreads)))
5727                   ;; Fetch all if the predicate is non-nil.
5728                   gnus-newsgroup-display)
5729               ;; We want to select the headers for all the articles in
5730               ;; the group, so we select either all the active
5731               ;; articles in the group, or (if that's nil), the
5732               ;; articles in the cache.
5733               (or
5734                (if gnus-newsgroup-maximum-articles
5735                    (let ((active (gnus-active group)))
5736                      (gnus-uncompress-range
5737                       (cons (max (car active)
5738                                  (- (cdr active)
5739                                     gnus-newsgroup-maximum-articles
5740                                     -1))
5741                             (cdr active))))
5742                  (gnus-uncompress-range (gnus-active group)))
5743                (gnus-cache-articles-in-group group))
5744             ;; Select only the "normal" subset of articles.
5745             (gnus-sorted-nunion
5746              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5747              gnus-newsgroup-unreads)))
5748          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5749          (scored (length scored-list))
5750          (number (length articles))
5751          (marked (+ (length gnus-newsgroup-marked)
5752                     (length gnus-newsgroup-dormant)))
5753          (select
5754           (cond
5755            ((numberp read-all)
5756             read-all)
5757            ((numberp gnus-newsgroup-display)
5758             gnus-newsgroup-display)
5759            (t
5760             (condition-case ()
5761                 (cond
5762                  ((and (or (<= scored marked) (= scored number))
5763                        (numberp gnus-large-newsgroup)
5764                        (> number gnus-large-newsgroup))
5765                   (let* ((cursor-in-echo-area nil)
5766                          (initial (gnus-parameter-large-newsgroup-initial
5767                                    gnus-newsgroup-name))
5768                          (input
5769                           (read-string
5770                            (format
5771                             "How many articles from %s (%s %d): "
5772                             (gnus-group-decoded-name gnus-newsgroup-name)
5773                             (if initial "max" "default")
5774                             number)
5775                            (if initial
5776                                (cons (number-to-string initial)
5777                                      0)))))
5778                     (if (string-match "^[ \t]*$" input) number input)))
5779                  ((and (> scored marked) (< scored number)
5780                        (> (- scored number) 20))
5781                   (let ((input
5782                          (read-string
5783                           (format "%s %s (%d scored, %d total): "
5784                                   "How many articles from"
5785                                   (gnus-group-decoded-name group)
5786                                   scored number))))
5787                     (if (string-match "^[ \t]*$" input)
5788                         number input)))
5789                  (t number))
5790               (quit
5791                (message "Quit getting the articles to read")
5792                nil))))))
5793     (setq select (if (stringp select) (string-to-number select) select))
5794     (if (or (null select) (zerop select))
5795         select
5796       (if (and (not (zerop scored)) (<= (abs select) scored))
5797           (progn
5798             (setq articles (sort scored-list '<))
5799             (setq number (length articles)))
5800         (setq articles (copy-sequence articles)))
5801
5802       (when (< (abs select) number)
5803         (if (< select 0)
5804             ;; Select the N oldest articles.
5805             (setcdr (nthcdr (1- (abs select)) articles) nil)
5806           ;; Select the N most recent articles.
5807           (setq articles (nthcdr (- number select) articles))))
5808       (setq gnus-newsgroup-unselected
5809             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5810       (when gnus-alter-articles-to-read-function
5811         (setq articles
5812               (sort
5813                (funcall gnus-alter-articles-to-read-function
5814                         gnus-newsgroup-name articles)
5815                '<)))
5816       articles)))
5817
5818 (defun gnus-killed-articles (killed articles)
5819   (let (out)
5820     (while articles
5821       (when (inline (gnus-member-of-range (car articles) killed))
5822         (push (car articles) out))
5823       (setq articles (cdr articles)))
5824     out))
5825
5826 (defun gnus-uncompress-marks (marks)
5827   "Uncompress the mark ranges in MARKS."
5828   (let ((uncompressed '(score bookmark))
5829         out)
5830     (while marks
5831       (if (memq (caar marks) uncompressed)
5832           (push (car marks) out)
5833         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5834       (setq marks (cdr marks)))
5835     out))
5836
5837 (defun gnus-article-mark-to-type (mark)
5838   "Return the type of MARK."
5839   (or (cadr (assq mark gnus-article-special-mark-lists))
5840       'list))
5841
5842 (defun gnus-article-unpropagatable-p (mark)
5843   "Return whether MARK should be propagated to back end."
5844   (memq mark gnus-article-unpropagated-mark-lists))
5845
5846 (defun gnus-adjust-marked-articles (info)
5847   "Set all article lists and remove all marks that are no longer valid."
5848   (let* ((marked-lists (gnus-info-marks info))
5849          (active (gnus-active (gnus-info-group info)))
5850          (min (car active))
5851          (max (cdr active))
5852          (types gnus-article-mark-lists)
5853          marks var articles article mark mark-type
5854          bgn end)
5855
5856     (dolist (marks marked-lists)
5857       (setq mark (car marks)
5858             mark-type (gnus-article-mark-to-type mark)
5859             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5860
5861       ;; We set the variable according to the type of the marks list,
5862       ;; and then adjust the marks to a subset of the active articles.
5863       (cond
5864        ;; Adjust "simple" lists - compressed yet unsorted
5865        ((eq mark-type 'list)
5866         ;; Simultaneously uncompress and clip to active range
5867         ;; See gnus-uncompress-range for a description of possible marks
5868         (let (l lh)
5869           (if (not (cadr marks))
5870               (set var nil)
5871             (setq articles (if (numberp (cddr marks))
5872                                (list (cdr marks))
5873                              (cdr marks))
5874                   lh (cons nil nil)
5875                   l lh)
5876
5877             (while (setq article (pop articles))
5878               (cond ((consp article)
5879                      (setq bgn (max (car article) min)
5880                            end (min (cdr article) max))
5881                      (while (<= bgn end)
5882                        (setq l (setcdr l (cons bgn nil))
5883                              bgn (1+ bgn))))
5884                     ((and (<= min article)
5885                           (>= max article))
5886                      (setq l (setcdr l (cons article nil))))))
5887             (set var (cdr lh)))))
5888        ;; Adjust assocs.
5889        ((eq mark-type 'tuple)
5890         (set var (setq articles (cdr marks)))
5891         (when (not (listp (cdr (symbol-value var))))
5892           (set var (list (symbol-value var))))
5893         (when (not (listp (cdr articles)))
5894           (setq articles (list articles)))
5895         (while articles
5896           (when (or (not (consp (setq article (pop articles))))
5897                     (< (car article) min)
5898                     (> (car article) max))
5899             (set var (delq article (symbol-value var))))))
5900        ;; Adjust ranges (sloppily).
5901        ((eq mark-type 'range)
5902         (cond
5903          ((eq mark 'seen)
5904           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5905           ;; It should be (seen (NUM1 . NUM2)).
5906           (when (numberp (cddr marks))
5907             (setcdr marks (list (cdr marks))))
5908           (setq articles (cdr marks))
5909           (while (and articles
5910                       (or (and (consp (car articles))
5911                                (> min (cdar articles)))
5912                           (and (numberp (car articles))
5913                                (> min (car articles)))))
5914             (pop articles))
5915           (set var articles))))))))
5916
5917 (defun gnus-update-missing-marks (missing)
5918   "Go through the list of MISSING articles and remove them from the mark lists."
5919   (when missing
5920     (let (var m)
5921       ;; Go through all types.
5922       (dolist (elem gnus-article-mark-lists)
5923         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5924           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5925           (when (symbol-value var)
5926             ;; This list has articles.  So we delete all missing
5927             ;; articles from it.
5928             (setq m missing)
5929             (while m
5930               (set var (delq (pop m) (symbol-value var))))))))))
5931
5932 (defun gnus-update-marks ()
5933   "Enter the various lists of marked articles into the newsgroup info list."
5934   (let ((types gnus-article-mark-lists)
5935         (info (gnus-get-info gnus-newsgroup-name))
5936         type list newmarked symbol delta-marks)
5937     (when info
5938       ;; Add all marks lists to the list of marks lists.
5939       (while (setq type (pop types))
5940         (setq list (symbol-value
5941                     (setq symbol
5942                           (intern (format "gnus-newsgroup-%s" (car type))))))
5943
5944         (when list
5945           ;; Get rid of the entries of the articles that have the
5946           ;; default score.
5947           (when (and (eq (cdr type) 'score)
5948                      gnus-save-score
5949                      list)
5950             (let* ((arts list)
5951                    (prev (cons nil list))
5952                    (all prev))
5953               (while arts
5954                 (if (or (not (consp (car arts)))
5955                         (= (cdar arts) gnus-summary-default-score))
5956                     (setcdr prev (cdr arts))
5957                   (setq prev arts))
5958                 (setq arts (cdr arts)))
5959               (setq list (cdr all)))))
5960
5961         (when (eq (cdr type) 'seen)
5962           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5963
5964         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5965           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5966
5967         (when (and (gnus-check-backend-function
5968                     'request-set-mark gnus-newsgroup-name)
5969                    (not (gnus-article-unpropagatable-p (cdr type))))
5970           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5971                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5972                  (add (gnus-remove-from-range
5973                        (gnus-copy-sequence list) old)))
5974             (when add
5975               (push (list add 'add (list (cdr type))) delta-marks))
5976             (when del
5977               (push (list del 'del (list (cdr type))) delta-marks))))
5978
5979         (when list
5980           (push (cons (cdr type) list) newmarked)))
5981
5982       (when delta-marks
5983         (unless (gnus-check-group gnus-newsgroup-name)
5984           (error "Can't open server for %s" gnus-newsgroup-name))
5985         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5986
5987       ;; Enter these new marks into the info of the group.
5988       (if (nthcdr 3 info)
5989           (setcar (nthcdr 3 info) newmarked)
5990         ;; Add the marks lists to the end of the info.
5991         (when newmarked
5992           (setcdr (nthcdr 2 info) (list newmarked))))
5993
5994       ;; Cut off the end of the info if there's nothing else there.
5995       (let ((i 5))
5996         (while (and (> i 2)
5997                     (not (nth i info)))
5998           (when (nthcdr (decf i) info)
5999             (setcdr (nthcdr i info) nil)))))))
6000
6001 (defun gnus-set-mode-line (where)
6002   "Set the mode line of the article or summary buffers.
6003 If WHERE is `summary', the summary mode line format will be used."
6004   ;; Is this mode line one we keep updated?
6005   (when (and (memq where gnus-updated-mode-lines)
6006              (symbol-value
6007               (intern (format "gnus-%s-mode-line-format-spec" where))))
6008     (let (mode-string)
6009       ;; We evaluate this in the summary buffer since these
6010       ;; variables are buffer-local to that buffer.
6011       (with-current-buffer gnus-summary-buffer
6012         ;; We bind all these variables that are used in the `eval' form
6013         ;; below.
6014         (let* ((mformat (symbol-value
6015                          (intern
6016                           (format "gnus-%s-mode-line-format-spec" where))))
6017                (gnus-tmp-group-name (gnus-mode-string-quote
6018                                      (gnus-group-decoded-name
6019                                       gnus-newsgroup-name)))
6020                (gnus-tmp-article-number (or gnus-current-article 0))
6021                (gnus-tmp-unread gnus-newsgroup-unreads)
6022                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6023                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6024                (gnus-tmp-unread-and-unselected
6025                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6026                             (zerop gnus-tmp-unselected))
6027                        "")
6028                       ((zerop gnus-tmp-unselected)
6029                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6030                       (t (format "{%d(+%d) more}"
6031                                  gnus-tmp-unread-and-unticked
6032                                  gnus-tmp-unselected))))
6033                (gnus-tmp-subject
6034                 (if (and gnus-current-headers
6035                          (vectorp gnus-current-headers))
6036                     (gnus-mode-string-quote
6037                      (mail-header-subject gnus-current-headers))
6038                   ""))
6039                bufname-length max-len
6040                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6041           (setq mode-string (eval mformat))
6042           (setq bufname-length (if (string-match "%b" mode-string)
6043                                    (- (length
6044                                        (buffer-name
6045                                         (if (eq where 'summary)
6046                                             nil
6047                                           (get-buffer gnus-article-buffer))))
6048                                       2)
6049                                  0))
6050           (setq max-len (max 4 (if gnus-mode-non-string-length
6051                                    (- (window-width)
6052                                       gnus-mode-non-string-length
6053                                       bufname-length)
6054                                  (length mode-string))))
6055           ;; We might have to chop a bit of the string off...
6056           (when (> (length mode-string) max-len)
6057             (setq mode-string
6058                   (concat (truncate-string-to-width mode-string (- max-len 3))
6059                           "...")))
6060           ;; Pad the mode string a bit.
6061           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
6062       ;; Update the mode line.
6063       (setq mode-line-buffer-identification
6064             (gnus-mode-line-buffer-identification (list mode-string)))
6065       (set-buffer-modified-p t))))
6066
6067 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6068   "Go through the HEADERS list and add all Xrefs to a hash table.
6069 The resulting hash table is returned, or nil if no Xrefs were found."
6070   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6071          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6072          (xref-hashtb (gnus-make-hashtable))
6073          start group entry number xrefs header)
6074     (while headers
6075       (setq header (pop headers))
6076       (when (and (setq xrefs (mail-header-xref header))
6077                  (not (memq (setq number (mail-header-number header))
6078                             unreads)))
6079         (setq start 0)
6080         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6081           (setq start (match-end 0))
6082           (setq group (if prefix
6083                           (concat prefix (substring xrefs (match-beginning 1)
6084                                                     (match-end 1)))
6085                         (substring xrefs (match-beginning 1) (match-end 1))))
6086           (setq number
6087                 (string-to-number (substring xrefs (match-beginning 2)
6088                                           (match-end 2))))
6089           (if (setq entry (gnus-gethash group xref-hashtb))
6090               (setcdr entry (cons number (cdr entry)))
6091             (gnus-sethash group (cons number nil) xref-hashtb)))))
6092     (and start xref-hashtb)))
6093
6094 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6095   "Look through all the headers and mark the Xrefs as read."
6096   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6097         name info xref-hashtb idlist method nth4)
6098     (with-current-buffer gnus-group-buffer
6099       (when (setq xref-hashtb
6100                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6101         (mapatoms
6102          (lambda (group)
6103            (unless (string= from-newsgroup (setq name (symbol-name group)))
6104              (setq idlist (symbol-value group))
6105              ;; Dead groups are not updated.
6106              (and (prog1
6107                       (setq info (gnus-get-info name))
6108                     (when (stringp (setq nth4 (gnus-info-method info)))
6109                       (setq nth4 (gnus-server-to-method nth4))))
6110                   ;; Only do the xrefs if the group has the same
6111                   ;; select method as the group we have just read.
6112                   (or (gnus-methods-equal-p
6113                        nth4 (gnus-find-method-for-group from-newsgroup))
6114                       virtual
6115                       (equal nth4 (setq method (gnus-find-method-for-group
6116                                                 from-newsgroup)))
6117                       (and (equal (car nth4) (car method))
6118                            (equal (nth 1 nth4) (nth 1 method))))
6119                   gnus-use-cross-reference
6120                   (or (not (eq gnus-use-cross-reference t))
6121                       virtual
6122                       ;; Only do cross-references on subscribed
6123                       ;; groups, if that is what is wanted.
6124                       (<= (gnus-info-level info) gnus-level-subscribed))
6125                   (gnus-group-make-articles-read name idlist))))
6126          xref-hashtb)))))
6127
6128 (defun gnus-compute-read-articles (group articles)
6129   (let* ((entry (gnus-group-entry group))
6130          (info (nth 2 entry))
6131          (active (gnus-active group))
6132          ninfo)
6133     (when entry
6134       ;; First peel off all invalid article numbers.
6135       (when active
6136         (let ((ids articles)
6137               id first)
6138           (while (setq id (pop ids))
6139             (when (and first (> id (cdr active)))
6140               ;; We'll end up in this situation in one particular
6141               ;; obscure situation.  If you re-scan a group and get
6142               ;; a new article that is cross-posted to a different
6143               ;; group that has not been re-scanned, you might get
6144               ;; crossposted article that has a higher number than
6145               ;; Gnus believes possible.  So we re-activate this
6146               ;; group as well.  This might mean doing the
6147               ;; crossposting thingy will *increase* the number
6148               ;; of articles in some groups.  Tsk, tsk.
6149               (setq active (or (gnus-activate-group group) active)))
6150             (when (or (> id (cdr active))
6151                       (< id (car active)))
6152               (setq articles (delq id articles))))))
6153       ;; If the read list is nil, we init it.
6154       (if (and active
6155                (null (gnus-info-read info))
6156                (> (car active) 1))
6157           (setq ninfo (cons 1 (1- (car active))))
6158         (setq ninfo (gnus-info-read info)))
6159       ;; Then we add the read articles to the range.
6160       (gnus-add-to-range
6161        ninfo (setq articles (sort articles '<))))))
6162
6163 (defun gnus-group-make-articles-read (group articles)
6164   "Update the info of GROUP to say that ARTICLES are read."
6165   (let* ((num 0)
6166          (entry (gnus-group-entry group))
6167          (info (nth 2 entry))
6168          (active (gnus-active group))
6169          range)
6170     (when entry
6171       (setq range (gnus-compute-read-articles group articles))
6172       (with-current-buffer gnus-group-buffer
6173         (gnus-undo-register
6174           `(progn
6175              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6176              (gnus-info-set-read ',info ',(gnus-info-read info))
6177              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6178              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6179              (gnus-group-update-group ,group t))))
6180       ;; Add the read articles to the range.
6181       (gnus-info-set-read info range)
6182       (gnus-request-set-mark group (list (list range 'add '(read))))
6183       ;; Then we have to re-compute how many unread
6184       ;; articles there are in this group.
6185       (when active
6186         (cond
6187          ((not range)
6188           (setq num (- (1+ (cdr active)) (car active))))
6189          ((not (listp (cdr range)))
6190           (setq num (- (cdr active) (- (1+ (cdr range))
6191                                        (car range)))))
6192          (t
6193           (while range
6194             (if (numberp (car range))
6195                 (setq num (1+ num))
6196               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6197             (setq range (cdr range)))
6198           (setq num (- (cdr active) num))))
6199         ;; Update the number of unread articles.
6200         (setcar entry num)
6201         ;; Update the group buffer.
6202         (unless (gnus-ephemeral-group-p group)
6203           (gnus-group-update-group group t))))))
6204
6205 (defvar gnus-newsgroup-none-id 0)
6206
6207 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6208   (let ((cur nntp-server-buffer)
6209         (dependencies
6210          (or dependencies
6211              (with-current-buffer gnus-summary-buffer
6212                gnus-newsgroup-dependencies)))
6213         headers id end ref number
6214         (mail-parse-charset gnus-newsgroup-charset)
6215         (mail-parse-ignored-charsets
6216          (save-current-buffer (condition-case nil
6217                                   (set-buffer gnus-summary-buffer)
6218                                 (error))
6219                               gnus-newsgroup-ignored-charsets)))
6220     (with-current-buffer nntp-server-buffer
6221       ;; Translate all TAB characters into SPACE characters.
6222       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6223       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6224       (ietf-drums-unfold-fws)
6225       (gnus-run-hooks 'gnus-parse-headers-hook)
6226       (let ((case-fold-search t)
6227             in-reply-to header p lines chars)
6228         (goto-char (point-min))
6229         ;; Search to the beginning of the next header.  Error messages
6230         ;; do not begin with 2 or 3.
6231         (while (re-search-forward "^[23][0-9]+ " nil t)
6232           (setq id nil
6233                 ref nil)
6234           ;; This implementation of this function, with nine
6235           ;; search-forwards instead of the one re-search-forward and
6236           ;; a case (which basically was the old function) is actually
6237           ;; about twice as fast, even though it looks messier.  You
6238           ;; can't have everything, I guess.  Speed and elegance
6239           ;; doesn't always go hand in hand.
6240           (setq
6241            header
6242            (vector
6243             ;; Number.
6244             (prog1
6245                 (setq number (read cur))
6246               (end-of-line)
6247               (setq p (point))
6248               (narrow-to-region (point)
6249                                 (or (and (search-forward "\n.\n" nil t)
6250                                          (- (point) 2))
6251                                     (point))))
6252             ;; Subject.
6253             (progn
6254               (goto-char p)
6255               (if (search-forward "\nsubject:" nil t)
6256                   (funcall gnus-decode-encoded-word-function
6257                            (nnheader-header-value))
6258                 "(none)"))
6259             ;; From.
6260             (progn
6261               (goto-char p)
6262               (if (search-forward "\nfrom:" nil t)
6263                   (funcall gnus-decode-encoded-address-function
6264                            (nnheader-header-value))
6265                 "(nobody)"))
6266             ;; Date.
6267             (progn
6268               (goto-char p)
6269               (if (search-forward "\ndate:" nil t)
6270                   (nnheader-header-value) ""))
6271             ;; Message-ID.
6272             (progn
6273               (goto-char p)
6274               (setq id (if (re-search-forward
6275                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6276                            ;; We do it this way to make sure the Message-ID
6277                            ;; is (somewhat) syntactically valid.
6278                            (buffer-substring (match-beginning 1)
6279                                              (match-end 1))
6280                          ;; If there was no message-id, we just fake one
6281                          ;; to make subsequent routines simpler.
6282                          (nnheader-generate-fake-message-id number))))
6283             ;; References.
6284             (progn
6285               (goto-char p)
6286               (if (search-forward "\nreferences:" nil t)
6287                   (progn
6288                     (setq end (point))
6289                     (prog1
6290                         (nnheader-header-value)
6291                       (setq ref
6292                             (buffer-substring
6293                              (progn
6294                                (end-of-line)
6295                                (search-backward ">" end t)
6296                                (1+ (point)))
6297                              (progn
6298                                (search-backward "<" end t)
6299                                (point))))))
6300                 ;; Get the references from the in-reply-to header if there
6301                 ;; were no references and the in-reply-to header looks
6302                 ;; promising.
6303                 (if (and (search-forward "\nin-reply-to:" nil t)
6304                          (setq in-reply-to (nnheader-header-value))
6305                          (string-match "<[^>]+>" in-reply-to))
6306                     (let (ref2)
6307                       (setq ref (substring in-reply-to (match-beginning 0)
6308                                            (match-end 0)))
6309                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6310                         (setq ref2 (substring in-reply-to (match-beginning 0)
6311                                               (match-end 0)))
6312                         (when (> (length ref2) (length ref))
6313                           (setq ref ref2)))
6314                       ref)
6315                   (setq ref nil))))
6316             ;; Chars.
6317             (progn
6318               (goto-char p)
6319               (if (search-forward "\nchars: " nil t)
6320                   (if (numberp (setq chars (ignore-errors (read cur))))
6321                       chars -1)
6322                 -1))
6323             ;; Lines.
6324             (progn
6325               (goto-char p)
6326               (if (search-forward "\nlines: " nil t)
6327                   (if (numberp (setq lines (ignore-errors (read cur))))
6328                       lines -1)
6329                 -1))
6330             ;; Xref.
6331             (progn
6332               (goto-char p)
6333               (and (search-forward "\nxref:" nil t)
6334                    (nnheader-header-value)))
6335             ;; Extra.
6336             (when gnus-extra-headers
6337               (let ((extra gnus-extra-headers)
6338                     out)
6339                 (while extra
6340                   (goto-char p)
6341                   (when (search-forward
6342                          (concat "\n" (symbol-name (car extra)) ":") nil t)
6343                     (push (cons (car extra) (nnheader-header-value))
6344                           out))
6345                   (pop extra))
6346                 out))))
6347           (when (equal id ref)
6348             (setq ref nil))
6349
6350           (when gnus-alter-header-function
6351             (funcall gnus-alter-header-function header)
6352             (setq id (mail-header-id header)
6353                   ref (gnus-parent-id (mail-header-references header))))
6354
6355           (when (setq header
6356                       (gnus-dependencies-add-header
6357                        header dependencies force-new))
6358             (push header headers))
6359           (goto-char (point-max))
6360           (widen))
6361         (nreverse headers)))))
6362
6363 ;; Goes through the xover lines and returns a list of vectors
6364 (defun gnus-get-newsgroup-headers-xover (sequence &optional
6365                                                   force-new dependencies
6366                                                   group also-fetch-heads)
6367   "Parse the news overview data in the server buffer.
6368 Return a list of headers that match SEQUENCE (see
6369 `nntp-retrieve-headers')."
6370   ;; Get the Xref when the users reads the articles since most/some
6371   ;; NNTP servers do not include Xrefs when using XOVER.
6372   (setq gnus-article-internal-prepare-hook '(gnus-article-get-xrefs))
6373   (let ((mail-parse-charset gnus-newsgroup-charset)
6374         (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets)
6375         (cur nntp-server-buffer)
6376         (dependencies (or dependencies gnus-newsgroup-dependencies))
6377         (allp (cond
6378                ((eq gnus-read-all-available-headers t)
6379                 t)
6380                ((and (stringp gnus-read-all-available-headers)
6381                      group)
6382                 (string-match gnus-read-all-available-headers group))
6383                (t
6384                 nil)))
6385         number headers header)
6386     (with-current-buffer nntp-server-buffer
6387       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6388       ;; Allow the user to mangle the headers before parsing them.
6389       (gnus-run-hooks 'gnus-parse-headers-hook)
6390       (goto-char (point-min))
6391       (gnus-parse-without-error
6392         (while (and (or sequence allp)
6393                     (not (eobp)))
6394           (setq number (read cur))
6395           (when (not allp)
6396             (while (and sequence
6397                         (< (car sequence) number))
6398               (setq sequence (cdr sequence))))
6399           (when (and (or allp
6400                          (and sequence
6401                               (eq number (car sequence))))
6402                      (progn
6403                        (setq sequence (cdr sequence))
6404                        (setq header (inline
6405                                       (gnus-nov-parse-line
6406                                        number dependencies force-new)))))
6407             (push header headers))
6408           (forward-line 1)))
6409       ;; A common bug in inn is that if you have posted an article and
6410       ;; then retrieves the active file, it will answer correctly --
6411       ;; the new article is included.  However, a NOV entry for the
6412       ;; article may not have been generated yet, so this may fail.
6413       ;; We work around this problem by retrieving the last few
6414       ;; headers using HEAD.
6415       (if (or (not also-fetch-heads)
6416               (not sequence))
6417           ;; We (probably) got all the headers.
6418           (nreverse headers)
6419         (let ((gnus-nov-is-evil t))
6420           (nconc
6421            (nreverse headers)
6422            (when (eq (gnus-retrieve-headers sequence group) 'headers)
6423              (gnus-get-newsgroup-headers))))))))
6424
6425 (defun gnus-article-get-xrefs ()
6426   "Fill in the Xref value in `gnus-current-headers', if necessary.
6427 This is meant to be called in `gnus-article-internal-prepare-hook'."
6428   (let ((headers (with-current-buffer gnus-summary-buffer
6429                    gnus-current-headers)))
6430     (or (not gnus-use-cross-reference)
6431         (not headers)
6432         (and (mail-header-xref headers)
6433              (not (string= (mail-header-xref headers) "")))
6434         (let ((case-fold-search t)
6435               xref)
6436           (save-restriction
6437             (nnheader-narrow-to-headers)
6438             (goto-char (point-min))
6439             (when (or (and (not (eobp))
6440                            (eq (downcase (char-after)) ?x)
6441                            (looking-at "Xref:"))
6442                       (search-forward "\nXref:" nil t))
6443               (goto-char (1+ (match-end 0)))
6444               (setq xref (buffer-substring (point) (point-at-eol)))
6445               (mail-header-set-xref headers xref)))))))
6446
6447 (defun gnus-summary-insert-subject (id &optional old-header use-old-header)
6448   "Find article ID and insert the summary line for that article.
6449 OLD-HEADER can either be a header or a line number to insert
6450 the subject line on."
6451   (let* ((line (and (numberp old-header) old-header))
6452          (old-header (and (vectorp old-header) old-header))
6453          (header (cond ((and old-header use-old-header)
6454                         old-header)
6455                        ((and (numberp id)
6456                              (gnus-number-to-header id))
6457                         (gnus-number-to-header id))
6458                        (t
6459                         (gnus-read-header id))))
6460          (number (and (numberp id) id))
6461          d)
6462     (when header
6463       ;; Rebuild the thread that this article is part of and go to the
6464       ;; article we have fetched.
6465       (when (and (not gnus-show-threads)
6466                  old-header)
6467         (when (and number
6468                    (setq d (gnus-data-find (mail-header-number old-header))))
6469           (goto-char (gnus-data-pos d))
6470           (gnus-data-remove
6471            number
6472            (- (point-at-bol)
6473               (prog1
6474                   (1+ (point-at-eol))
6475                 (gnus-delete-line))))))
6476       ;; Remove list identifiers from subject.
6477       (when gnus-list-identifiers
6478         (let ((gnus-newsgroup-headers (list header)))
6479           (gnus-summary-remove-list-identifiers)))
6480       (when old-header
6481         (mail-header-set-number header (mail-header-number old-header)))
6482       (setq gnus-newsgroup-sparse
6483             (delq (setq number (mail-header-number header))
6484                   gnus-newsgroup-sparse))
6485       (setq gnus-newsgroup-ancient (delq number gnus-newsgroup-ancient))
6486       (push number gnus-newsgroup-limit)
6487       (gnus-rebuild-thread (mail-header-id header) line)
6488       (gnus-summary-goto-subject number nil t))
6489     (when (and (numberp number)
6490                (> number 0))
6491       ;; We have to update the boundaries even if we can't fetch the
6492       ;; article if ID is a number -- so that the next `P' or `N'
6493       ;; command will fetch the previous (or next) article even
6494       ;; if the one we tried to fetch this time has been canceled.
6495       (when (> number gnus-newsgroup-end)
6496         (setq gnus-newsgroup-end number))
6497       (when (< number gnus-newsgroup-begin)
6498         (setq gnus-newsgroup-begin number))
6499       (setq gnus-newsgroup-unselected
6500             (delq number gnus-newsgroup-unselected)))
6501     ;; Report back a success?
6502     (and header (mail-header-number header))))
6503
6504 ;;; Process/prefix in the summary buffer
6505
6506 (defun gnus-summary-work-articles (n)
6507   "Return a list of articles to be worked upon.
6508 The prefix argument, the list of process marked articles, and the
6509 current article will be taken into consideration."
6510   (with-current-buffer gnus-summary-buffer
6511     (cond
6512      (n
6513       ;; A numerical prefix has been given.
6514       (setq n (prefix-numeric-value n))
6515       (let ((backward (< n 0))
6516             (n (abs (prefix-numeric-value n)))
6517             articles article)
6518         (save-excursion
6519           (while
6520               (and (> n 0)
6521                    (push (setq article (gnus-summary-article-number))
6522                          articles)
6523                    (if backward
6524                        (gnus-summary-find-prev nil article)
6525                      (gnus-summary-find-next nil article)))
6526             (decf n)))
6527         (nreverse articles)))
6528      ((and (gnus-region-active-p) (mark))
6529       (message "region active")
6530       ;; Work on the region between point and mark.
6531       (let ((max (max (point) (mark)))
6532             articles article)
6533         (save-excursion
6534           (goto-char (min (point) (mark)))
6535           (while
6536               (and
6537                (push (setq article (gnus-summary-article-number)) articles)
6538                (gnus-summary-find-next nil article)
6539                (< (point) max)))
6540           (nreverse articles))))
6541      (gnus-newsgroup-processable
6542       ;; There are process-marked articles present.
6543       ;; Save current state.
6544       (gnus-summary-save-process-mark)
6545       ;; Return the list.
6546       (reverse gnus-newsgroup-processable))
6547      (t
6548       ;; Just return the current article.
6549       (list (gnus-summary-article-number))))))
6550
6551 (defmacro gnus-summary-iterate (arg &rest forms)
6552   "Iterate over the process/prefixed articles and do FORMS.
6553 ARG is the interactive prefix given to the command.  FORMS will be
6554 executed with point over the summary line of the articles."
6555   (let ((articles (make-symbol "gnus-summary-iterate-articles")))
6556     `(let ((,articles (gnus-summary-work-articles ,arg)))
6557        (while ,articles
6558          (gnus-summary-goto-subject (car ,articles))
6559          ,@forms
6560          (pop ,articles)))))
6561
6562 (put 'gnus-summary-iterate 'lisp-indent-function 1)
6563 (put 'gnus-summary-iterate 'edebug-form-spec '(form body))
6564
6565 (defun gnus-summary-save-process-mark ()
6566   "Push the current set of process marked articles on the stack."
6567   (interactive)
6568   (push (copy-sequence gnus-newsgroup-processable)
6569         gnus-newsgroup-process-stack))
6570
6571 (defun gnus-summary-kill-process-mark ()
6572   "Push the current set of process marked articles on the stack and unmark."
6573   (interactive)
6574   (gnus-summary-save-process-mark)
6575   (gnus-summary-unmark-all-processable))
6576
6577 (defun gnus-summary-yank-process-mark ()
6578   "Pop the last process mark state off the stack and restore it."
6579   (interactive)
6580   (unless gnus-newsgroup-process-stack
6581     (error "Empty mark stack"))
6582   (gnus-summary-process-mark-set (pop gnus-newsgroup-process-stack)))
6583
6584 (defun gnus-summary-process-mark-set (set)
6585   "Make SET into the current process marked articles."
6586   (gnus-summary-unmark-all-processable)
6587   (mapc 'gnus-summary-set-process-mark set))
6588
6589 ;;; Searching and stuff
6590
6591 (defun gnus-summary-search-group (&optional backward use-level)
6592   "Search for next unread newsgroup.
6593 If optional argument BACKWARD is non-nil, search backward instead."
6594   (with-current-buffer gnus-group-buffer
6595     (when (gnus-group-search-forward
6596            backward nil (if use-level (gnus-group-group-level) nil))
6597       (gnus-group-group-name))))
6598
6599 (defun gnus-summary-best-group (&optional exclude-group)
6600   "Find the name of the best unread group.
6601 If EXCLUDE-GROUP, do not go to this group."
6602   (with-current-buffer gnus-group-buffer
6603     (save-excursion
6604       (gnus-group-best-unread-group exclude-group))))
6605
6606 (defun gnus-summary-find-next (&optional unread article backward)
6607   (if backward
6608       (gnus-summary-find-prev unread article)
6609     (let* ((dummy (gnus-summary-article-intangible-p))
6610            (article (or article (gnus-summary-article-number)))
6611            (data (gnus-data-find-list article))
6612            result)
6613       (when (and (not dummy)
6614                  (or (not gnus-summary-check-current)
6615                      (not unread)
6616                      (not (gnus-data-unread-p (car data)))))
6617         (setq data (cdr data)))
6618       (when (setq result
6619                   (if unread
6620                       (progn
6621                         (while data
6622                           (unless (memq (gnus-data-number (car data))
6623                                         (cond
6624                                          ((eq gnus-auto-goto-ignores
6625                                               'always-undownloaded)
6626                                           gnus-newsgroup-undownloaded)
6627                                          (gnus-plugged
6628                                           nil)
6629                                          ((eq gnus-auto-goto-ignores
6630                                               'unfetched)
6631                                           gnus-newsgroup-unfetched)
6632                                          ((eq gnus-auto-goto-ignores
6633                                               'undownloaded)
6634                                           gnus-newsgroup-undownloaded)))
6635                             (when (gnus-data-unread-p (car data))
6636                               (setq result (car data)
6637                                     data nil)))
6638                           (setq data (cdr data)))
6639                         result)
6640                     (car data)))
6641         (goto-char (gnus-data-pos result))
6642         (gnus-data-number result)))))
6643
6644 (defun gnus-summary-find-prev (&optional unread article)
6645   (let* ((eobp (eobp))
6646          (article (or article (gnus-summary-article-number)))
6647          (data (gnus-data-find-list article (gnus-data-list 'rev)))
6648          result)
6649     (when (and (not eobp)
6650                (or (not gnus-summary-check-current)
6651                    (not unread)
6652                    (not (gnus-data-unread-p (car data)))))
6653       (setq data (cdr data)))
6654     (when (setq result
6655                 (if unread
6656                     (progn
6657                       (while data
6658                         (unless (memq (gnus-data-number (car data))
6659                                       (cond
6660                                        ((eq gnus-auto-goto-ignores
6661                                             'always-undownloaded)
6662                                         gnus-newsgroup-undownloaded)
6663                                        (gnus-plugged
6664                                         nil)
6665                                        ((eq gnus-auto-goto-ignores
6666                                             'unfetched)
6667                                         gnus-newsgroup-unfetched)
6668                                        ((eq gnus-auto-goto-ignores
6669                                             'undownloaded)
6670                                         gnus-newsgroup-undownloaded)))
6671                           (when (gnus-data-unread-p (car data))
6672                             (setq result (car data)
6673                                   data nil)))
6674                         (setq data (cdr data)))
6675                       result)
6676                   (car data)))
6677       (goto-char (gnus-data-pos result))
6678       (gnus-data-number result))))
6679
6680 (defun gnus-summary-find-subject (subject &optional unread backward article)
6681   (let* ((simp-subject (gnus-simplify-subject-fully subject))
6682          (article (or article (gnus-summary-article-number)))
6683          (articles (gnus-data-list backward))
6684          (arts (gnus-data-find-list article articles))
6685          result)
6686     (when (or (not gnus-summary-check-current)
6687               (not unread)
6688               (not (gnus-data-unread-p (car arts))))
6689       (setq arts (cdr arts)))
6690     (while arts
6691       (and (or (not unread)
6692                (gnus-data-unread-p (car arts)))
6693            (vectorp (gnus-data-header (car arts)))
6694            (gnus-subject-equal
6695             simp-subject (mail-header-subject (gnus-data-header (car arts))) t)
6696            (setq result (car arts)
6697                  arts nil))
6698       (setq arts (cdr arts)))
6699     (and result
6700          (goto-char (gnus-data-pos result))
6701          (gnus-data-number result))))
6702
6703 (defun gnus-summary-search-forward (&optional unread subject backward)
6704   "Search forward for an article.
6705 If UNREAD, look for unread articles.  If SUBJECT, look for
6706 articles with that subject.  If BACKWARD, search backward instead."
6707   (cond (subject (gnus-summary-find-subject subject unread backward))
6708         (backward (gnus-summary-find-prev unread))
6709         (t (gnus-summary-find-next unread))))
6710
6711 (defun gnus-recenter (&optional n)
6712   "Center point in window and redisplay frame.
6713 Also do horizontal recentering."
6714   (interactive "P")
6715   (when (and gnus-auto-center-summary
6716              (not (eq gnus-auto-center-summary 'vertical)))
6717     (gnus-horizontal-recenter))
6718   (if (fboundp 'recenter-top-bottom)
6719       (recenter-top-bottom n)
6720     (recenter n)))
6721
6722 (put 'gnus-recenter 'isearch-scroll t)
6723
6724 (defun gnus-forward-line-ignore-invisible (n)
6725   "Move N lines forward (backward if N is negative).
6726 Like forward-line, but skip over (and don't count) invisible lines."
6727   (let (done)
6728     (while (and (> n 0) (not done))
6729       ;; If the following character is currently invisible,
6730       ;; skip all characters with that same `invisible' property value.
6731       (while (gnus-invisible-p (point))
6732         (goto-char (gnus-next-char-property-change (point))))
6733       (forward-line 1)
6734       (if (eobp)
6735           (setq done t)
6736         (setq n (1- n))))
6737     (while (and (< n 0) (not done))
6738       (forward-line -1)
6739       (if (bobp) (setq done t)
6740         (setq n (1+ n))
6741         (while (and (not (bobp)) (gnus-invisible-p (1- (point))))
6742           (goto-char (gnus-previous-char-property-change (point))))))))
6743
6744 (defun gnus-summary-recenter ()
6745   "Center point in the summary window.
6746 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6747 displayed, no centering will be performed."
6748   ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6749   ;; Recenter only when requested.  Suggested by popovich@park.cs.columbia.edu.
6750   (interactive)
6751   ;; The user has to want it.
6752   (when gnus-auto-center-summary
6753     (let* ((top (cond ((< (window-height) 4) 0)
6754                       ((< (window-height) 7) 1)
6755                       (t (if (numberp gnus-auto-center-summary)
6756                              gnus-auto-center-summary
6757                            (/ (1- (window-height)) 2)))))
6758            (height (1- (window-height)))
6759            (bottom (save-excursion
6760                      (goto-char (point-max))
6761                      (gnus-forward-line-ignore-invisible (- height))
6762                      (point)))
6763            (window (get-buffer-window (current-buffer))))
6764       (when (get-buffer-window gnus-article-buffer)
6765         ;; Only do recentering when the article buffer is displayed,
6766         ;; Set the window start to either `bottom', which is the biggest
6767         ;; possible valid number, or the second line from the top,
6768         ;; whichever is the least.
6769         (let ((top-pos (save-excursion
6770                          (gnus-forward-line-ignore-invisible (- top))
6771                          (point))))
6772           (if (> bottom top-pos)
6773               ;; Keep the second line from the top visible
6774               (set-window-start window top-pos)
6775             ;; Try to keep the bottom line visible; if it's partially
6776             ;; obscured, either scroll one more line to make it fully
6777             ;; visible, or revert to using TOP-POS.
6778             (save-excursion
6779               (goto-char (point-max))
6780               (gnus-forward-line-ignore-invisible -1)
6781               (let ((last-line-start (point)))
6782                 (goto-char bottom)
6783                 (set-window-start window (point) t)
6784                 (when (not (pos-visible-in-window-p last-line-start window))
6785                   (gnus-forward-line-ignore-invisible 1)
6786                   (set-window-start window (min (point) top-pos) t)))))))
6787       ;; Do horizontal recentering while we're at it.
6788       (when (and (get-buffer-window (current-buffer) t)
6789                  (not (eq gnus-auto-center-summary 'vertical)))
6790         (let ((selected (selected-window)))
6791           (select-window (get-buffer-window (current-buffer) t))
6792           (gnus-summary-position-point)
6793           (gnus-horizontal-recenter)
6794           (select-window selected))))))
6795
6796 (defun gnus-summary-jump-to-group (newsgroup)
6797   "Move point to NEWSGROUP in group mode buffer."
6798   ;; Keep update point of group mode buffer if visible.
6799   (if (eq (current-buffer) (get-buffer gnus-group-buffer))
6800       (save-window-excursion
6801         ;; Take care of tree window mode.
6802         (when (get-buffer-window gnus-group-buffer)
6803           (pop-to-buffer gnus-group-buffer))
6804         (gnus-group-jump-to-group newsgroup))
6805     (save-excursion
6806       ;; Take care of tree window mode.
6807       (if (get-buffer-window gnus-group-buffer 0)
6808           (pop-to-buffer gnus-group-buffer)
6809         (set-buffer gnus-group-buffer))
6810       (gnus-group-jump-to-group newsgroup))))
6811
6812 ;; This function returns a list of article numbers based on the
6813 ;; difference between the ranges of read articles in this group and
6814 ;; the range of active articles.
6815 (defun gnus-list-of-unread-articles (group)
6816   (let* ((read (gnus-info-read (gnus-get-info group)))
6817          (active (or (gnus-active group) (gnus-activate-group group)))
6818          (last (or (cdr active)
6819                    (error "Group %s couldn't be activated " group)))
6820          (bottom (if gnus-newsgroup-maximum-articles
6821                      (max (car active)
6822                           (- last gnus-newsgroup-maximum-articles -1))
6823                    (car active)))
6824          first nlast unread)
6825     ;; If none are read, then all are unread.
6826     (if (not read)
6827         (setq first bottom)
6828       ;; If the range of read articles is a single range, then the
6829       ;; first unread article is the article after the last read
6830       ;; article.  Sounds logical, doesn't it?
6831       (if (and (not (listp (cdr read)))
6832                (or (< (car read) bottom)
6833                    (progn (setq read (list read))
6834                           nil)))
6835           (setq first (max bottom (1+ (cdr read))))
6836         ;; `read' is a list of ranges.
6837         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6838                                   (caar read)))
6839                   1)
6840           (setq first bottom))
6841         (while read
6842           (when first
6843             (while (< first nlast)
6844               (setq unread (cons first unread)
6845                     first (1+ first))))
6846           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6847           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6848           (setq read (cdr read)))))
6849     ;; And add the last unread articles.
6850     (while (<= first last)
6851       (setq unread (cons first unread)
6852             first (1+ first)))
6853     ;; Return the list of unread articles.
6854     (delq 0 (nreverse unread))))
6855
6856 (defun gnus-list-of-read-articles (group)
6857   "Return a list of unread, unticked and non-dormant articles."
6858   (let* ((info (gnus-get-info group))
6859          (marked (gnus-info-marks info))
6860          (active (gnus-active group)))
6861     (and info active
6862          (gnus-list-range-difference
6863           (gnus-list-range-difference
6864            (gnus-sorted-complement
6865             (gnus-uncompress-range
6866              (if gnus-newsgroup-maximum-articles
6867                  (cons (max (car active)
6868                             (- (cdr active)
6869                                gnus-newsgroup-maximum-articles
6870                                -1))
6871                        (cdr active))
6872                active))
6873             (gnus-list-of-unread-articles group))
6874            (cdr (assq 'dormant marked)))
6875           (cdr (assq 'tick marked))))))
6876
6877 ;; This function returns a sequence of article numbers based on the
6878 ;; difference between the ranges of read articles in this group and
6879 ;; the range of active articles.
6880 (defun gnus-sequence-of-unread-articles (group)
6881   (let* ((read (gnus-info-read (gnus-get-info group)))
6882          (active (or (gnus-active group) (gnus-activate-group group)))
6883          (last (cdr active))
6884          (bottom (if gnus-newsgroup-maximum-articles
6885                      (max (car active)
6886                           (- last gnus-newsgroup-maximum-articles -1))
6887                    (car active)))
6888          first nlast unread)
6889     ;; If none are read, then all are unread.
6890     (if (not read)
6891         (setq first bottom)
6892       ;; If the range of read articles is a single range, then the
6893       ;; first unread article is the article after the last read
6894       ;; article.  Sounds logical, doesn't it?
6895       (if (and (not (listp (cdr read)))
6896                (or (< (car read) bottom)
6897                    (progn (setq read (list read))
6898                           nil)))
6899           (setq first (max bottom (1+ (cdr read))))
6900         ;; `read' is a list of ranges.
6901         (when (/= (setq nlast (or (and (numberp (car read)) (car read))
6902                                   (caar read)))
6903                   1)
6904           (setq first bottom))
6905         (while read
6906           (when first
6907             (push (cons first nlast) unread))
6908           (setq first (1+ (if (atom (car read)) (car read) (cdar read))))
6909           (setq nlast (if (atom (cadr read)) (cadr read) (caadr read)))
6910           (setq read (cdr read)))))
6911     ;; And add the last unread articles.
6912     (cond ((not (and first last))
6913            nil)
6914           ((< first last)
6915            (push (cons first last) unread))
6916           ((= first last)
6917            (push first unread)))
6918     ;; Return the sequence of unread articles.
6919     (delq 0 (nreverse unread))))
6920
6921 ;; Various summary commands
6922
6923 (defun gnus-summary-select-article-buffer ()
6924   "Reconfigure windows to show article buffer."
6925   (interactive)
6926   (if (not (gnus-buffer-live-p gnus-article-buffer))
6927       (error "There is no article buffer for this summary buffer")
6928     (gnus-configure-windows 'article)
6929     (select-window (get-buffer-window gnus-article-buffer))))
6930
6931 (defun gnus-summary-universal-argument (arg)
6932   "Perform any operation on all articles that are process/prefixed."
6933   (interactive "P")
6934   (let ((articles (gnus-summary-work-articles arg))
6935         func article)
6936     (if (eq
6937          (setq
6938           func
6939           (key-binding
6940            (read-key-sequence
6941             (substitute-command-keys
6942              "\\<gnus-summary-mode-map>\\[gnus-summary-universal-argument]"))))
6943          'undefined)
6944         (gnus-error 1 "Undefined key")
6945       (save-excursion
6946         (while articles
6947           (gnus-summary-goto-subject (setq article (pop articles)))
6948           (let (gnus-newsgroup-processable)
6949             (command-execute func))
6950           (gnus-summary-remove-process-mark article)))))
6951   (gnus-summary-position-point))
6952
6953 (defun gnus-summary-toggle-truncation (&optional arg)
6954   "Toggle truncation of summary lines.
6955 With ARG, turn line truncation on if ARG is positive."
6956   (interactive "P")
6957   (setq truncate-lines
6958         (if (null arg) (not truncate-lines)
6959           (> (prefix-numeric-value arg) 0)))
6960   (redraw-display))
6961
6962 (defun gnus-summary-find-for-reselect ()
6963   "Return the number of an article to stay on across a reselect.
6964 The current article is considered, then following articles, then previous
6965 articles.  An article is sought which is not cancelled and isn't a temporary
6966 insertion from another group.  If there's no such then return a dummy 0."
6967   (let (found)
6968     (dolist (rev '(nil t))
6969       (unless found      ; don't demand the reverse list if we don't need it
6970         (let ((data (gnus-data-find-list
6971                      (gnus-summary-article-number) (gnus-data-list rev))))
6972           (while (and data (not found))
6973             (if (and (< 0 (gnus-data-number (car data)))
6974                      (not (eq gnus-canceled-mark (gnus-data-mark (car data)))))
6975                 (setq found (gnus-data-number (car data))))
6976             (setq data (cdr data))))))
6977     (or found 0)))
6978
6979 (defun gnus-summary-reselect-current-group (&optional all rescan)
6980   "Exit and then reselect the current newsgroup.
6981 The prefix argument ALL means to select all articles."
6982   (interactive "P")
6983   (when (gnus-ephemeral-group-p gnus-newsgroup-name)
6984     (error "Ephemeral groups can't be reselected"))
6985   (let ((current-subject (gnus-summary-find-for-reselect))
6986         (group gnus-newsgroup-name))
6987     (setq gnus-newsgroup-begin nil)
6988     (gnus-summary-exit nil 'leave-hidden)
6989     ;; We have to adjust the point of group mode buffer because
6990     ;; point was moved to the next unread newsgroup by exiting.
6991     (gnus-summary-jump-to-group group)
6992     (when rescan
6993       (save-excursion
6994         (gnus-group-get-new-news-this-group 1)))
6995     (gnus-group-read-group all t)
6996     (gnus-summary-goto-subject current-subject nil t)))
6997
6998 (defun gnus-summary-rescan-group (&optional all)
6999   "Exit the newsgroup, ask for new articles, and select the newsgroup."
7000   (interactive "P")
7001   (gnus-summary-reselect-current-group all t))
7002
7003 (defun gnus-summary-update-info (&optional non-destructive)
7004   (save-excursion
7005     (let ((group gnus-newsgroup-name))
7006       (when group
7007         (when gnus-newsgroup-kill-headers
7008           (setq gnus-newsgroup-killed
7009                 (gnus-compress-sequence
7010                  (gnus-sorted-union
7011                   (gnus-list-range-intersection
7012                    gnus-newsgroup-unselected gnus-newsgroup-killed)
7013                   gnus-newsgroup-unreads)
7014                  t)))
7015         (unless (listp (cdr gnus-newsgroup-killed))
7016           (setq gnus-newsgroup-killed (list gnus-newsgroup-killed)))
7017         (let ((headers gnus-newsgroup-headers))
7018           ;; Set the new ranges of read articles.
7019           (with-current-buffer gnus-group-buffer
7020             (gnus-undo-force-boundary))
7021           (gnus-update-read-articles
7022            group (gnus-sorted-union
7023                   gnus-newsgroup-unreads gnus-newsgroup-unselected))
7024           ;; Set the current article marks.
7025           (let ((gnus-newsgroup-scored
7026                  (if (and (not gnus-save-score)
7027                           (not non-destructive))
7028                      nil
7029                    gnus-newsgroup-scored)))
7030             (save-excursion
7031               (gnus-update-marks)))
7032           ;; Do the cross-ref thing.
7033           (when gnus-use-cross-reference
7034             (gnus-mark-xrefs-as-read group headers gnus-newsgroup-unreads))
7035           ;; Do not switch windows but change the buffer to work.
7036           (set-buffer gnus-group-buffer)
7037           (unless (gnus-ephemeral-group-p group)
7038             (gnus-group-update-group group)))))))
7039
7040 (defun gnus-summary-save-newsrc (&optional force)
7041   "Save the current number of read/marked articles in the dribble buffer.
7042 The dribble buffer will then be saved.
7043 If FORCE (the prefix), also save the .newsrc file(s)."
7044   (interactive "P")
7045   (gnus-summary-update-info t)
7046   (if force
7047       (gnus-save-newsrc-file)
7048     (gnus-dribble-save)))
7049
7050 (declare-function gnus-cache-write-active "gnus-cache" (&optional force))
7051
7052 (defun gnus-summary-exit (&optional temporary leave-hidden)
7053   "Exit reading current newsgroup, and then return to group selection mode.
7054 `gnus-exit-group-hook' is called with no arguments if that value is non-nil."
7055   (interactive)
7056   (gnus-set-global-variables)
7057   (when (gnus-buffer-live-p gnus-article-buffer)
7058     (with-current-buffer gnus-article-buffer
7059       (mm-destroy-parts gnus-article-mime-handles)
7060       ;; Set it to nil for safety reason.
7061       (setq gnus-article-mime-handle-alist nil)
7062       (setq gnus-article-mime-handles nil)))
7063   (gnus-kill-save-kill-buffer)
7064   (gnus-async-halt-prefetch)
7065   (let* ((group gnus-newsgroup-name)
7066          (quit-config (gnus-group-quit-config gnus-newsgroup-name))
7067          (gnus-group-is-exiting-p t)
7068          (mode major-mode)
7069          (group-point nil)
7070          (buf (current-buffer)))
7071     (unless quit-config
7072       ;; Do adaptive scoring, and possibly save score files.
7073       (when gnus-newsgroup-adaptive
7074         (gnus-score-adaptive))
7075       (when gnus-use-scoring
7076         (gnus-score-save)))
7077     (gnus-run-hooks 'gnus-summary-prepare-exit-hook)
7078     ;; If we have several article buffers, we kill them at exit.
7079     (unless gnus-single-article-buffer
7080       (when (gnus-buffer-live-p gnus-article-buffer)
7081         (with-current-buffer gnus-article-buffer
7082           ;; Don't kill sticky article buffers
7083           (unless (eq major-mode 'gnus-sticky-article-mode)
7084             (gnus-kill-buffer gnus-article-buffer)
7085             (setq gnus-article-current nil))))
7086       (gnus-kill-buffer gnus-original-article-buffer))
7087     (when gnus-use-cache
7088       (gnus-cache-possibly-remove-articles)
7089       (gnus-cache-save-buffers))
7090     (gnus-async-prefetch-remove-group group)
7091     (when gnus-suppress-duplicates
7092       (gnus-dup-enter-articles))
7093     (when gnus-use-trees
7094       (gnus-tree-close group))
7095     (when gnus-use-cache
7096       (gnus-cache-write-active))
7097     ;; Remove entries for this group.
7098     (nnmail-purge-split-history (gnus-group-real-name group))
7099     ;; Make all changes in this group permanent.
7100     (unless quit-config
7101       (gnus-run-hooks 'gnus-exit-group-hook)
7102       (gnus-summary-update-info))
7103     (gnus-close-group group)
7104     ;; Make sure where we were, and go to next newsgroup.
7105     (set-buffer gnus-group-buffer)
7106     (unless quit-config
7107       (gnus-group-jump-to-group group))
7108     (gnus-run-hooks 'gnus-summary-exit-hook)
7109     (unless (or quit-config
7110                 (not gnus-summary-next-group-on-exit)
7111                 ;; If this group has disappeared from the summary
7112                 ;; buffer, don't skip forwards.
7113                 (not (string= group (gnus-group-group-name))))
7114       (gnus-group-next-unread-group 1))
7115     (setq group-point (point))
7116     (if temporary
7117         nil                             ;Nothing to do.
7118       (set-buffer buf)
7119       (if (not gnus-kill-summary-on-exit)
7120           (progn
7121             (gnus-deaden-summary)
7122             (setq mode nil))
7123         ;; We set all buffer-local variables to nil.  It is unclear why
7124         ;; this is needed, but if we don't, buffer-local variables are
7125         ;; not garbage-collected, it seems.  This would the lead to en
7126         ;; ever-growing Emacs.
7127         (gnus-summary-clear-local-variables)
7128         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7129           (gnus-summary-clear-local-variables))
7130         (when (get-buffer gnus-article-buffer)
7131           (bury-buffer gnus-article-buffer))
7132         ;; Return to group mode buffer.
7133         (when (eq mode 'gnus-summary-mode)
7134           (gnus-kill-buffer buf)))
7135       (setq gnus-current-select-method gnus-select-method)
7136       (set-buffer gnus-group-buffer)
7137       (if quit-config
7138           (gnus-handle-ephemeral-exit quit-config)
7139         (goto-char group-point)
7140         ;; If gnus-group-buffer is already displayed, make sure we also move
7141         ;; the cursor in the window that displays it.
7142         (let ((win (get-buffer-window (current-buffer) 0)))
7143           (if win (set-window-point win (point))))
7144         (unless leave-hidden
7145           (gnus-configure-windows 'group 'force)))
7146       ;; Clear the current group name.
7147       (unless quit-config
7148         (setq gnus-newsgroup-name nil)))))
7149
7150 (defalias 'gnus-summary-quit 'gnus-summary-exit-no-update)
7151 (defun gnus-summary-exit-no-update (&optional no-questions)
7152   "Quit reading current newsgroup without updating read article info."
7153   (interactive)
7154   (let* ((group gnus-newsgroup-name)
7155          (gnus-group-is-exiting-p t)
7156          (gnus-group-is-exiting-without-update-p t)
7157          (quit-config (gnus-group-quit-config group)))
7158     (when (or no-questions
7159               gnus-expert-user
7160               (gnus-y-or-n-p "Discard changes to this group and exit? "))
7161       (gnus-async-halt-prefetch)
7162       (run-hooks 'gnus-summary-prepare-exit-hook)
7163       (when (gnus-buffer-live-p gnus-article-buffer)
7164         (with-current-buffer gnus-article-buffer
7165           (mm-destroy-parts gnus-article-mime-handles)
7166           ;; Set it to nil for safety reason.
7167           (setq gnus-article-mime-handle-alist nil)
7168           (setq gnus-article-mime-handles nil)))
7169       ;; If we have several article buffers, we kill them at exit.
7170       (unless gnus-single-article-buffer
7171         (gnus-kill-buffer gnus-article-buffer)
7172         (gnus-kill-buffer gnus-original-article-buffer)
7173         (setq gnus-article-current nil))
7174       (if (not gnus-kill-summary-on-exit)
7175           (gnus-deaden-summary)
7176         (gnus-close-group group)
7177         (gnus-summary-clear-local-variables)
7178         (let ((gnus-summary-local-variables gnus-newsgroup-variables))
7179           (gnus-summary-clear-local-variables))
7180         (gnus-kill-buffer gnus-summary-buffer))
7181       (unless gnus-single-article-buffer
7182         (setq gnus-article-current nil))
7183       (when gnus-use-trees
7184         (gnus-tree-close group))
7185       (gnus-async-prefetch-remove-group group)
7186       (when (get-buffer gnus-article-buffer)
7187         (bury-buffer gnus-article-buffer))
7188       ;; Return to the group buffer.
7189       (gnus-configure-windows 'group 'force)
7190       ;; Clear the current group name.
7191       (setq gnus-newsgroup-name nil)
7192       (unless (gnus-ephemeral-group-p group)
7193         (gnus-group-update-group group))
7194       (when (equal (gnus-group-group-name) group)
7195         (gnus-group-next-unread-group 1))
7196       (when quit-config
7197         (gnus-handle-ephemeral-exit quit-config)))))
7198
7199 (defun gnus-handle-ephemeral-exit (quit-config)
7200   "Handle movement when leaving an ephemeral group.
7201 The state which existed when entering the ephemeral is reset."
7202   (if (not (buffer-name (car quit-config)))
7203       (gnus-configure-windows 'group 'force)
7204     (set-buffer (car quit-config))
7205     (cond ((eq major-mode 'gnus-summary-mode)
7206            (gnus-set-global-variables))
7207           ((eq major-mode 'gnus-article-mode)
7208            (save-current-buffer
7209              ;; The `gnus-summary-buffer' variable may point
7210              ;; to the old summary buffer when using a single
7211              ;; article buffer.
7212              (unless (gnus-buffer-live-p gnus-summary-buffer)
7213                (set-buffer gnus-group-buffer))
7214              (set-buffer gnus-summary-buffer)
7215              (gnus-set-global-variables))))
7216     (if (or (eq (cdr quit-config) 'article)
7217             (eq (cdr quit-config) 'pick))
7218         (if (and (boundp 'gnus-pick-mode) (symbol-value 'gnus-pick-mode))
7219             (gnus-configure-windows 'pick 'force)
7220           (gnus-configure-windows (cdr quit-config) 'force))
7221       (gnus-configure-windows (cdr quit-config) 'force))
7222     (when (eq major-mode 'gnus-summary-mode)
7223       (if (memq gnus-auto-select-on-ephemeral-exit '(next-noselect
7224                                                      next-unread-noselect))
7225           (when (zerop (cond ((eq gnus-auto-select-on-ephemeral-exit
7226                                   'next-noselect)
7227                               (gnus-summary-next-subject 1 nil t))
7228                              ((eq gnus-auto-select-on-ephemeral-exit
7229                                   'next-unread-noselect)
7230                               (gnus-summary-next-subject 1 t t))))
7231             ;; Hide the article buffer which displays the article different
7232             ;; from the one that the cursor points to in the summary buffer.
7233             (gnus-configure-windows 'summary 'force))
7234         (cond ((eq gnus-auto-select-on-ephemeral-exit 'next)
7235                (gnus-summary-next-subject 1))
7236               ((eq gnus-auto-select-on-ephemeral-exit 'next-unread)
7237                (gnus-summary-next-subject 1 t))))
7238       (gnus-summary-recenter)
7239       (gnus-summary-position-point))))
7240
7241 ;;; Dead summaries.
7242
7243 (defvar gnus-dead-summary-mode-map
7244   (let ((map (make-keymap)))
7245     (suppress-keymap map)
7246     (substitute-key-definition 'undefined 'gnus-summary-wake-up-the-dead map)
7247     (dolist (key '("\C-d" "\r" "\177" [delete]))
7248       (define-key map key 'gnus-summary-wake-up-the-dead))
7249     (dolist (key '("q" "Q"))
7250       (define-key map key 'bury-buffer))
7251     map))
7252
7253 (define-minor-mode gnus-dead-summary-mode
7254   "Minor mode for Gnus summary buffers."
7255   :lighter " Dead" :keymap gnus-dead-summary-mode-map
7256   (unless (derived-mode-p 'gnus-summary-mode)
7257     (setq gnus-dead-summary-mode nil)))
7258
7259 (defun gnus-deaden-summary ()
7260   "Make the current summary buffer into a dead summary buffer."
7261   ;; Kill any previous dead summary buffer.
7262   (when (and gnus-dead-summary
7263              (buffer-name gnus-dead-summary))
7264     (with-current-buffer gnus-dead-summary
7265       (when gnus-dead-summary-mode
7266         (kill-buffer (current-buffer)))))
7267   ;; Make this the current dead summary.
7268   (setq gnus-dead-summary (current-buffer))
7269   (gnus-dead-summary-mode 1)
7270   (let ((name (buffer-name)))
7271     (when (string-match "Summary" name)
7272       (rename-buffer
7273        (concat (substring name 0 (match-beginning 0)) "Dead "
7274                (substring name (match-beginning 0)))
7275        t)
7276       (bury-buffer))))
7277
7278 (defun gnus-kill-or-deaden-summary (buffer)
7279   "Kill or deaden the summary BUFFER."
7280   (save-excursion
7281     (when (and (buffer-name buffer)
7282                (not gnus-single-article-buffer))
7283       (with-current-buffer buffer
7284         (gnus-kill-buffer gnus-article-buffer)
7285         (gnus-kill-buffer gnus-original-article-buffer)))
7286     (cond
7287      ;; Kill the buffer.
7288      (gnus-kill-summary-on-exit
7289       (when (and gnus-use-trees
7290                  (gnus-buffer-exists-p buffer))
7291         (with-current-buffer buffer
7292           (gnus-tree-close gnus-newsgroup-name)))
7293       (gnus-kill-buffer buffer))
7294      ;; Deaden the buffer.
7295      ((gnus-buffer-exists-p buffer)
7296       (with-current-buffer buffer
7297         (gnus-deaden-summary))))))
7298
7299 (defun gnus-summary-wake-up-the-dead (&rest args)
7300   "Wake up the dead summary buffer."
7301   (interactive)
7302   (gnus-dead-summary-mode -1)
7303   (let ((name (buffer-name)))
7304     (when (string-match "Dead " name)
7305       (rename-buffer
7306        (concat (substring name 0 (match-beginning 0))
7307                (substring name (match-end 0)))
7308        t)))
7309   (gnus-message 3 "This dead summary is now alive again"))
7310
7311 ;; Suggested by Andrew Eskilsson <pi92ae@pt.hk-r.se>.
7312 (defun gnus-summary-fetch-faq (&optional faq-dir)
7313   "Fetch the FAQ for the current group.
7314 If FAQ-DIR (the prefix), prompt for a directory to search for the faq
7315 in."
7316   (interactive
7317    (list
7318     (when current-prefix-arg
7319       (completing-read
7320        "FAQ dir: " (and (listp gnus-group-faq-directory)
7321                         (mapcar 'list
7322                                 gnus-group-faq-directory))))))
7323   (let (gnus-faq-buffer)
7324     (when (setq gnus-faq-buffer
7325                 (gnus-group-fetch-faq gnus-newsgroup-name faq-dir))
7326       (gnus-configure-windows 'summary-faq))))
7327
7328 ;; Suggested by Per Abrahamsen <amanda@iesd.auc.dk>.
7329 (defun gnus-summary-describe-group (&optional force)
7330   "Describe the current newsgroup."
7331   (interactive "P")
7332   (gnus-group-describe-group force gnus-newsgroup-name))
7333
7334 (defun gnus-summary-describe-briefly ()
7335   "Describe summary mode commands briefly."
7336   (interactive)
7337   (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")))
7338
7339 ;; Walking around group mode buffer from summary mode.
7340
7341 (defun gnus-summary-next-group (&optional no-article target-group backward)
7342   "Exit current newsgroup and then select next unread newsgroup.
7343 If prefix argument NO-ARTICLE is non-nil, no article is selected
7344 initially.  If TARGET-GROUP, go to this group.  If BACKWARD, go to
7345 previous group instead."
7346   (interactive "P")
7347   ;; Stop pre-fetching.
7348   (gnus-async-halt-prefetch)
7349   (let ((current-group gnus-newsgroup-name)
7350         (current-buffer (current-buffer))
7351         entered)
7352     ;; First we semi-exit this group to update Xrefs and all variables.
7353     ;; We can't do a real exit, because the window conf must remain
7354     ;; the same in case the user is prompted for info, and we don't
7355     ;; want the window conf to change before that...
7356     (gnus-summary-exit t)
7357     (while (not entered)
7358       ;; Then we find what group we are supposed to enter.
7359       (set-buffer gnus-group-buffer)
7360       (gnus-group-jump-to-group current-group)
7361       (setq target-group
7362             (or target-group
7363                 (if (eq gnus-keep-same-level 'best)
7364                     (gnus-summary-best-group gnus-newsgroup-name)
7365                   (gnus-summary-search-group backward gnus-keep-same-level))))
7366       (if (not target-group)
7367           ;; There are no further groups, so we return to the group
7368           ;; buffer.
7369           (progn
7370             (gnus-message 5 "Returning to the group buffer")
7371             (setq entered t)
7372             (when (gnus-buffer-live-p current-buffer)
7373               (set-buffer current-buffer)
7374               (gnus-summary-exit))
7375             (gnus-run-hooks 'gnus-group-no-more-groups-hook))
7376         ;; We try to enter the target group.
7377         (gnus-group-jump-to-group target-group)
7378         (let ((unreads (gnus-group-group-unread)))
7379           (if (and (or (eq t unreads)
7380                        (and unreads (not (zerop unreads))))
7381                    (gnus-summary-read-group
7382                     target-group nil no-article
7383                     (and (buffer-name current-buffer) current-buffer)
7384                     nil backward))
7385               (setq entered t)
7386             (setq current-group target-group
7387                   target-group nil)))))))
7388
7389 (defun gnus-summary-prev-group (&optional no-article)
7390   "Exit current newsgroup and then select previous unread newsgroup.
7391 If prefix argument NO-ARTICLE is non-nil, no article is selected initially."
7392   (interactive "P")
7393   (gnus-summary-next-group no-article nil t))
7394
7395 ;; Walking around summary lines.
7396
7397 (defun gnus-summary-first-subject (&optional unread undownloaded unseen)
7398   "Go to the first subject satisfying any non-nil constraint.
7399 If UNREAD is non-nil, the article should be unread.
7400 If UNDOWNLOADED is non-nil, the article should be undownloaded.
7401 If UNSEEN is non-nil, the article should be unseen.
7402 Returns the article selected or nil if there are no matching articles."
7403   (interactive "P")
7404   (cond
7405    ;; Empty summary.
7406    ((null gnus-newsgroup-data)
7407     (gnus-message 3 "No articles in the group")
7408     nil)
7409    ;; Pick the first article.
7410    ((not (or unread undownloaded unseen))
7411     (goto-char (gnus-data-pos (car gnus-newsgroup-data)))
7412     (gnus-data-number (car gnus-newsgroup-data)))
7413    ;; Find the first unread article.
7414    (t
7415     (let ((data gnus-newsgroup-data))
7416       (while (and data
7417                   (let ((num (gnus-data-number (car data))))
7418                     (or (memq num gnus-newsgroup-unfetched)
7419                         (not (or (and unread
7420                                       (memq num gnus-newsgroup-unreads))
7421                                  (and undownloaded
7422                                       (memq num gnus-newsgroup-undownloaded))
7423                                  (and unseen
7424                                       (memq num gnus-newsgroup-unseen)))))))
7425         (setq data (cdr data)))
7426       (prog1
7427           (if data
7428               (progn
7429                 (goto-char (gnus-data-pos (car data)))
7430                 (gnus-data-number (car data)))
7431             (gnus-message 3 "No more%s articles"
7432                           (let* ((r (when unread " unread"))
7433                                  (d (when undownloaded " undownloaded"))
7434                                  (s (when unseen " unseen"))
7435                                  (l (delq nil (list r d s))))
7436                             (cond ((= 3 (length l))
7437                                    (concat r "," d ", or" s))
7438                                   ((= 2 (length l))
7439                                    (concat (car l) ", or" (cadr l)))
7440                                   ((= 1 (length l))
7441                                    (car l))
7442                                   (t
7443                                    ""))))
7444             nil
7445             )
7446         (gnus-summary-position-point))))))
7447
7448 (defun gnus-summary-next-subject (n &optional unread dont-display)
7449   "Go to next N'th summary line.
7450 If N is negative, go to the previous N'th subject line.
7451 If UNREAD is non-nil, only unread articles are selected.
7452 The difference between N and the actual number of steps taken is
7453 returned."
7454   (interactive "p")
7455   (let ((backward (< n 0))
7456         (n (abs n)))
7457     (while (and (> n 0)
7458                 (if backward
7459                     (gnus-summary-find-prev unread)
7460                   (gnus-summary-find-next unread)))
7461       (unless (zerop (setq n (1- n)))
7462         (gnus-summary-show-thread)))
7463     (when (/= 0 n)
7464       (gnus-message 7 "No more%s articles"
7465                     (if unread " unread" "")))
7466     (unless dont-display
7467       (gnus-summary-recenter)
7468       (gnus-summary-position-point))
7469     n))
7470
7471 (defun gnus-summary-next-unread-subject (n)
7472   "Go to next N'th unread summary line."
7473   (interactive "p")
7474   (gnus-summary-next-subject n t))
7475
7476 (defun gnus-summary-prev-subject (n &optional unread)
7477   "Go to previous N'th summary line.
7478 If optional argument UNREAD is non-nil, only unread article is selected."
7479   (interactive "p")
7480   (gnus-summary-next-subject (- n) unread))
7481
7482 (defun gnus-summary-prev-unread-subject (n)
7483   "Go to previous N'th unread summary line."
7484   (interactive "p")
7485   (gnus-summary-next-subject (- n) t))
7486
7487 (defun gnus-summary-goto-subjects (articles)
7488   "Insert the subject header for ARTICLES in the current buffer."
7489   (save-excursion
7490     (dolist (article articles)
7491       (gnus-summary-goto-subject article t)))
7492   (gnus-summary-limit (append articles gnus-newsgroup-limit))
7493   (gnus-summary-position-point))
7494
7495 (defun gnus-summary-goto-subject (article &optional force silent)
7496   "Go to the subject line of ARTICLE.
7497 If FORCE, also allow jumping to articles not currently shown."
7498   (interactive "nArticle number: ")
7499   (unless (numberp article)
7500     (error "Article %s is not a number" article))
7501   (let ((b (point))
7502         (data (gnus-data-find article)))
7503     ;; We read in the article if we have to.
7504     (and (not data)
7505          force
7506          (gnus-summary-insert-subject
7507           article
7508           (if (or (numberp force) (vectorp force)) force)
7509           t)
7510          (setq data (gnus-data-find article)))
7511     (goto-char b)
7512     (if (not data)
7513         (progn
7514           (unless silent
7515             (gnus-message 3 "Can't find article %d" article))
7516           nil)
7517       (let ((pt (gnus-data-pos data)))
7518         (goto-char pt)
7519         (gnus-summary-set-article-display-arrow pt))
7520       (gnus-summary-position-point)
7521       article)))
7522
7523 ;; Walking around summary lines with displaying articles.
7524
7525 (defun gnus-summary-expand-window (&optional arg)
7526   "Make the summary buffer take up the entire Emacs frame.
7527 Given a prefix, will force an `article' buffer configuration."
7528   (interactive "P")
7529   (if arg
7530       (gnus-configure-windows 'article 'force)
7531     (gnus-configure-windows 'summary 'force)))
7532
7533 (defun gnus-summary-display-article (article &optional all-header)
7534   "Display ARTICLE in article buffer."
7535   (unless (and (gnus-buffer-live-p gnus-article-buffer)
7536                (with-current-buffer gnus-article-buffer
7537                  (eq major-mode 'gnus-article-mode)))
7538     (gnus-article-setup-buffer))
7539   (gnus-set-global-variables)
7540   (with-current-buffer gnus-article-buffer
7541     (setq gnus-article-charset gnus-newsgroup-charset)
7542     (setq gnus-article-ignored-charsets gnus-newsgroup-ignored-charsets)
7543     (mm-enable-multibyte))
7544   (if (null article)
7545       nil
7546     (prog1
7547         (if gnus-summary-display-article-function
7548             (funcall gnus-summary-display-article-function article all-header)
7549           (gnus-article-prepare article all-header))
7550       (gnus-run-hooks 'gnus-select-article-hook)
7551       (when (and gnus-current-article
7552                  (not (zerop gnus-current-article)))
7553         (gnus-summary-goto-subject gnus-current-article))
7554       (gnus-summary-recenter)
7555       (when (and gnus-use-trees gnus-show-threads)
7556         (gnus-possibly-generate-tree article)
7557         (gnus-highlight-selected-tree article))
7558       ;; Successfully display article.
7559       (gnus-article-set-window-start
7560        (cdr (assq article gnus-newsgroup-bookmarks))))))
7561
7562 (defun gnus-summary-select-article (&optional all-headers force pseudo article)
7563   "Select the current article.
7564 If ALL-HEADERS is non-nil, show all header fields.  If FORCE is
7565 non-nil, the article will be re-fetched even if it already present in
7566 the article buffer.  If PSEUDO is non-nil, pseudo-articles will also
7567 be displayed."
7568   ;; Make sure we are in the summary buffer to work around bbdb bug.
7569   (unless (eq major-mode 'gnus-summary-mode)
7570     (set-buffer gnus-summary-buffer))
7571   (let ((article (or article (gnus-summary-article-number)))
7572         (all-headers (not (not all-headers))) ;Must be t or nil.
7573         gnus-summary-display-article-function)
7574     (and (not pseudo)
7575          (gnus-summary-article-pseudo-p article)
7576          (error "This is a pseudo-article"))
7577     (with-current-buffer gnus-summary-buffer
7578       (if (or (and gnus-single-article-buffer
7579                    (or (null gnus-current-article)
7580                        (null gnus-article-current)
7581                        (null (get-buffer gnus-article-buffer))
7582                        (not (eq article (cdr gnus-article-current)))
7583                        (not (equal (car gnus-article-current)
7584                                    gnus-newsgroup-name))))
7585               (and (not gnus-single-article-buffer)
7586                    (or (null gnus-current-article)
7587                        (not (eq gnus-current-article article))))
7588               force)
7589           ;; The requested article is different from the current article.
7590           (progn
7591             (gnus-summary-display-article article all-headers)
7592             (when (gnus-buffer-live-p gnus-article-buffer)
7593               (with-current-buffer gnus-article-buffer
7594                 (if (not gnus-article-decoded-p) ;; a local variable
7595                     (mm-disable-multibyte))))
7596             (gnus-article-set-window-start
7597              (cdr (assq article gnus-newsgroup-bookmarks)))
7598             article)
7599         'old))))
7600
7601 (defun gnus-summary-force-verify-and-decrypt ()
7602   "Display buttons for signed/encrypted parts and verify/decrypt them."
7603   (interactive)
7604   (let ((mm-verify-option 'known)
7605         (mm-decrypt-option 'known)
7606         (gnus-article-emulate-mime t)
7607         (gnus-buttonized-mime-types (append (list "multipart/signed"
7608                                                   "multipart/encrypted")
7609                                             gnus-buttonized-mime-types)))
7610     (gnus-summary-select-article nil 'force)))
7611
7612 (defun gnus-summary-set-current-mark (&optional current-mark)
7613   "Obsolete function."
7614   nil)
7615
7616 (defun gnus-summary-next-article (&optional unread subject backward push)
7617   "Select the next article.
7618 If UNREAD, only unread articles are selected.
7619 If SUBJECT, only articles with SUBJECT are selected.
7620 If BACKWARD, the previous article is selected instead of the next."
7621   (interactive "P")
7622   ;; Make sure we are in the summary buffer.
7623   (unless (eq major-mode 'gnus-summary-mode)
7624     (set-buffer gnus-summary-buffer))
7625   (cond
7626    ;; Is there such an article?
7627    ((and (gnus-summary-search-forward unread subject backward)
7628          (or (gnus-summary-display-article (gnus-summary-article-number))
7629              (eq (gnus-summary-article-mark) gnus-canceled-mark)))
7630     (gnus-summary-position-point))
7631    ;; If not, we try the first unread, if that is wanted.
7632    ((and subject
7633          gnus-auto-select-same
7634          (gnus-summary-first-unread-article))
7635     (gnus-summary-position-point)
7636     (gnus-message 6 "Wrapped"))
7637    ;; Try to get next/previous article not displayed in this group.
7638    ((and gnus-auto-extend-newsgroup
7639          (not unread) (not subject))
7640     (gnus-summary-goto-article
7641      (if backward (1- gnus-newsgroup-begin) (1+ gnus-newsgroup-end))
7642      nil (count-lines (point-min) (point))))
7643    ;; Go to next/previous group.
7644    (t
7645     (unless (gnus-ephemeral-group-p gnus-newsgroup-name)
7646       (gnus-summary-jump-to-group gnus-newsgroup-name))
7647     (let ((cmd (if (featurep 'xemacs)
7648                    last-command-char
7649                  last-command-event))
7650           (point
7651            (with-current-buffer gnus-group-buffer
7652              (point)))
7653           (group
7654            (if (eq gnus-keep-same-level 'best)
7655                (gnus-summary-best-group gnus-newsgroup-name)
7656              (gnus-summary-search-group backward gnus-keep-same-level))))
7657       ;; For some reason, the group window gets selected.  We change
7658       ;; it back.
7659       (select-window (get-buffer-window (current-buffer)))
7660       ;; Select next unread newsgroup automagically.
7661       (cond
7662        ((or (not gnus-auto-select-next)
7663             (not cmd))
7664         (gnus-message 7 "No more%s articles" (if unread " unread" "")))
7665        ((or (eq gnus-auto-select-next 'quietly)
7666             (and (eq gnus-auto-select-next 'slightly-quietly)
7667                  push)
7668             (and (eq gnus-auto-select-next 'almost-quietly)
7669                  (gnus-summary-last-article-p)))
7670         ;; Select quietly.
7671         (if (gnus-ephemeral-group-p gnus-newsgroup-name)
7672             (gnus-summary-exit)
7673           (gnus-message 7 "No more%s articles (%s)..."
7674                         (if unread " unread" "")
7675                         (if group (concat "selecting " group)
7676                           "exiting"))
7677           (gnus-summary-next-group nil group backward)))
7678        (t
7679         (when (gnus-key-press-event-p last-input-event)
7680           (gnus-summary-walk-group-buffer
7681            gnus-newsgroup-name cmd unread backward point))))))))
7682
7683 (defun gnus-summary-walk-group-buffer (from-group cmd unread backward start)
7684   (let ((keystrokes '((?\C-n (gnus-group-next-unread-group 1))
7685                       (?\C-p (gnus-group-prev-unread-group 1))))
7686         (cursor-in-echo-area t)
7687         keve key group ended prompt)
7688     (with-current-buffer gnus-group-buffer
7689       (goto-char start)
7690       (setq group
7691             (if (eq gnus-keep-same-level 'best)
7692                 (gnus-summary-best-group gnus-newsgroup-name)
7693               (gnus-summary-search-group backward gnus-keep-same-level))))
7694     (while (not ended)
7695       (setq prompt
7696             (format
7697              "No more%s articles%s " (if unread " unread" "")
7698              (if (and group
7699                       (not (gnus-ephemeral-group-p gnus-newsgroup-name)))
7700                  (format " (Type %s for %s [%s])"
7701                          (single-key-description cmd)
7702                          (gnus-group-decoded-name group)
7703                          (gnus-group-unread group))
7704                (format " (Type %s to exit %s)"
7705                        (single-key-description cmd)
7706                        (gnus-group-decoded-name gnus-newsgroup-name)))))
7707       ;; Confirm auto selection.
7708       (setq key (car (setq keve (gnus-read-event-char prompt)))
7709             ended t)
7710       (cond
7711        ((assq key keystrokes)
7712         (let ((obuf (current-buffer)))
7713           (switch-to-buffer gnus-group-buffer)
7714           (when group
7715             (gnus-group-jump-to-group group))
7716           (eval (cadr (assq key keystrokes)))
7717           (setq group (gnus-group-group-name))
7718           (switch-to-buffer obuf))
7719         (setq ended nil))
7720        ((equal key cmd)
7721         (if (or (not group)
7722                 (gnus-ephemeral-group-p gnus-newsgroup-name))
7723             (gnus-summary-exit)
7724           (gnus-summary-next-group nil group backward)))
7725        (t
7726         (push (cdr keve) unread-command-events))))))
7727
7728 (defun gnus-summary-next-unread-article ()
7729   "Select unread article after current one."
7730   (interactive)
7731   (gnus-summary-next-article
7732    (or (not (eq gnus-summary-goto-unread 'never))
7733        (gnus-summary-last-article-p (gnus-summary-article-number)))
7734    (and gnus-auto-select-same
7735         (gnus-summary-article-subject))))
7736
7737 (defun gnus-summary-prev-article (&optional unread subject)
7738   "Select the article before the current one.
7739 If UNREAD is non-nil, only unread articles are selected."
7740   (interactive "P")
7741   (gnus-summary-next-article unread subject t))
7742
7743 (defun gnus-summary-prev-unread-article ()
7744   "Select unread article before current one."
7745   (interactive)
7746   (gnus-summary-prev-article
7747    (or (not (eq gnus-summary-goto-unread 'never))
7748        (gnus-summary-first-article-p (gnus-summary-article-number)))
7749    (and gnus-auto-select-same
7750         (gnus-summary-article-subject))))
7751
7752 (defun gnus-summary-next-page (&optional lines circular stop)
7753   "Show next page of the selected article.
7754 If at the end of the current article, select the next article.
7755 LINES says how many lines should be scrolled up.
7756
7757 If CIRCULAR is non-nil, go to the start of the article instead of
7758 selecting the next article when reaching the end of the current
7759 article.
7760
7761 If STOP is non-nil, just stop when reaching the end of the message.
7762
7763 Also see the variable `gnus-article-skip-boring'."
7764   (interactive "P")
7765   (setq gnus-summary-buffer (current-buffer))
7766   (gnus-set-global-variables)
7767   (let ((article (gnus-summary-article-number))
7768         (article-window (get-buffer-window gnus-article-buffer t))
7769         endp)
7770     ;; If the buffer is empty, we have no article.
7771     (unless article
7772       (error "No article to select"))
7773     (gnus-configure-windows 'article)
7774     (if (eq (cdr (assq article gnus-newsgroup-reads)) gnus-canceled-mark)
7775         (if (and (eq gnus-summary-goto-unread 'never)
7776                  (not (gnus-summary-last-article-p article)))
7777             (gnus-summary-next-article)
7778           (gnus-summary-next-unread-article))
7779       (if (or (null gnus-current-article)
7780               (null gnus-article-current)
7781               (/= article (cdr gnus-article-current))
7782               (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7783           ;; Selected subject is different from current article's.
7784           (gnus-summary-display-article article)
7785         (when article-window
7786           (gnus-eval-in-buffer-window gnus-article-buffer
7787             (setq endp (or (gnus-article-next-page lines)
7788                            (gnus-article-only-boring-p))))
7789           (when endp
7790             (cond (stop
7791                    (gnus-message 3 "End of message"))
7792                   (circular
7793                    (gnus-summary-beginning-of-article))
7794                   (lines
7795                    (gnus-message 3 "End of message"))
7796                   ((null lines)
7797                    (if (and (eq gnus-summary-goto-unread 'never)
7798                             (not (gnus-summary-last-article-p article)))
7799                        (gnus-summary-next-article)
7800                      (gnus-summary-next-unread-article))))))))
7801     (gnus-summary-recenter)
7802     (gnus-summary-position-point)))
7803
7804 (defun gnus-summary-prev-page (&optional lines move)
7805   "Show previous page of selected article.
7806 Argument LINES specifies lines to be scrolled down.
7807 If MOVE, move to the previous unread article if point is at
7808 the beginning of the buffer."
7809   (interactive "P")
7810   (let ((article (gnus-summary-article-number))
7811         (article-window (get-buffer-window gnus-article-buffer t))
7812         endp)
7813     (gnus-configure-windows 'article)
7814     (if (or (null gnus-current-article)
7815             (null gnus-article-current)
7816             (/= article (cdr gnus-article-current))
7817             (not (equal (car gnus-article-current) gnus-newsgroup-name)))
7818         ;; Selected subject is different from current article's.
7819         (gnus-summary-display-article article)
7820       (gnus-summary-recenter)
7821       (when article-window
7822         (gnus-eval-in-buffer-window gnus-article-buffer
7823           (setq endp (gnus-article-prev-page lines)))
7824         (when (and move endp)
7825           (cond (lines
7826                  (gnus-message 3 "Beginning of message"))
7827                 ((null lines)
7828                  (if (and (eq gnus-summary-goto-unread 'never)
7829                           (not (gnus-summary-first-article-p article)))
7830                      (gnus-summary-prev-article)
7831                    (gnus-summary-prev-unread-article))))))))
7832   (gnus-summary-position-point))
7833
7834 (defun gnus-summary-prev-page-or-article (&optional lines)
7835   "Show previous page of selected article.
7836 Argument LINES specifies lines to be scrolled down.
7837 If at the beginning of the article, go to the next article."
7838   (interactive "P")
7839   (gnus-summary-prev-page lines t))
7840
7841 (defun gnus-summary-scroll-up (lines)
7842   "Scroll up (or down) one line current article.
7843 Argument LINES specifies lines to be scrolled up (or down if negative)."
7844   (interactive "p")
7845   (gnus-configure-windows 'article)
7846   (gnus-summary-show-thread)
7847   (when (eq (gnus-summary-select-article nil nil 'pseudo) 'old)
7848     (gnus-eval-in-buffer-window gnus-article-buffer
7849       (cond ((> lines 0)
7850              (when (gnus-article-next-page lines)
7851                (gnus-message 3 "End of message")))
7852             ((< lines 0)
7853              (gnus-article-prev-page (- lines))))))
7854   (gnus-summary-recenter)
7855   (gnus-summary-position-point))
7856
7857 (defun gnus-summary-scroll-down (lines)
7858   "Scroll down (or up) one line current article.
7859 Argument LINES specifies lines to be scrolled down (or up if negative)."
7860   (interactive "p")
7861   (gnus-summary-scroll-up (- lines)))
7862
7863 (defun gnus-summary-next-same-subject ()
7864   "Select next article which has the same subject as current one."
7865   (interactive)
7866   (gnus-summary-next-article nil (gnus-summary-article-subject)))
7867
7868 (defun gnus-summary-prev-same-subject ()
7869   "Select previous article which has the same subject as current one."
7870   (interactive)
7871   (gnus-summary-prev-article nil (gnus-summary-article-subject)))
7872
7873 (defun gnus-summary-next-unread-same-subject ()
7874   "Select next unread article which has the same subject as current one."
7875   (interactive)
7876   (gnus-summary-next-article t (gnus-summary-article-subject)))
7877
7878 (defun gnus-summary-prev-unread-same-subject ()
7879   "Select previous unread article which has the same subject as current one."
7880   (interactive)
7881   (gnus-summary-prev-article t (gnus-summary-article-subject)))
7882
7883 (defun gnus-summary-first-unread-article ()
7884   "Select the first unread article.
7885 Return nil if there are no unread articles."
7886   (interactive)
7887   (prog1
7888       (when (gnus-summary-first-subject t)
7889         (gnus-summary-show-thread)
7890         (gnus-summary-first-subject t)
7891         (gnus-summary-display-article (gnus-summary-article-number)))
7892     (gnus-summary-position-point)))
7893
7894 (defun gnus-summary-first-unread-subject ()
7895   "Place the point on the subject line of the first unread article.
7896 Return nil if there are no unread articles."
7897   (interactive)
7898   (prog1
7899       (when (gnus-summary-first-subject t)
7900         (gnus-summary-show-thread)
7901         (gnus-summary-first-subject t))
7902     (gnus-summary-position-point)))
7903
7904 (defun gnus-summary-first-unseen-subject ()
7905   "Place the point on the subject line of the first unseen article.
7906 Return nil if there are no unseen articles."
7907   (interactive)
7908   (prog1
7909       (when (gnus-summary-first-subject nil nil t)
7910         (gnus-summary-show-thread)
7911         (gnus-summary-first-subject nil nil t))
7912     (gnus-summary-position-point)))
7913
7914 (defun gnus-summary-first-unseen-or-unread-subject ()
7915   "Place the point on the subject line of the first unseen article or,
7916 if all article have been seen, on the subject line of the first unread
7917 article."
7918   (interactive)
7919   (prog1
7920       (unless (when (gnus-summary-first-subject nil nil t)
7921                 (gnus-summary-show-thread)
7922                 (gnus-summary-first-subject nil nil t))
7923         (when (gnus-summary-first-subject t)
7924           (gnus-summary-show-thread)
7925           (gnus-summary-first-subject t)))
7926     (gnus-summary-position-point)))
7927
7928 (defun gnus-summary-first-article ()
7929   "Select the first article.
7930 Return nil if there are no articles."
7931   (interactive)
7932   (prog1
7933       (when (gnus-summary-first-subject)
7934         (gnus-summary-show-thread)
7935         (gnus-summary-first-subject)
7936         (gnus-summary-display-article (gnus-summary-article-number)))
7937     (gnus-summary-position-point)))
7938
7939 (defun gnus-summary-best-unread-article (&optional arg)
7940   "Select the unread article with the highest score.
7941 If given a prefix argument, select the next unread article that has a
7942 score higher than the default score."
7943   (interactive "P")
7944   (let ((article (if arg
7945                      (gnus-summary-better-unread-subject)
7946                    (gnus-summary-best-unread-subject))))
7947     (if article
7948         (gnus-summary-goto-article article)
7949       (error "No unread articles"))))
7950
7951 (defun gnus-summary-best-unread-subject ()
7952   "Select the unread subject with the highest score."
7953   (interactive)
7954   (let ((best -1000000)
7955         (data gnus-newsgroup-data)
7956         article score)
7957     (while data
7958       (and (gnus-data-unread-p (car data))
7959            (> (setq score
7960                     (gnus-summary-article-score (gnus-data-number (car data))))
7961               best)
7962            (setq best score
7963                  article (gnus-data-number (car data))))
7964       (setq data (cdr data)))
7965     (when article
7966       (gnus-summary-goto-subject article))
7967     (gnus-summary-position-point)
7968     article))
7969
7970 (defun gnus-summary-better-unread-subject ()
7971   "Select the first unread subject that has a score over the default score."
7972   (interactive)
7973   (let ((data gnus-newsgroup-data)
7974         article score)
7975     (while (and (setq article (gnus-data-number (car data)))
7976                 (or (gnus-data-read-p (car data))
7977                     (not (> (gnus-summary-article-score article)
7978                             gnus-summary-default-score))))
7979       (setq data (cdr data)))
7980     (when article
7981       (gnus-summary-goto-subject article))
7982     (gnus-summary-position-point)
7983     article))
7984
7985 (defun gnus-summary-last-subject ()
7986   "Go to the last displayed subject line in the group."
7987   (let ((article (gnus-data-number (car (gnus-data-list t)))))
7988     (when article
7989       (gnus-summary-goto-subject article))))
7990
7991 (defun gnus-summary-goto-article (article &optional all-headers force)
7992   "Fetch ARTICLE (article number or Message-ID) and display it if it exists.
7993 If ALL-HEADERS is non-nil, no header lines are hidden.
7994 If FORCE, go to the article even if it isn't displayed.  If FORCE
7995 is a number, it is the line the article is to be displayed on."
7996   (interactive
7997    (list
7998     (completing-read
7999      "Article number or Message-ID: "
8000      (mapcar (lambda (number) (list (int-to-string number)))
8001              gnus-newsgroup-limit))
8002     current-prefix-arg
8003     t))
8004   (prog1
8005       (if (and (stringp article)
8006                (string-match "@\\|%40" article))
8007           (gnus-summary-refer-article article)
8008         (when (stringp article)
8009           (setq article (string-to-number article)))
8010         (if (gnus-summary-goto-subject article force)
8011             (gnus-summary-display-article article all-headers)
8012           (gnus-message 4 "Couldn't go to article %s" article) nil))
8013     (gnus-summary-position-point)))
8014
8015 (defun gnus-summary-goto-last-article ()
8016   "Go to the previously read article."
8017   (interactive)
8018   (prog1
8019       (when gnus-last-article
8020         (gnus-summary-goto-article gnus-last-article nil t))
8021     (gnus-summary-position-point)))
8022
8023 (defun gnus-summary-pop-article (number)
8024   "Pop one article off the history and go to the previous.
8025 NUMBER articles will be popped off."
8026   (interactive "p")
8027   (let (to)
8028     (setq gnus-newsgroup-history
8029           (cdr (setq to (nthcdr number gnus-newsgroup-history))))
8030     (if to
8031         (gnus-summary-goto-article (car to) nil t)
8032       (error "Article history empty")))
8033   (gnus-summary-position-point))
8034
8035 ;; Summary commands and functions for limiting the summary buffer.
8036
8037 (defun gnus-summary-limit-to-articles (n)
8038   "Limit the summary buffer to the next N articles.
8039 If not given a prefix, use the process marked articles instead."
8040   (interactive "P")
8041   (prog1
8042       (let ((articles (gnus-summary-work-articles n)))
8043         (setq gnus-newsgroup-processable nil)
8044         (gnus-summary-limit articles))
8045     (gnus-summary-position-point)))
8046
8047 (defun gnus-summary-pop-limit (&optional total)
8048   "Restore the previous limit.
8049 If given a prefix, remove all limits."
8050   (interactive "P")
8051   (when total
8052     (setq gnus-newsgroup-limits
8053           (list (mapcar (lambda (h) (mail-header-number h))
8054                         gnus-newsgroup-headers))))
8055   (unless gnus-newsgroup-limits
8056     (error "No limit to pop"))
8057   (prog1
8058       (gnus-summary-limit nil 'pop)
8059     (gnus-summary-position-point)))
8060
8061 (defun gnus-summary-limit-to-subject (subject &optional header not-matching)
8062   "Limit the summary buffer to articles that have subjects that match a regexp.
8063 If NOT-MATCHING, excluding articles that have subjects that match a regexp."
8064   (interactive
8065    (list (read-string (if current-prefix-arg
8066                           "Exclude subject (regexp): "
8067                         "Limit to subject (regexp): "))
8068          nil current-prefix-arg))
8069   (unless header
8070     (setq header "subject"))
8071   (when (not (equal "" subject))
8072     (prog1
8073         (let ((articles (gnus-summary-find-matching
8074                          (or header "subject") subject 'all nil nil
8075                          not-matching)))
8076           (unless articles
8077             (error "Found no matches for \"%s\"" subject))
8078           (gnus-summary-limit articles))
8079       (gnus-summary-position-point))))
8080
8081 (defun gnus-summary-limit-to-author (from &optional not-matching)
8082   "Limit the summary buffer to articles that have authors that match a regexp.
8083 If NOT-MATCHING, excluding articles that have authors that match a regexp."
8084   (interactive
8085    (list (read-string (if current-prefix-arg
8086                           "Exclude author (regexp): "
8087                         "Limit to author (regexp): "))
8088          current-prefix-arg))
8089   (gnus-summary-limit-to-subject from "from" not-matching))
8090
8091 (defun gnus-summary-limit-to-recipient (recipient &optional not-matching)
8092   "Limit the summary buffer to articles with the given RECIPIENT.
8093
8094 If NOT-MATCHING, exclude RECIPIENT.
8095
8096 To and Cc headers are checked.  You need to include them in
8097 `nnmail-extra-headers'."
8098   ;; Unlike `rmail-summary-by-recipients', doesn't include From.
8099   (interactive
8100    (list (read-string (format "%s recipient (regexp): "
8101                               (if current-prefix-arg "Exclude" "Limit to")))
8102          current-prefix-arg))
8103   (when (not (equal "" recipient))
8104     (prog1 (let* ((to
8105                    (if (memq 'To nnmail-extra-headers)
8106                        (gnus-summary-find-matching
8107                         (cons 'extra 'To) recipient 'all nil nil
8108                         not-matching)
8109                      (gnus-message
8110                       1 "`To' isn't present in `nnmail-extra-headers'")
8111                      (sit-for 1)
8112                      nil))
8113                   (cc
8114                    (if (memq 'Cc nnmail-extra-headers)
8115                        (gnus-summary-find-matching
8116                         (cons 'extra 'Cc) recipient 'all nil nil
8117                         not-matching)
8118                      (gnus-message
8119                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8120                      (sit-for 1)
8121                      nil))
8122                   (articles
8123                    (if not-matching
8124                        ;; We need the numbers that are in both lists:
8125                        (mapcar (lambda (a)
8126                                  (and (memq a to) a))
8127                                cc)
8128                      (nconc to cc))))
8129              (unless articles
8130                (error "Found no matches for \"%s\"" recipient))
8131              (gnus-summary-limit articles))
8132       (gnus-summary-position-point))))
8133
8134 (defun gnus-summary-limit-to-address (address &optional not-matching)
8135   "Limit the summary buffer to articles with the given ADDRESS.
8136
8137 If NOT-MATCHING, exclude ADDRESS.
8138
8139 To, Cc and From headers are checked.  You need to include `To' and `Cc'
8140 in `nnmail-extra-headers'."
8141   (interactive
8142    (list (read-string (format "%s address (regexp): "
8143                               (if current-prefix-arg "Exclude" "Limit to")))
8144          current-prefix-arg))
8145   (when (not (equal "" address))
8146     (prog1 (let* ((to
8147                    (if (memq 'To nnmail-extra-headers)
8148                        (gnus-summary-find-matching
8149                         (cons 'extra 'To) address 'all nil nil
8150                         not-matching)
8151                      (gnus-message
8152                       1 "`To' isn't present in `nnmail-extra-headers'")
8153                      (sit-for 1)
8154                      t))
8155                   (cc
8156                    (if (memq 'Cc nnmail-extra-headers)
8157                        (gnus-summary-find-matching
8158                         (cons 'extra 'Cc) address 'all nil nil
8159                         not-matching)
8160                      (gnus-message
8161                       1 "`Cc' isn't present in `nnmail-extra-headers'")
8162                      (sit-for 1)
8163                      t))
8164                   (from
8165                    (gnus-summary-find-matching "from" address
8166                                                'all nil nil not-matching))
8167                   (articles
8168                    (if not-matching
8169                        ;; We need the numbers that are in all lists:
8170                        (if (eq cc t)
8171                            (if (eq to t)
8172                                from
8173                              (mapcar (lambda (a) (car (memq a from))) to))
8174                          (if (eq to t)
8175                              (mapcar (lambda (a) (car (memq a from))) cc)
8176                            (mapcar (lambda (a) (car (memq a from)))
8177                                    (mapcar (lambda (a) (car (memq a to)))
8178                                            cc))))
8179                      (nconc (if (eq to t) nil to)
8180                             (if (eq cc t) nil cc)
8181                             from))))
8182              (unless articles
8183                (error "Found no matches for \"%s\"" address))
8184              (gnus-summary-limit articles))
8185       (gnus-summary-position-point))))
8186
8187 (defun gnus-summary-limit-strange-charsets-predicate (header)
8188   (when (fboundp 'char-charset)
8189     (let ((string (concat (mail-header-subject header)
8190                           (mail-header-from header)))
8191           charset found)
8192       (dotimes (i (1- (length string)))
8193         (setq charset (format "%s" (char-charset (aref string (1+ i)))))
8194         (when (string-match "unicode\\|big\\|japanese" charset)
8195           (setq found t)))
8196       found)))
8197
8198 (defun gnus-summary-limit-to-predicate (predicate)
8199   "Limit to articles where PREDICATE returns non-nil.
8200 PREDICATE will be called with the header structures of the
8201 articles."
8202   (let ((articles nil)
8203         (case-fold-search t))
8204     (dolist (header gnus-newsgroup-headers)
8205       (when (funcall predicate header)
8206         (push (mail-header-number header) articles)))
8207     (gnus-summary-limit (nreverse articles))))
8208
8209 (defun gnus-summary-limit-to-age (age &optional younger-p)
8210   "Limit the summary buffer to articles that are older than (or equal) AGE days.
8211 If YOUNGER-P (the prefix) is non-nil, limit the summary buffer to
8212 articles that are younger than AGE days."
8213   (interactive
8214    (let ((younger current-prefix-arg)
8215          (days-got nil)
8216          days)
8217      (while (not days-got)
8218        (setq days (if younger
8219                       (read-string "Limit to articles younger than (in days, older when negative): ")
8220                     (read-string
8221                      "Limit to articles older than (in days, younger when negative): ")))
8222        (when (> (length days) 0)
8223          (setq days (read days)))
8224        (if (numberp days)
8225            (progn
8226              (setq days-got t)
8227              (when (< days 0)
8228                (setq younger (not younger))
8229                (setq days (* days -1))))
8230          (message "Please enter a number.")
8231          (sleep-for 1)))
8232      (list days younger)))
8233   (prog1
8234       (let ((data gnus-newsgroup-data)
8235             (cutoff (days-to-time age))
8236             articles d date is-younger)
8237         (while (setq d (pop data))
8238           (when (and (vectorp (gnus-data-header d))
8239                      (setq date (mail-header-date (gnus-data-header d))))
8240             (setq is-younger (time-less-p
8241                               (time-since (condition-case ()
8242                                               (date-to-time date)
8243                                             (error '(0 0))))
8244                               cutoff))
8245             (when (if younger-p
8246                       is-younger
8247                     (not is-younger))
8248               (push (gnus-data-number d) articles))))
8249         (gnus-summary-limit (nreverse articles)))
8250     (gnus-summary-position-point)))
8251
8252 (defun gnus-summary-limit-to-extra (header regexp &optional not-matching)
8253   "Limit the summary buffer to articles that match an 'extra' header."
8254   (interactive
8255    (let ((header
8256           (intern
8257            (gnus-completing-read-with-default
8258             (symbol-name (car gnus-extra-headers))
8259             (if current-prefix-arg
8260                 "Exclude extra header"
8261               "Limit extra header")
8262             (mapcar (lambda (x)
8263                       (cons (symbol-name x) x))
8264                     gnus-extra-headers)
8265             nil
8266             t))))
8267      (list header
8268            (read-string (format "%s header %s (regexp): "
8269                                 (if current-prefix-arg "Exclude" "Limit to")
8270                                 header))
8271            current-prefix-arg)))
8272   (when (not (equal "" regexp))
8273     (prog1
8274         (let ((articles (gnus-summary-find-matching
8275                          (cons 'extra header) regexp 'all nil nil
8276                          not-matching)))
8277           (unless articles
8278             (error "Found no matches for \"%s\"" regexp))
8279           (gnus-summary-limit articles))
8280       (gnus-summary-position-point))))
8281
8282 (defun gnus-summary-limit-to-display-predicate ()
8283   "Limit the summary buffer to the predicated in the `display' group parameter."
8284   (interactive)
8285   (unless gnus-newsgroup-display
8286     (error "There is no `display' group parameter"))
8287   (let (articles)
8288     (dolist (number gnus-newsgroup-articles)
8289       (when (funcall gnus-newsgroup-display)
8290         (push number articles)))
8291     (gnus-summary-limit articles))
8292   (gnus-summary-position-point))
8293
8294 (defalias 'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread)
8295 (make-obsolete
8296  'gnus-summary-delete-marked-as-read 'gnus-summary-limit-to-unread "Emacs 20.4")
8297
8298 (defun gnus-summary-limit-to-unread (&optional all)
8299   "Limit the summary buffer to articles that are not marked as read.
8300 If ALL is non-nil, limit strictly to unread articles."
8301   (interactive "P")
8302   (if all
8303       (gnus-summary-limit-to-marks (char-to-string gnus-unread-mark))
8304     (gnus-summary-limit-to-marks
8305      ;; Concat all the marks that say that an article is read and have
8306      ;; those removed.
8307      (list gnus-del-mark gnus-read-mark gnus-ancient-mark
8308            gnus-killed-mark gnus-spam-mark gnus-kill-file-mark
8309            gnus-low-score-mark gnus-expirable-mark
8310            gnus-canceled-mark gnus-catchup-mark gnus-sparse-mark
8311            gnus-duplicate-mark gnus-souped-mark)
8312      'reverse)))
8313
8314 (defun gnus-summary-limit-to-headers (match &optional reverse)
8315   "Limit the summary buffer to articles that have headers that match MATCH.
8316 If REVERSE (the prefix), limit to articles that don't match."
8317   (interactive "sMatch headers (regexp): \nP")
8318   (gnus-summary-limit-to-bodies match reverse t))
8319
8320 (defun gnus-summary-limit-to-bodies (match &optional reverse headersp)
8321   "Limit the summary buffer to articles that have bodies that match MATCH.
8322 If REVERSE (the prefix), limit to articles that don't match."
8323   (interactive "sMatch body (regexp): \nP")
8324   (let ((articles nil)
8325         (gnus-select-article-hook nil)  ;Disable hook.
8326         (gnus-article-prepare-hook nil)
8327         (gnus-use-article-prefetch nil)
8328         (gnus-keep-backlog nil)
8329         (gnus-break-pages nil)
8330         (gnus-summary-display-arrow nil)
8331         (gnus-updated-mode-lines nil)
8332         (gnus-auto-center-summary nil)
8333         (gnus-display-mime-function nil))
8334     (dolist (data gnus-newsgroup-data)
8335       (let (gnus-mark-article-hook)
8336         (gnus-summary-select-article t t nil (gnus-data-number data)))
8337       (with-current-buffer gnus-article-buffer
8338         (article-goto-body)
8339         (let* ((case-fold-search t)
8340                (found (if headersp
8341                           (re-search-backward match nil t)
8342                         (re-search-forward match nil t))))
8343           (when (or (and found
8344                          (not reverse))
8345                     (and (not found)
8346                          reverse))
8347             (push (gnus-data-number data) articles)))))
8348     (if (not articles)
8349         (message "No messages matched")
8350       (gnus-summary-limit articles)))
8351   (gnus-summary-position-point))
8352
8353 (defun gnus-summary-limit-to-singletons (&optional threadsp)
8354   "Limit the summary buffer to articles that aren't part on any thread.
8355 If THREADSP (the prefix), limit to articles that are in threads."
8356   (interactive "P")
8357   (let ((articles nil)
8358         thread-articles
8359         threads)
8360     (dolist (thread gnus-newsgroup-threads)
8361       (if (stringp (car thread))
8362           (dolist (thread (cdr thread))
8363             (push thread threads))
8364         (push thread threads)))
8365     (dolist (thread threads)
8366       (setq thread-articles (gnus-articles-in-thread thread))
8367       (when (or (and threadsp
8368                      (> (length thread-articles) 1))
8369                 (and (not threadsp)
8370                      (= (length thread-articles) 1)))
8371         (setq articles (nconc thread-articles articles))))
8372     (if (not articles)
8373         (message "No messages matched")
8374       (gnus-summary-limit articles))
8375     (gnus-summary-position-point)))
8376
8377 (defun gnus-summary-limit-to-replied (&optional unreplied)
8378   "Limit the summary buffer to replied articles.
8379 If UNREPLIED (the prefix), limit to unreplied articles."
8380   (interactive "P")
8381   (if unreplied
8382       (gnus-summary-limit
8383        (gnus-set-difference gnus-newsgroup-articles
8384         gnus-newsgroup-replied))
8385     (gnus-summary-limit gnus-newsgroup-replied))
8386   (gnus-summary-position-point))
8387
8388 (defalias 'gnus-summary-delete-marked-with 'gnus-summary-limit-exclude-marks)
8389 (make-obsolete 'gnus-summary-delete-marked-with
8390                'gnus-summary-limit-exclude-marks "Emacs 20.4")
8391
8392 (defun gnus-summary-limit-exclude-marks (marks &optional reverse)
8393   "Exclude articles that are marked with MARKS (e.g. \"DK\").
8394 If REVERSE, limit the summary buffer to articles that are marked
8395 with MARKS.  MARKS can either be a string of marks or a list of marks.
8396 Returns how many articles were removed."
8397   (interactive "sMarks: ")
8398   (gnus-summary-limit-to-marks marks t))
8399
8400 (defun gnus-summary-limit-to-marks (marks &optional reverse)
8401   "Limit the summary buffer to articles that are marked with MARKS (e.g. \"DK\").
8402 If REVERSE (the prefix), limit the summary buffer to articles that are
8403 not marked with MARKS.  MARKS can either be a string of marks or a
8404 list of marks.
8405 Returns how many articles were removed."
8406   (interactive "sMarks: \nP")
8407   (prog1
8408       (let ((data gnus-newsgroup-data)
8409             (marks (if (listp marks) marks
8410                      (append marks nil))) ; Transform to list.
8411             articles)
8412         (while data
8413           (when (if reverse (not (memq (gnus-data-mark (car data)) marks))
8414                   (memq (gnus-data-mark (car data)) marks))
8415             (push (gnus-data-number (car data)) articles))
8416           (setq data (cdr data)))
8417         (gnus-summary-limit articles))
8418     (gnus-summary-position-point)))
8419
8420 (defun gnus-summary-limit-to-score (score)
8421   "Limit to articles with score at or above SCORE."
8422   (interactive "NLimit to articles with score of at least: ")
8423   (let ((data gnus-newsgroup-data)
8424         articles)
8425     (while data
8426       (when (>= (gnus-summary-article-score (gnus-data-number (car data)))
8427                 score)
8428         (push (gnus-data-number (car data)) articles))
8429       (setq data (cdr data)))
8430     (prog1
8431         (gnus-summary-limit articles)
8432       (gnus-summary-position-point))))
8433
8434 (defun gnus-summary-limit-to-unseen ()
8435   "Limit to unseen articles."
8436   (interactive)
8437   (prog1
8438       (gnus-summary-limit gnus-newsgroup-unseen)
8439     (gnus-summary-position-point)))
8440
8441 (defun gnus-summary-limit-include-thread (id)
8442   "Display all the hidden articles that is in the thread with ID in it.
8443 When called interactively, ID is the Message-ID of the current
8444 article."
8445   (interactive (list (mail-header-id (gnus-summary-article-header))))
8446   (let ((articles (gnus-articles-in-thread
8447                    (gnus-id-to-thread (gnus-root-id id)))))
8448     (prog1
8449         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8450       (gnus-summary-limit-include-matching-articles
8451        "subject"
8452        (regexp-quote (gnus-simplify-subject-re
8453                       (mail-header-subject (gnus-id-to-header id)))))
8454       (gnus-summary-position-point))))
8455
8456 (defun gnus-summary-limit-include-matching-articles (header regexp)
8457   "Display all the hidden articles that have HEADERs that match REGEXP."
8458   (interactive (list (read-string "Match on header: ")
8459                      (read-string "Regexp: ")))
8460   (let ((articles (gnus-find-matching-articles header regexp)))
8461     (prog1
8462         (gnus-summary-limit (nconc articles gnus-newsgroup-limit))
8463       (gnus-summary-position-point))))
8464
8465 (defun gnus-summary-insert-dormant-articles ()
8466   "Insert all the dormant articles for this group into the current buffer."
8467   (interactive)
8468   (let ((gnus-verbose (max 6 gnus-verbose)))
8469     (if (not gnus-newsgroup-dormant)
8470         (gnus-message 3 "No dormant articles for this group")
8471       (gnus-summary-goto-subjects gnus-newsgroup-dormant))))
8472
8473 (defun gnus-summary-insert-ticked-articles ()
8474   "Insert ticked articles for this group into the current buffer."
8475   (interactive)
8476   (let ((gnus-verbose (max 6 gnus-verbose)))
8477     (if (not gnus-newsgroup-marked)
8478         (gnus-message 3 "No ticked articles for this group")
8479       (gnus-summary-goto-subjects gnus-newsgroup-marked))))
8480
8481 (defun gnus-summary-limit-include-dormant ()
8482   "Display all the hidden articles that are marked as dormant.
8483 Note that this command only works on a subset of the articles currently
8484 fetched for this group."
8485   (interactive)
8486   (unless gnus-newsgroup-dormant
8487     (error "There are no dormant articles in this group"))
8488   (prog1
8489       (gnus-summary-limit (append gnus-newsgroup-dormant gnus-newsgroup-limit))
8490     (gnus-summary-position-point)))
8491
8492 (defun gnus-summary-limit-exclude-dormant ()
8493   "Hide all dormant articles."
8494   (interactive)
8495   (prog1
8496       (gnus-summary-limit-to-marks (list gnus-dormant-mark) 'reverse)
8497     (gnus-summary-position-point)))
8498
8499 (defun gnus-summary-limit-exclude-childless-dormant ()
8500   "Hide all dormant articles that have no children."
8501   (interactive)
8502   (let ((data (gnus-data-list t))
8503         articles d children)
8504     ;; Find all articles that are either not dormant or have
8505     ;; children.
8506     (while (setq d (pop data))
8507       (when (or (not (= (gnus-data-mark d) gnus-dormant-mark))
8508                 (and (setq children
8509                            (gnus-article-children (gnus-data-number d)))
8510                      (let (found)
8511                        (while children
8512                          (when (memq (car children) articles)
8513                            (setq children nil
8514                                  found t))
8515                          (pop children))
8516                        found)))
8517         (push (gnus-data-number d) articles)))
8518     ;; Do the limiting.
8519     (prog1
8520         (gnus-summary-limit articles)
8521       (gnus-summary-position-point))))
8522
8523 (defun gnus-summary-limit-mark-excluded-as-read (&optional all)
8524   "Mark all unread excluded articles as read.
8525 If ALL, mark even excluded ticked and dormants as read."
8526   (interactive "P")
8527   (setq gnus-newsgroup-limit (sort gnus-newsgroup-limit '<))
8528   (let ((articles (gnus-sorted-ndifference
8529                    (sort
8530                     (mapcar (lambda (h) (mail-header-number h))
8531                             gnus-newsgroup-headers)
8532                     '<)
8533                    gnus-newsgroup-limit))
8534         article)
8535     (setq gnus-newsgroup-unreads
8536           (gnus-sorted-intersection gnus-newsgroup-unreads
8537                                     gnus-newsgroup-limit))
8538     (if all
8539         (setq gnus-newsgroup-dormant nil
8540               gnus-newsgroup-marked nil
8541               gnus-newsgroup-reads
8542               (nconc
8543                (mapcar (lambda (n) (cons n gnus-catchup-mark)) articles)
8544                gnus-newsgroup-reads))
8545       (while (setq article (pop articles))
8546         (unless (or (memq article gnus-newsgroup-dormant)
8547                     (memq article gnus-newsgroup-marked))
8548           (push (cons article gnus-catchup-mark) gnus-newsgroup-reads))))))
8549
8550 (defun gnus-summary-limit (articles &optional pop)
8551   (if pop
8552       ;; We pop the previous limit off the stack and use that.
8553       (setq articles (car gnus-newsgroup-limits)
8554             gnus-newsgroup-limits (cdr gnus-newsgroup-limits))
8555     ;; We use the new limit, so we push the old limit on the stack.
8556     (push gnus-newsgroup-limit gnus-newsgroup-limits))
8557   ;; Set the limit.
8558   (setq gnus-newsgroup-limit articles)
8559   (let ((total (length gnus-newsgroup-data))
8560         (data (gnus-data-find-list (gnus-summary-article-number)))
8561         (gnus-summary-mark-below nil)   ; Inhibit this.
8562         found)
8563     ;; This will do all the work of generating the new summary buffer
8564     ;; according to the new limit.
8565     (gnus-summary-prepare)
8566     ;; Hide any threads, possibly.
8567     (gnus-summary-maybe-hide-threads)
8568     ;; Try to return to the article you were at, or one in the
8569     ;; neighborhood.
8570     (when data
8571       ;; We try to find some article after the current one.
8572       (while data
8573         (when (gnus-summary-goto-subject (gnus-data-number (car data)) nil t)
8574           (setq data nil
8575                 found t))
8576         (setq data (cdr data))))
8577     (unless found
8578       ;; If there is no data, that means that we were after the last
8579       ;; article.  The same goes when we can't find any articles
8580       ;; after the current one.
8581       (goto-char (point-max))
8582       (gnus-summary-find-prev))
8583     (gnus-set-mode-line 'summary)
8584     ;; We return how many articles were removed from the summary
8585     ;; buffer as a result of the new limit.
8586     (- total (length gnus-newsgroup-data))))
8587
8588 (defsubst gnus-invisible-cut-children (threads)
8589   (let ((num 0))
8590     (while threads
8591       (when (memq (mail-header-number (caar threads)) gnus-newsgroup-limit)
8592         (incf num))
8593       (pop threads))
8594     (< num 2)))
8595
8596 (defsubst gnus-cut-thread (thread)
8597   "Go forwards in the thread until we find an article that we want to display."
8598   (when (or (eq gnus-fetch-old-headers 'some)
8599             (eq gnus-fetch-old-headers 'invisible)
8600             (numberp gnus-fetch-old-headers)
8601             (eq gnus-build-sparse-threads 'some)
8602             (eq gnus-build-sparse-threads 'more))
8603     ;; Deal with old-fetched headers and sparse threads.
8604     (while (and
8605             thread
8606             (or
8607              (gnus-summary-article-sparse-p (mail-header-number (car thread)))
8608              (gnus-summary-article-ancient-p
8609               (mail-header-number (car thread))))
8610             (if (or (<= (length (cdr thread)) 1)
8611                     (eq gnus-fetch-old-headers 'invisible))
8612                 (setq gnus-newsgroup-limit
8613                       (delq (mail-header-number (car thread))
8614                             gnus-newsgroup-limit)
8615                       thread (cadr thread))
8616               (when (gnus-invisible-cut-children (cdr thread))
8617                 (let ((th (cdr thread)))
8618                   (while th
8619                     (if (memq (mail-header-number (caar th))
8620                               gnus-newsgroup-limit)
8621                         (setq thread (car th)
8622                               th nil)
8623                       (setq th (cdr th))))))))))
8624   thread)
8625
8626 (defun gnus-cut-threads (threads)
8627   "Cut off all uninteresting articles from the beginning of THREADS."
8628   (when (or (eq gnus-fetch-old-headers 'some)
8629             (eq gnus-fetch-old-headers 'invisible)
8630             (numberp gnus-fetch-old-headers)
8631             (eq gnus-build-sparse-threads 'some)
8632             (eq gnus-build-sparse-threads 'more))
8633     (let ((th threads))
8634       (while th
8635         (setcar th (gnus-cut-thread (car th)))
8636         (setq th (cdr th)))))
8637   ;; Remove nixed out threads.
8638   (delq nil threads))
8639
8640 (defun gnus-summary-initial-limit (&optional show-if-empty)
8641   "Figure out what the initial limit is supposed to be on group entry.
8642 This entails weeding out unwanted dormants, low-scored articles,
8643 fetch-old-headers verbiage, and so on."
8644   ;; Most groups have nothing to remove.
8645   (unless (or gnus-inhibit-limiting
8646               (and (null gnus-newsgroup-dormant)
8647                    (eq gnus-newsgroup-display 'gnus-not-ignore)
8648                    (not (eq gnus-fetch-old-headers 'some))
8649                    (not (numberp gnus-fetch-old-headers))
8650                    (not (eq gnus-fetch-old-headers 'invisible))
8651                    (null gnus-summary-expunge-below)
8652                    (not (eq gnus-build-sparse-threads 'some))
8653                    (not (eq gnus-build-sparse-threads 'more))
8654                    (null gnus-thread-expunge-below)
8655                    (not gnus-use-nocem)))
8656     (push gnus-newsgroup-limit gnus-newsgroup-limits)
8657     (setq gnus-newsgroup-limit nil)
8658     (mapatoms
8659      (lambda (node)
8660        (unless (car (symbol-value node))
8661          ;; These threads have no parents -- they are roots.
8662          (let ((nodes (cdr (symbol-value node)))
8663                thread)
8664            (while nodes
8665              (if (and gnus-thread-expunge-below
8666                       (< (gnus-thread-total-score (car nodes))
8667                          gnus-thread-expunge-below))
8668                  (gnus-expunge-thread (pop nodes))
8669                (setq thread (pop nodes))
8670                (gnus-summary-limit-children thread))))))
8671      gnus-newsgroup-dependencies)
8672     ;; If this limitation resulted in an empty group, we might
8673     ;; pop the previous limit and use it instead.
8674     (when (and (not gnus-newsgroup-limit)
8675                show-if-empty)
8676       (setq gnus-newsgroup-limit (pop gnus-newsgroup-limits)))
8677     gnus-newsgroup-limit))
8678
8679 (defun gnus-summary-limit-children (thread)
8680   "Return 1 if this subthread is visible and 0 if it is not."
8681   ;; First we get the number of visible children to this thread.  This
8682   ;; is done by recursing down the thread using this function, so this
8683   ;; will really go down to a leaf article first, before slowly
8684   ;; working its way up towards the root.
8685   (when thread
8686     (let* ((max-lisp-eval-depth (max 5000 max-lisp-eval-depth))
8687            (children
8688            (if (cdr thread)
8689                (apply '+ (mapcar 'gnus-summary-limit-children
8690                                  (cdr thread)))
8691              0))
8692           (number (mail-header-number (car thread)))
8693           score)
8694       (if (and
8695            (not (memq number gnus-newsgroup-marked))
8696            (or
8697             ;; If this article is dormant and has absolutely no visible
8698             ;; children, then this article isn't visible.
8699             (and (memq number gnus-newsgroup-dormant)
8700                  (zerop children))
8701             ;; If this is "fetch-old-headered" and there is no
8702             ;; visible children, then we don't want this article.
8703             (and (or (eq gnus-fetch-old-headers 'some)
8704                      (numberp gnus-fetch-old-headers))
8705                  (gnus-summary-article-ancient-p number)
8706                  (zerop children))
8707             ;; If this is "fetch-old-headered" and `invisible', then
8708             ;; we don't want this article.
8709             (and (eq gnus-fetch-old-headers 'invisible)
8710                  (gnus-summary-article-ancient-p number))
8711             ;; If this is a sparsely inserted article with no children,
8712             ;; we don't want it.
8713             (and (eq gnus-build-sparse-threads 'some)
8714                  (gnus-summary-article-sparse-p number)
8715                  (zerop children))
8716             ;; If we use expunging, and this article is really
8717             ;; low-scored, then we don't want this article.
8718             (when (and gnus-summary-expunge-below
8719                        (< (setq score
8720                                 (or (cdr (assq number gnus-newsgroup-scored))
8721                                     gnus-summary-default-score))
8722                           gnus-summary-expunge-below))
8723               ;; We increase the expunge-tally here, but that has
8724               ;; nothing to do with the limits, really.
8725               (incf gnus-newsgroup-expunged-tally)
8726               ;; We also mark as read here, if that's wanted.
8727               (when (and gnus-summary-mark-below
8728                          (< score gnus-summary-mark-below))
8729                 (setq gnus-newsgroup-unreads
8730                       (delq number gnus-newsgroup-unreads))
8731                 (if gnus-newsgroup-auto-expire
8732                     (push number gnus-newsgroup-expirable)
8733                   (push (cons number gnus-low-score-mark)
8734                         gnus-newsgroup-reads)))
8735               t)
8736             ;; Do the `display' group parameter.
8737             (and gnus-newsgroup-display
8738                  (not (funcall gnus-newsgroup-display)))
8739             ;; Check NoCeM things.
8740             (when (and gnus-use-nocem
8741                        (gnus-nocem-unwanted-article-p
8742                         (mail-header-id (car thread))))
8743               (setq gnus-newsgroup-unreads
8744                     (delq number gnus-newsgroup-unreads))
8745               t)))
8746           ;; Nope, invisible article.
8747           0
8748         ;; Ok, this article is to be visible, so we add it to the limit
8749         ;; and return 1.
8750         (push number gnus-newsgroup-limit)
8751         1))))
8752
8753 (defun gnus-expunge-thread (thread)
8754   "Mark all articles in THREAD as read."
8755   (let* ((number (mail-header-number (car thread))))
8756     (incf gnus-newsgroup-expunged-tally)
8757     ;; We also mark as read here, if that's wanted.
8758     (setq gnus-newsgroup-unreads
8759           (delq number gnus-newsgroup-unreads))
8760     (if gnus-newsgroup-auto-expire
8761         (push number gnus-newsgroup-expirable)
8762       (push (cons number gnus-low-score-mark)
8763             gnus-newsgroup-reads)))
8764   ;; Go recursively through all subthreads.
8765   (mapcar 'gnus-expunge-thread (cdr thread)))
8766
8767 ;; Summary article oriented commands
8768
8769 (defun gnus-summary-refer-parent-article (n)
8770   "Refer parent article N times.
8771 If N is negative, go to ancestor -N instead.
8772 The difference between N and the number of articles fetched is returned."
8773   (interactive "p")
8774   (let ((skip 1)
8775         error header ref)
8776     (when (not (natnump n))
8777       (setq skip (abs n)
8778             n 1))
8779     (while (and (> n 0)
8780                 (not error))
8781       (setq header (gnus-summary-article-header))
8782       (if (and (eq (mail-header-number header)
8783                    (cdr gnus-article-current))
8784                (equal gnus-newsgroup-name
8785                       (car gnus-article-current)))
8786           ;; If we try to find the parent of the currently
8787           ;; displayed article, then we take a look at the actual
8788           ;; References header, since this is slightly more
8789           ;; reliable than the References field we got from the
8790           ;; server.
8791           (with-current-buffer gnus-original-article-buffer
8792             (nnheader-narrow-to-headers)
8793             (unless (setq ref (message-fetch-field "references"))
8794               (when (setq ref (message-fetch-field "in-reply-to"))
8795                 (setq ref (gnus-extract-message-id-from-in-reply-to ref))))
8796             (widen))
8797         (setq ref
8798               ;; It's not the current article, so we take a bet on
8799               ;; the value we got from the server.
8800               (mail-header-references header)))
8801       (if (and ref
8802                (not (equal ref "")))
8803           (unless (gnus-summary-refer-article (gnus-parent-id ref skip))
8804             (gnus-message 1 "Couldn't find parent"))
8805         (gnus-message 1 "No references in article %d"
8806                       (gnus-summary-article-number))
8807         (setq error t))
8808       (decf n))
8809     (gnus-summary-position-point)
8810     n))
8811
8812 (defun gnus-summary-refer-references ()
8813   "Fetch all articles mentioned in the References header.
8814 Return the number of articles fetched."
8815   (interactive)
8816   (let ((ref (mail-header-references (gnus-summary-article-header)))
8817         (current (gnus-summary-article-number))
8818         (n 0))
8819     (if (or (not ref)
8820             (equal ref ""))
8821         (error "No References in the current article")
8822       ;; For each Message-ID in the References header...
8823       (while (string-match "<[^>]*>" ref)
8824         (incf n)
8825         ;; ... fetch that article.
8826         (gnus-summary-refer-article
8827          (prog1 (match-string 0 ref)
8828            (setq ref (substring ref (match-end 0))))))
8829       (gnus-summary-goto-subject current)
8830       (gnus-summary-position-point)
8831       n)))
8832
8833 (defun gnus-summary-refer-thread (&optional limit)
8834   "Fetch all articles in the current thread.
8835 If LIMIT (the numerical prefix), fetch that many old headers instead
8836 of what's specified by the `gnus-refer-thread-limit' variable."
8837   (interactive "P")
8838   (let ((id (mail-header-id (gnus-summary-article-header)))
8839         (limit (if limit (prefix-numeric-value limit)
8840                  gnus-refer-thread-limit)))
8841     (unless (eq gnus-fetch-old-headers 'invisible)
8842       (gnus-message 5 "Fetching headers for %s..." gnus-newsgroup-name)
8843       ;; Retrieve the headers and read them in.
8844       (if (eq (if (numberp limit)
8845                   (gnus-retrieve-headers
8846                    (list (min
8847                           (+ (mail-header-number
8848                               (gnus-summary-article-header))
8849                              limit)
8850                           gnus-newsgroup-end))
8851                    gnus-newsgroup-name (* limit 2))
8852                 ;; gnus-refer-thread-limit is t, i.e. fetch _all_
8853                 ;; headers.
8854                 (gnus-retrieve-headers (list gnus-newsgroup-end)
8855                                        gnus-newsgroup-name limit))
8856               'nov)
8857           (gnus-build-all-threads)
8858         (error "Can't fetch thread from back ends that don't support NOV"))
8859       (gnus-message 5 "Fetching headers for %s...done" gnus-newsgroup-name))
8860     (gnus-summary-limit-include-thread id)))
8861
8862 (defun gnus-summary-refer-article (message-id)
8863   "Fetch an article specified by MESSAGE-ID."
8864   (interactive "sMessage-ID: ")
8865   (when (and (stringp message-id)
8866              (not (zerop (length message-id))))
8867     (setq message-id (gnus-replace-in-string message-id " " ""))
8868     ;; Construct the correct Message-ID if necessary.
8869     ;; Suggested by tale@pawl.rpi.edu.
8870     (unless (string-match "^<" message-id)
8871       (setq message-id (concat "<" message-id)))
8872     (unless (string-match ">$" message-id)
8873       (setq message-id (concat message-id ">")))
8874     ;; People often post MIDs from URLs, so unhex it:
8875     (unless (string-match "@" message-id)
8876       (setq message-id (gnus-url-unhex-string message-id)))
8877     (let* ((header (gnus-id-to-header message-id))
8878            (sparse (and header
8879                         (gnus-summary-article-sparse-p
8880                          (mail-header-number header))
8881                         (memq (mail-header-number header)
8882                               gnus-newsgroup-limit)))
8883            number)
8884       (cond
8885        ;; If the article is present in the buffer we just go to it.
8886        ((and header
8887              (or (not (gnus-summary-article-sparse-p
8888                        (mail-header-number header)))
8889                  sparse))
8890         (prog1
8891             (gnus-summary-goto-article
8892              (mail-header-number header) nil t)
8893           (when sparse
8894             (gnus-summary-update-article (mail-header-number header)))))
8895        (t
8896         ;; We fetch the article.
8897         (catch 'found
8898           (dolist (gnus-override-method (gnus-refer-article-methods))
8899             (when (and (gnus-check-server gnus-override-method)
8900                        ;; Fetch the header,
8901                        (setq number (gnus-summary-insert-subject message-id)))
8902               ;; and display the article.
8903               (gnus-summary-select-article nil nil nil number)
8904               (throw 'found t)))
8905           (gnus-message 3 "Couldn't fetch article %s" message-id)))))))
8906
8907 (defun gnus-refer-article-methods ()
8908   "Return a list of referable methods."
8909   (cond
8910    ;; No method, so we default to current and native.
8911    ((null gnus-refer-article-method)
8912     (list gnus-current-select-method gnus-select-method))
8913    ;; Current.
8914    ((eq 'current gnus-refer-article-method)
8915     (list gnus-current-select-method))
8916    ;; List of select methods.
8917    ((not (and (symbolp (car gnus-refer-article-method))
8918               (assq (car gnus-refer-article-method) nnoo-definition-alist)))
8919     (let (out)
8920       (dolist (method gnus-refer-article-method)
8921         (push (if (eq 'current method)
8922                   gnus-current-select-method
8923                 method)
8924               out))
8925       (nreverse out)))
8926    ;; One single select method.
8927    (t
8928     (list gnus-refer-article-method))))
8929
8930 (defun gnus-summary-edit-parameters ()
8931   "Edit the group parameters of the current group."
8932   (interactive)
8933   (gnus-group-edit-group gnus-newsgroup-name 'params))
8934
8935 (defun gnus-summary-customize-parameters ()
8936   "Customize the group parameters of the current group."
8937   (interactive)
8938   (gnus-group-customize gnus-newsgroup-name))
8939
8940 (defun gnus-summary-enter-digest-group (&optional force)
8941   "Enter an nndoc group based on the current article.
8942 If FORCE, force a digest interpretation.  If not, try
8943 to guess what the document format is."
8944   (interactive "P")
8945   (let ((conf gnus-current-window-configuration))
8946     (save-window-excursion
8947       (save-excursion
8948         (let (gnus-article-prepare-hook
8949               gnus-display-mime-function
8950               gnus-break-pages)
8951           (gnus-summary-select-article))))
8952     (setq gnus-current-window-configuration conf)
8953     (let* ((name (format "%s-%d"
8954                          (gnus-group-prefixed-name
8955                           gnus-newsgroup-name (list 'nndoc ""))
8956                          (with-current-buffer gnus-summary-buffer
8957                            gnus-current-article)))
8958            (ogroup gnus-newsgroup-name)
8959            (params (append (gnus-info-params (gnus-get-info ogroup))
8960                            (list (cons 'to-group ogroup))
8961                            (list (cons 'parent-group ogroup))
8962                            (list (cons 'save-article-group ogroup))))
8963            (case-fold-search t)
8964            (buf (current-buffer))
8965            dig to-address)
8966       (with-current-buffer gnus-original-article-buffer
8967         ;; Have the digest group inherit the main mail address of
8968         ;; the parent article.
8969         (when (setq to-address (or (gnus-fetch-field "reply-to")
8970                                    (gnus-fetch-field "from")))
8971           (setq params
8972                 (append
8973                  (list (cons 'to-address
8974                              (funcall gnus-decode-encoded-address-function
8975                                       to-address))))))
8976         (setq dig (nnheader-set-temp-buffer " *gnus digest buffer*"))
8977         (insert-buffer-substring gnus-original-article-buffer)
8978         ;; Remove lines that may lead nndoc to misinterpret the
8979         ;; document type.
8980         (narrow-to-region
8981          (goto-char (point-min))
8982          (or (search-forward "\n\n" nil t) (point)))
8983         (goto-char (point-min))
8984         (delete-matching-lines "^Path:\\|^From ")
8985         (widen))
8986       (unwind-protect
8987           (if (let ((gnus-newsgroup-ephemeral-charset gnus-newsgroup-charset)
8988                     (gnus-newsgroup-ephemeral-ignored-charsets
8989                      gnus-newsgroup-ignored-charsets))
8990                 (gnus-group-read-ephemeral-group
8991                  name `(nndoc ,name (nndoc-address ,(get-buffer dig))
8992                               (nndoc-article-type
8993                                ,(if force 'mbox 'guess)))
8994                  t nil nil nil
8995                  `((adapt-file . ,(gnus-score-file-name gnus-newsgroup-name
8996                                                         "ADAPT")))))
8997               ;; Make all postings to this group go to the parent group.
8998               (nconc (gnus-info-params (gnus-get-info name))
8999                      params)
9000             ;; Couldn't select this doc group.
9001             (switch-to-buffer buf)
9002             (gnus-set-global-variables)
9003             (gnus-configure-windows 'summary)
9004             (gnus-message 3 "Article couldn't be entered?"))
9005         (kill-buffer dig)))))
9006
9007 (defun gnus-summary-read-document (n)
9008   "Open a new group based on the current article(s).
9009 This will allow you to read digests and other similar
9010 documents as newsgroups.
9011 Obeys the standard process/prefix convention."
9012   (interactive "P")
9013   (let* ((ogroup gnus-newsgroup-name)
9014          (params (append (gnus-info-params (gnus-get-info ogroup))
9015                          (list (cons 'to-group ogroup))))
9016          group egroup groups vgroup)
9017     (dolist (article (gnus-summary-work-articles n))
9018       (setq group (format "%s-%d" gnus-newsgroup-name article))
9019       (gnus-summary-remove-process-mark article)
9020       (when (gnus-summary-display-article article)
9021         (save-excursion ;;What for?
9022           (with-temp-buffer
9023             (insert-buffer-substring gnus-original-article-buffer)
9024             ;; Remove some headers that may lead nndoc to make
9025             ;; the wrong guess.
9026             (message-narrow-to-head)
9027             (goto-char (point-min))
9028             (delete-matching-lines "^Path:\\|^From ")
9029             (widen)
9030             (if (setq egroup
9031                       (gnus-group-read-ephemeral-group
9032                        group `(nndoc ,group (nndoc-address ,(current-buffer))
9033                                      (nndoc-article-type guess))
9034                        t nil t))
9035                 (progn
9036                   ;; Make all postings to this group go to the parent group.
9037                   (nconc (gnus-info-params (gnus-get-info egroup))
9038                          params)
9039                   (push egroup groups))
9040               ;; Couldn't select this doc group.
9041               (gnus-error 3 "Article couldn't be entered"))))))
9042     ;; Now we have selected all the documents.
9043     (cond
9044      ((not groups)
9045       (error "None of the articles could be interpreted as documents"))
9046      ((gnus-group-read-ephemeral-group
9047        (setq vgroup (format
9048                      "nnvirtual:%s-%s" gnus-newsgroup-name
9049                      (format-time-string "%Y%m%dT%H%M%S" (current-time))))
9050        `(nnvirtual ,vgroup (nnvirtual-component-groups ,groups))
9051        t
9052        (cons (current-buffer) 'summary)))
9053      (t
9054       (error "Couldn't select virtual nndoc group")))))
9055
9056 (defun gnus-summary-isearch-article (&optional regexp-p)
9057   "Do incremental search forward on the current article.
9058 If REGEXP-P (the prefix) is non-nil, do regexp isearch."
9059   (interactive "P")
9060   (gnus-summary-select-article)
9061   (gnus-configure-windows 'article)
9062   (gnus-eval-in-buffer-window gnus-article-buffer
9063     (save-restriction
9064       (widen)
9065       (isearch-forward regexp-p))))
9066
9067 (defun gnus-summary-repeat-search-article-forward ()
9068   "Repeat the previous search forwards."
9069   (interactive)
9070   (unless gnus-last-search-regexp
9071     (error "No previous search"))
9072   (gnus-summary-search-article-forward gnus-last-search-regexp))
9073
9074 (defun gnus-summary-repeat-search-article-backward ()
9075   "Repeat the previous search backwards."
9076   (interactive)
9077   (unless gnus-last-search-regexp
9078     (error "No previous search"))
9079   (gnus-summary-search-article-forward gnus-last-search-regexp t))
9080
9081 (defun gnus-summary-search-article-forward (regexp &optional backward)
9082   "Search for an article containing REGEXP forward.
9083 If BACKWARD, search backward instead."
9084   (interactive
9085    (list (read-string
9086           (format "Search article %s (regexp%s): "
9087                   (if current-prefix-arg "backward" "forward")
9088                   (if gnus-last-search-regexp
9089                       (concat ", default " gnus-last-search-regexp)
9090                     "")))
9091          current-prefix-arg))
9092   (if (string-equal regexp "")
9093       (setq regexp (or gnus-last-search-regexp ""))
9094     (setq gnus-last-search-regexp regexp)
9095     (setq gnus-article-before-search gnus-current-article))
9096   ;; Intentionally set gnus-last-article.
9097   (setq gnus-last-article gnus-article-before-search)
9098   (let ((gnus-last-article gnus-last-article))
9099     (if (gnus-summary-search-article regexp backward)
9100         (gnus-summary-show-thread)
9101       (signal 'search-failed (list regexp)))))
9102
9103 (defun gnus-summary-search-article-backward (regexp)
9104   "Search for an article containing REGEXP backward."
9105   (interactive
9106    (list (read-string
9107           (format "Search article backward (regexp%s): "
9108                   (if gnus-last-search-regexp
9109                       (concat ", default " gnus-last-search-regexp)
9110                     "")))))
9111   (gnus-summary-search-article-forward regexp 'backward))
9112
9113 (defun gnus-summary-search-article (regexp &optional backward)
9114   "Search for an article containing REGEXP.
9115 Optional argument BACKWARD means do search for backward.
9116 `gnus-select-article-hook' is not called during the search."
9117   ;; We have to require this here to make sure that the following
9118   ;; dynamic binding isn't shadowed by autoloading.
9119   (require 'gnus-async)
9120   (require 'gnus-art)
9121   (let ((gnus-select-article-hook nil)  ;Disable hook.
9122         (gnus-article-prepare-hook nil)
9123         (gnus-mark-article-hook nil)    ;Inhibit marking as read.
9124         (gnus-use-article-prefetch nil)
9125         (gnus-xmas-force-redisplay nil) ;Inhibit XEmacs redisplay.
9126         (gnus-use-trees nil)            ;Inhibit updating tree buffer.
9127         (gnus-visual nil)
9128         (gnus-keep-backlog nil)
9129         (gnus-break-pages nil)
9130         (gnus-summary-display-arrow nil)
9131         (gnus-updated-mode-lines nil)
9132         (gnus-auto-center-summary nil)
9133         (sum (current-buffer))
9134         (gnus-display-mime-function nil)
9135         (found nil)
9136         point)
9137     (gnus-save-hidden-threads
9138       (gnus-summary-select-article)
9139       (set-buffer gnus-article-buffer)
9140       (goto-char (window-point (get-buffer-window (current-buffer))))
9141       (when backward
9142         (forward-line -1))
9143       (while (not found)
9144         (gnus-message 7 "Searching article: %d..." (cdr gnus-article-current))
9145         (if (if backward
9146                 (re-search-backward regexp nil t)
9147               (re-search-forward regexp nil t))
9148             ;; We found the regexp.
9149             (progn
9150               (setq found 'found)
9151               (beginning-of-line)
9152               (set-window-start
9153                (get-buffer-window (current-buffer))
9154                (point))
9155               (forward-line 1)
9156               (set-window-point
9157                (get-buffer-window (current-buffer))
9158                (point))
9159               (set-buffer sum)
9160               (setq point (point)))
9161           ;; We didn't find it, so we go to the next article.
9162           (set-buffer sum)
9163           (setq found 'not)
9164           (while (eq found 'not)
9165             (if (not (if backward (gnus-summary-find-prev)
9166                        (gnus-summary-find-next)))
9167                 ;; No more articles.
9168                 (setq found t)
9169               ;; Select the next article and adjust point.
9170               (unless (gnus-summary-article-sparse-p
9171                        (gnus-summary-article-number))
9172                 (setq found nil)
9173                 (gnus-summary-select-article)
9174                 (set-buffer gnus-article-buffer)
9175                 (widen)
9176                 (goto-char (if backward (point-max) (point-min))))))))
9177       (gnus-message 7 ""))
9178     ;; Return whether we found the regexp.
9179     (when (eq found 'found)
9180       (goto-char point)
9181       (gnus-summary-show-thread)
9182       (gnus-summary-goto-subject gnus-current-article)
9183       (gnus-summary-position-point)
9184       t)))
9185
9186 (defun gnus-find-matching-articles (header regexp)
9187   "Return a list of all articles that match REGEXP on HEADER.
9188 This search includes all articles in the current group that Gnus has
9189 fetched headers for, whether they are displayed or not."
9190   (let ((articles nil)
9191         ;; Can't eta-reduce because it's a macro.
9192         (func `(lambda (h) (,(intern (concat "mail-header-" header)) h)))
9193         (case-fold-search t))
9194     (dolist (header gnus-newsgroup-headers)
9195       (when (string-match regexp (funcall func header))
9196         (push (mail-header-number header) articles)))
9197     (nreverse articles)))
9198
9199 (defun gnus-summary-find-matching (header regexp &optional backward unread
9200                                           not-case-fold not-matching)
9201   "Return a list of all articles that match REGEXP on HEADER.
9202 The search stars on the current article and goes forwards unless
9203 BACKWARD is non-nil.  If BACKWARD is `all', do all articles.
9204 If UNREAD is non-nil, only unread articles will
9205 be taken into consideration.  If NOT-CASE-FOLD, case won't be folded
9206 in the comparisons. If NOT-MATCHING, return a list of all articles that
9207 not match REGEXP on HEADER."
9208   (let ((case-fold-search (not not-case-fold))
9209         articles d func)
9210     (if (consp header)
9211         (if (eq (car header) 'extra)
9212             (setq func
9213                   `(lambda (h)
9214                      (or (cdr (assq ',(cdr header) (mail-header-extra h)))
9215                          "")))
9216           (error "%s is an invalid header" header))
9217       (unless (fboundp (intern (concat "mail-header-" header)))
9218         (error "%s is not a valid header" header))
9219       (setq func `(lambda (h) (,(intern (concat "mail-header-" header)) h))))
9220     (dolist (d (if (eq backward 'all)
9221                    gnus-newsgroup-data
9222                  (gnus-data-find-list
9223                   (gnus-summary-article-number)
9224                   (gnus-data-list backward))))
9225       (when (and (or (not unread)       ; We want all articles...
9226                      (gnus-data-unread-p d)) ; Or just unreads.
9227                  (vectorp (gnus-data-header d)) ; It's not a pseudo.
9228                  (if not-matching
9229                      (not (string-match
9230                            regexp
9231                            (funcall func (gnus-data-header d))))
9232                    (string-match regexp
9233                                  (funcall func (gnus-data-header d)))))
9234         (push (gnus-data-number d) articles))) ; Success!
9235     (nreverse articles)))
9236
9237 (defun gnus-summary-execute-command (header regexp command &optional backward)
9238   "Search forward for an article whose HEADER matches REGEXP and execute COMMAND.
9239 If HEADER is an empty string (or nil), the match is done on the entire
9240 article.  If BACKWARD (the prefix) is non-nil, search backward instead."
9241   (interactive
9242    (list (let ((completion-ignore-case t))
9243            (completing-read
9244             "Header name: "
9245             (mapcar (lambda (header) (list (format "%s" header)))
9246                     (append
9247                      '("Number" "Subject" "From" "Lines" "Date"
9248                        "Message-ID" "Xref" "References" "Body")
9249                      gnus-extra-headers))
9250             nil 'require-match))
9251          (read-string "Regexp: ")
9252          (read-key-sequence "Command: ")
9253          current-prefix-arg))
9254   (when (equal header "Body")
9255     (setq header ""))
9256   ;; Hidden thread subtrees must be searched as well.
9257   (gnus-summary-show-all-threads)
9258   ;; We don't want to change current point nor window configuration.
9259   (save-excursion
9260     (save-window-excursion
9261       (let (gnus-visual
9262             gnus-treat-strip-trailing-blank-lines
9263             gnus-treat-strip-leading-blank-lines
9264             gnus-treat-strip-multiple-blank-lines
9265             gnus-treat-hide-boring-headers
9266             gnus-treat-fold-newsgroups
9267             gnus-article-prepare-hook)
9268         (gnus-message 6 "Executing %s..." (key-description command))
9269         ;; We'd like to execute COMMAND interactively so as to give arguments.
9270         (gnus-execute header regexp
9271                       `(call-interactively ',(key-binding command))
9272                       backward)
9273         (gnus-message 6 "Executing %s...done" (key-description command))))))
9274
9275 (defun gnus-summary-beginning-of-article ()
9276   "Scroll the article back to the beginning."
9277   (interactive)
9278   (gnus-summary-select-article)
9279   (gnus-configure-windows 'article)
9280   (gnus-eval-in-buffer-window gnus-article-buffer
9281     (widen)
9282     (goto-char (point-min))
9283     (when gnus-break-pages
9284       (gnus-narrow-to-page))))
9285
9286 (defun gnus-summary-end-of-article ()
9287   "Scroll to the end of the article."
9288   (interactive)
9289   (gnus-summary-select-article)
9290   (gnus-configure-windows 'article)
9291   (gnus-eval-in-buffer-window gnus-article-buffer
9292     (widen)
9293     (goto-char (point-max))
9294     (recenter -3)
9295     (when gnus-break-pages
9296       (gnus-narrow-to-page))))
9297
9298 (defun gnus-summary-print-truncate-and-quote (string &optional len)
9299   "Truncate to LEN and quote all \"(\"'s in STRING."
9300   (gnus-replace-in-string (if (and len (> (length string) len))
9301                               (substring string 0 len)
9302                             string)
9303                           "[()]" "\\\\\\&"))
9304
9305 (defun gnus-summary-print-article (&optional filename n)
9306   "Generate and print a PostScript image of the process-marked (mail) articles.
9307
9308 If used interactively, print the current article if none are
9309 process-marked.  With prefix arg, prompt the user for the name of the
9310 file to save in.
9311
9312 When used from Lisp, accept two optional args FILENAME and N.  N means
9313 to print the next N articles.  If N is negative, print the N previous
9314 articles.  If N is nil and articles have been marked with the process
9315 mark, print these instead.
9316
9317 If the optional first argument FILENAME is nil, send the image to the
9318 printer.  If FILENAME is a string, save the PostScript image in a file with
9319 that name.  If FILENAME is a number, prompt the user for the name of the file
9320 to save in."
9321   (interactive (list (ps-print-preprint current-prefix-arg)))
9322   (dolist (article (gnus-summary-work-articles n))
9323     (gnus-summary-select-article nil nil 'pseudo article)
9324     (gnus-eval-in-buffer-window gnus-article-buffer
9325       (gnus-print-buffer))
9326     (gnus-summary-remove-process-mark article))
9327   (ps-despool filename))
9328
9329 (defun gnus-print-buffer ()
9330   (let ((buffer (generate-new-buffer " *print*")))
9331     (unwind-protect
9332         (progn
9333           (copy-to-buffer buffer (point-min) (point-max))
9334           (set-buffer buffer)
9335           (gnus-remove-text-with-property 'gnus-decoration)
9336           (when (gnus-visual-p 'article-highlight 'highlight)
9337             ;; Copy-to-buffer doesn't copy overlay.  So redo
9338             ;; highlight.
9339             (let ((gnus-article-buffer buffer))
9340               (gnus-article-highlight-citation t)
9341               (gnus-article-highlight-signature)
9342               (gnus-article-emphasize)
9343               (gnus-article-delete-invisible-text)))
9344           (let ((ps-left-header
9345                  (list
9346                   (concat "("
9347                           (gnus-summary-print-truncate-and-quote
9348                            (mail-header-subject gnus-current-headers)
9349                            66) ")")
9350                   (concat "("
9351                           (gnus-summary-print-truncate-and-quote
9352                            (mail-header-from gnus-current-headers)
9353                            45) ")")))
9354                 (ps-right-header
9355                  (list
9356                   "/pagenumberstring load"
9357                   (concat "("
9358                           (mail-header-date gnus-current-headers) ")"))))
9359             (gnus-run-hooks 'gnus-ps-print-hook)
9360             (save-excursion
9361               (if ps-print-color-p
9362                   (ps-spool-buffer-with-faces)
9363                 (ps-spool-buffer)))))
9364       (kill-buffer buffer))))
9365
9366 (defun gnus-summary-show-article (&optional arg)
9367   "Force redisplaying of the current article.
9368 If ARG (the prefix) is a number, show the article with the charset
9369 defined in `gnus-summary-show-article-charset-alist', or the charset
9370 input.
9371 If ARG (the prefix) is non-nil and not a number, show the raw article
9372 without any article massaging functions being run.  Normally, the key
9373 strokes are `C-u g'."
9374   (interactive "P")
9375   (cond
9376    ((numberp arg)
9377     (gnus-summary-show-article t)
9378     (let ((gnus-newsgroup-charset
9379            (or (cdr (assq arg gnus-summary-show-article-charset-alist))
9380                (mm-read-coding-system
9381                 "View as charset: " ;; actually it is coding system.
9382                 (with-current-buffer gnus-article-buffer
9383                   (mm-detect-coding-region (point) (point-max))))))
9384           (gnus-newsgroup-ignored-charsets 'gnus-all))
9385       (gnus-summary-select-article nil 'force)
9386       (let ((deps gnus-newsgroup-dependencies)
9387             head header lines)
9388         (with-current-buffer gnus-original-article-buffer
9389           (save-restriction
9390             (message-narrow-to-head)
9391             (setq head (buffer-string))
9392             (goto-char (point-min))
9393             (unless (re-search-forward "^lines:[ \t]\\([0-9]+\\)" nil t)
9394               (goto-char (point-max))
9395               (widen)
9396               (setq lines (1- (count-lines (point) (point-max))))))
9397           (with-temp-buffer
9398             (insert (format "211 %d Article retrieved.\n"
9399                             (cdr gnus-article-current)))
9400             (insert head)
9401             (if lines (insert (format "Lines: %d\n" lines)))
9402             (insert ".\n")
9403             (let ((nntp-server-buffer (current-buffer)))
9404               (setq header (car (gnus-get-newsgroup-headers deps t))))))
9405         (gnus-data-set-header
9406          (gnus-data-find (cdr gnus-article-current))
9407          header)
9408         (gnus-summary-update-article-line
9409          (cdr gnus-article-current) header)
9410         (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
9411           (gnus-summary-update-secondary-mark (cdr gnus-article-current))))))
9412    ((not arg)
9413     ;; Select the article the normal way.
9414     (gnus-summary-select-article nil 'force))
9415    (t
9416     ;; We have to require this here to make sure that the following
9417     ;; dynamic binding isn't shadowed by autoloading.
9418     (require 'gnus-async)
9419     (require 'gnus-art)
9420     ;; Bind the article treatment functions to nil.
9421     (let ((gnus-have-all-headers t)
9422           gnus-article-prepare-hook
9423           gnus-article-decode-hook
9424           gnus-display-mime-function
9425           gnus-break-pages)
9426       ;; Destroy any MIME parts.
9427       (when (gnus-buffer-live-p gnus-article-buffer)
9428         (with-current-buffer gnus-article-buffer
9429           (mm-destroy-parts gnus-article-mime-handles)
9430           ;; Set it to nil for safety reason.
9431           (setq gnus-article-mime-handle-alist nil)
9432           (setq gnus-article-mime-handles nil)))
9433       (gnus-summary-select-article nil 'force))))
9434   (gnus-summary-goto-subject gnus-current-article)
9435   (gnus-summary-position-point))
9436
9437 (defun gnus-summary-show-raw-article ()
9438   "Show the raw article without any article massaging functions being run."
9439   (interactive)
9440   (gnus-summary-show-article t))
9441
9442 (defun gnus-summary-verbose-headers (&optional arg)
9443   "Toggle permanent full header display.
9444 If ARG is a positive number, turn header display on.
9445 If ARG is a negative number, turn header display off."
9446   (interactive "P")
9447   (setq gnus-show-all-headers
9448         (cond ((or (not (numberp arg))
9449                    (zerop arg))
9450                (not gnus-show-all-headers))
9451               ((natnump arg)
9452                t)))
9453   (gnus-summary-show-article))
9454
9455 (defun gnus-summary-toggle-header (&optional arg)
9456   "Show the headers if they are hidden, or hide them if they are shown.
9457 If ARG is a positive number, show the entire header.
9458 If ARG is a negative number, hide the unwanted header lines."
9459   (interactive "P")
9460   (let ((window (and (gnus-buffer-live-p gnus-article-buffer)
9461                      (get-buffer-window gnus-article-buffer t))))
9462     (with-current-buffer gnus-article-buffer
9463       (widen)
9464       (article-narrow-to-head)
9465       (let* ((inhibit-read-only t)
9466              (inhibit-point-motion-hooks t)
9467              (hidden (if (numberp arg)
9468                          (>= arg 0)
9469                        (or (not (looking-at "[^ \t\n]+:"))
9470                            (gnus-article-hidden-text-p 'headers))))
9471              s e)
9472         (delete-region (point-min) (point-max))
9473         (with-current-buffer gnus-original-article-buffer
9474           (goto-char (setq s (point-min)))
9475           (setq e (if (search-forward "\n\n" nil t)
9476                       (1- (point))
9477                     (point-max))))
9478         (insert-buffer-substring gnus-original-article-buffer s e)
9479         (run-hooks 'gnus-article-decode-hook)
9480         (if hidden
9481             (let ((gnus-treat-hide-headers nil)
9482                   (gnus-treat-hide-boring-headers nil))
9483               (gnus-delete-wash-type 'headers)
9484               (gnus-treat-article 'head))
9485           (gnus-treat-article 'head))
9486         (widen)
9487         (if window
9488             (set-window-start window (goto-char (point-min))))
9489         (if gnus-break-pages
9490             (gnus-narrow-to-page)
9491           (when (gnus-visual-p 'page-marker)
9492             (let ((inhibit-read-only t))
9493               (gnus-remove-text-with-property 'gnus-prev)
9494               (gnus-remove-text-with-property 'gnus-next))))
9495         (gnus-set-mode-line 'article)))))
9496
9497 (defun gnus-summary-show-all-headers ()
9498   "Make all header lines visible."
9499   (interactive)
9500   (gnus-summary-toggle-header 1))
9501
9502 (defun gnus-summary-caesar-message (&optional arg)
9503   "Caesar rotate the current article by 13.
9504 With a non-numerical prefix, also rotate headers.  A numerical
9505 prefix specifies how many places to rotate each letter forward."
9506   (interactive "P")
9507   (gnus-summary-select-article)
9508   (let ((mail-header-separator ""))
9509     (gnus-eval-in-buffer-window gnus-article-buffer
9510       (save-restriction
9511         (widen)
9512         (let ((start (window-start))
9513               (inhibit-read-only t))
9514           (if (equal arg '(4))
9515               (message-caesar-buffer-body nil t)
9516             (message-caesar-buffer-body arg))
9517           (set-window-start (get-buffer-window (current-buffer)) start)))))
9518   ;; Create buttons and stuff...
9519   (gnus-treat-article nil))
9520
9521 (declare-function idna-to-unicode "ext:idna" (str))
9522
9523 (defun gnus-summary-idna-message (&optional arg)
9524   "Decode IDNA encoded domain names in the current articles.
9525 IDNA encoded domain names looks like `xn--bar'.  If a string
9526 remain unencoded after running this function, it is likely an
9527 invalid IDNA string (`xn--bar' is invalid).
9528
9529 You must have GNU Libidn (`http://www.gnu.org/software/libidn/')
9530 installed for this command to work."
9531   (interactive "P")
9532   (if (not (and (condition-case nil (require 'idna)
9533                   (file-error))
9534                 (mm-coding-system-p 'utf-8)
9535                 (executable-find (symbol-value 'idna-program))))
9536       (gnus-message
9537        5 "GNU Libidn not installed properly (`idn' or `idna.el' missing)")
9538     (gnus-summary-select-article)
9539     (let ((mail-header-separator ""))
9540       (gnus-eval-in-buffer-window gnus-article-buffer
9541         (save-restriction
9542           (widen)
9543           (let ((start (window-start))
9544                 buffer-read-only)
9545             (while (re-search-forward "\\(xn--[-0-9a-z]+\\)" nil t)
9546               (replace-match (idna-to-unicode (match-string 1))))
9547             (set-window-start (get-buffer-window (current-buffer)) start)))))))
9548
9549 (defun gnus-summary-morse-message (&optional arg)
9550   "Morse decode the current article."
9551   (interactive "P")
9552   (gnus-summary-select-article)
9553   (let ((mail-header-separator ""))
9554     (gnus-eval-in-buffer-window gnus-article-buffer
9555       (save-excursion
9556         (save-restriction
9557           (widen)
9558           (let ((pos (window-start))
9559                 (inhibit-read-only t))
9560             (goto-char (point-min))
9561             (when (message-goto-body)
9562               (gnus-narrow-to-body))
9563             (goto-char (point-min))
9564             (while (search-forward "·" (point-max) t)
9565               (replace-match "."))
9566             (unmorse-region (point-min) (point-max))
9567             (widen)
9568             (set-window-start (get-buffer-window (current-buffer)) pos)))))))
9569
9570 (defun gnus-summary-stop-page-breaking ()
9571   "Stop page breaking in the current article."
9572   (interactive)
9573   (gnus-summary-select-article)
9574   (gnus-eval-in-buffer-window gnus-article-buffer
9575     (widen)
9576     (when (gnus-visual-p 'page-marker)
9577       (let ((inhibit-read-only t))
9578         (gnus-remove-text-with-property 'gnus-prev)
9579         (gnus-remove-text-with-property 'gnus-next))
9580       (setq gnus-page-broken nil))))
9581
9582 (defun gnus-summary-move-article (&optional n to-newsgroup
9583                                             select-method action)
9584   "Move the current article to a different newsgroup.
9585 If N is a positive number, move the N next articles.
9586 If N is a negative number, move the N previous articles.
9587 If N is nil and any articles have been marked with the process mark,
9588 move those articles instead.
9589 If TO-NEWSGROUP is string, do not prompt for a newsgroup to move to.
9590 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9591 re-spool using this method.
9592
9593 When called interactively with TO-NEWSGROUP being nil, the value of
9594 the variable `gnus-move-split-methods' is used for finding a default
9595 for the target newsgroup.
9596
9597 For this function to work, both the current newsgroup and the
9598 newsgroup that you want to move to have to support the `request-move'
9599 and `request-accept' functions.
9600
9601 ACTION can be either `move' (the default), `crosspost' or `copy'."
9602   (interactive "P")
9603   (unless action
9604     (setq action 'move))
9605   ;; Check whether the source group supports the required functions.
9606   (cond ((and (eq action 'move)
9607               (not (gnus-check-backend-function
9608                     'request-move-article gnus-newsgroup-name)))
9609          (error "The current group does not support article moving"))
9610         ((and (eq action 'crosspost)
9611               (not (gnus-check-backend-function
9612                     'request-replace-article gnus-newsgroup-name)))
9613          (error "The current group does not support article editing")))
9614   (let ((articles (gnus-summary-work-articles n))
9615         (prefix (if (gnus-check-backend-function
9616                      'request-move-article gnus-newsgroup-name)
9617                     (funcall gnus-move-group-prefix-function
9618                              gnus-newsgroup-name)
9619                   ""))
9620         (names '((move "Move" "Moving")
9621                  (copy "Copy" "Copying")
9622                  (crosspost "Crosspost" "Crossposting")))
9623         (copy-buf (save-excursion
9624                     (nnheader-set-temp-buffer " *copy article*")))
9625         art-group to-method new-xref article to-groups
9626         articles-to-update-marks encoded)
9627     (unless (assq action names)
9628       (error "Unknown action %s" action))
9629     ;; Read the newsgroup name.
9630     (when (and (not to-newsgroup)
9631                (not select-method))
9632       (if (and gnus-move-split-methods
9633                (not
9634                 (and (memq gnus-current-article articles)
9635                      (gnus-buffer-live-p gnus-original-article-buffer))))
9636           ;; When `gnus-move-split-methods' is non-nil, we have to
9637           ;; select an article to give `gnus-read-move-group-name' an
9638           ;; opportunity to suggest an appropriate default.  However,
9639           ;; we needn't render or mark the article.
9640           (let ((gnus-display-mime-function nil)
9641                 (gnus-article-prepare-hook nil)
9642                 (gnus-mark-article-hook nil))
9643             (gnus-summary-select-article nil nil nil (car articles))))
9644       (setq to-newsgroup (gnus-read-move-group-name
9645                           (cadr (assq action names))
9646                           (symbol-value
9647                            (intern (format "gnus-current-%s-group" action)))
9648                           articles prefix)
9649             encoded to-newsgroup
9650             to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
9651       (set (intern (format "gnus-current-%s-group" action))
9652            (mm-decode-coding-string
9653             to-newsgroup
9654             (gnus-group-name-charset to-method to-newsgroup))))
9655     (unless to-method
9656       (setq to-method (or select-method
9657                           (gnus-server-to-method
9658                            (gnus-group-method to-newsgroup)))))
9659     (setq to-newsgroup
9660           (or encoded
9661               (and to-newsgroup
9662                    (mm-encode-coding-string
9663                     to-newsgroup
9664                     (gnus-group-name-charset to-method to-newsgroup)))))
9665     ;; Check the method we are to move this article to...
9666     (unless (gnus-check-backend-function
9667              'request-accept-article (car to-method))
9668       (error "%s does not support article copying" (car to-method)))
9669     (unless (gnus-check-server to-method)
9670       (error "Can't open server %s" (car to-method)))
9671     (gnus-message 6 "%s to %s: %s..."
9672                   (caddr (assq action names))
9673                   (or (car select-method)
9674                       (gnus-group-decoded-name to-newsgroup))
9675                   articles)
9676     (while articles
9677       (setq article (pop articles))
9678       (setq
9679        art-group
9680        (cond
9681         ;; Move the article.
9682         ((eq action 'move)
9683          ;; Remove this article from future suppression.
9684          (gnus-dup-unsuppress-article article)
9685          (let* ((from-method (gnus-find-method-for-group
9686                               gnus-newsgroup-name))
9687                 (to-method (or select-method
9688                                (gnus-find-method-for-group to-newsgroup)))
9689                 (move-is-internal (gnus-method-equal from-method to-method)))
9690            (gnus-request-move-article
9691             article                     ; Article to move
9692             gnus-newsgroup-name         ; From newsgroup
9693             (nth 1 (gnus-find-method-for-group
9694                     gnus-newsgroup-name)) ; Server
9695             (list 'gnus-request-accept-article
9696                   to-newsgroup (list 'quote select-method)
9697                   (not articles) t)     ; Accept form
9698             (not articles)              ; Only save nov last time
9699             move-is-internal)))         ; is this move internal?
9700         ;; Copy the article.
9701         ((eq action 'copy)
9702          (with-current-buffer copy-buf
9703            (when (gnus-request-article-this-buffer article gnus-newsgroup-name)
9704              (save-restriction
9705                (nnheader-narrow-to-headers)
9706                (dolist (hdr gnus-copy-article-ignored-headers)
9707                  (message-remove-header hdr t)))
9708              (gnus-request-accept-article
9709               to-newsgroup select-method (not articles) t))))
9710         ;; Crosspost the article.
9711         ((eq action 'crosspost)
9712          (let ((xref (message-tokenize-header
9713                       (mail-header-xref (gnus-summary-article-header article))
9714                       " ")))
9715            (setq new-xref (concat (gnus-group-real-name gnus-newsgroup-name)
9716                                   ":" (number-to-string article)))
9717            (unless xref
9718              (setq xref (list (system-name))))
9719            (setq new-xref
9720                  (concat
9721                   (mapconcat 'identity
9722                              (delete "Xref:" (delete new-xref xref))
9723                              " ")
9724                   " " new-xref))
9725            (with-current-buffer copy-buf
9726              ;; First put the article in the destination group.
9727              (gnus-request-article-this-buffer article gnus-newsgroup-name)
9728              (when (consp (setq art-group
9729                                 (gnus-request-accept-article
9730                                  to-newsgroup select-method (not articles) t)))
9731                (setq new-xref (concat new-xref " " (car art-group)
9732                                       ":"
9733                                       (number-to-string (cdr art-group))))
9734                ;; Now we have the new Xrefs header, so we insert
9735                ;; it and replace the new article.
9736                (nnheader-replace-header "Xref" new-xref)
9737                (gnus-request-replace-article
9738                 (cdr art-group) to-newsgroup (current-buffer) t)
9739                art-group))))))
9740       (cond
9741        ((not art-group)
9742         (gnus-message 1 "Couldn't %s article %s: %s"
9743                       (cadr (assq action names)) article
9744                       (nnheader-get-report (car to-method))))
9745        ((eq art-group 'junk)
9746         (when (eq action 'move)
9747           (gnus-summary-mark-article article gnus-canceled-mark)
9748           (gnus-message 4 "Deleted article %s" article)
9749           ;; run the delete hook
9750           (run-hook-with-args 'gnus-summary-article-delete-hook
9751                               action
9752                               (gnus-data-header
9753                                (assoc article (gnus-data-list nil)))
9754                               gnus-newsgroup-name nil
9755                               select-method)))
9756        (t
9757         (let* ((pto-group (gnus-group-prefixed-name
9758                            (car art-group) to-method))
9759                (info (gnus-get-info pto-group))
9760                (to-group (gnus-info-group info))
9761                to-marks)
9762           ;; Update the group that has been moved to.
9763           (when (and info
9764                      (memq action '(move copy)))
9765             (unless (member to-group to-groups)
9766               (push to-group to-groups))
9767
9768             (unless (memq article gnus-newsgroup-unreads)
9769               (push 'read to-marks)
9770               (gnus-info-set-read
9771                info (gnus-add-to-range (gnus-info-read info)
9772                                        (list (cdr art-group)))))
9773
9774             ;; See whether the article is to be put in the cache.
9775             (let* ((expirable (gnus-group-auto-expirable-p to-group))
9776                    (marks (if expirable
9777                               gnus-article-mark-lists
9778                             (delete '(expirable . expire)
9779                                     (copy-sequence gnus-article-mark-lists))))
9780                    (to-article (cdr art-group)))
9781
9782               ;; Enter the article into the cache in the new group,
9783               ;; if that is required.
9784               (when gnus-use-cache
9785                 (gnus-cache-possibly-enter-article
9786                  to-group to-article
9787                  (memq article gnus-newsgroup-marked)
9788                  (memq article gnus-newsgroup-dormant)
9789                  (memq article gnus-newsgroup-unreads)))
9790
9791               (when gnus-preserve-marks
9792                 ;; Copy any marks over to the new group.
9793                 (when (and (equal to-group gnus-newsgroup-name)
9794                            (not (memq article gnus-newsgroup-unreads)))
9795                   ;; Mark this article as read in this group.
9796                   (push (cons to-article gnus-read-mark) gnus-newsgroup-reads)
9797                   (setcdr (gnus-active to-group) to-article)
9798                   (setcdr gnus-newsgroup-active to-article))
9799
9800                 (while marks
9801                   (when (eq (gnus-article-mark-to-type (cdar marks)) 'list)
9802                     (when (memq article (symbol-value
9803                                          (intern (format "gnus-newsgroup-%s"
9804                                                          (caar marks)))))
9805                       (push (cdar marks) to-marks)
9806                       ;; If the other group is the same as this group,
9807                       ;; then we have to add the mark to the list.
9808                       (when (equal to-group gnus-newsgroup-name)
9809                         (set (intern (format "gnus-newsgroup-%s" (caar marks)))
9810                              (cons to-article
9811                                    (symbol-value
9812                                     (intern (format "gnus-newsgroup-%s"
9813                                                     (caar marks)))))))
9814                       ;; Copy the marks to other group.
9815                       (gnus-add-marked-articles
9816                        to-group (cdar marks) (list to-article) info)))
9817                   (setq marks (cdr marks)))
9818
9819                 (when (and expirable
9820                            gnus-mark-copied-or-moved-articles-as-expirable
9821                            (not (memq 'expire to-marks)))
9822                   ;; Mark this article as expirable.
9823                   (push 'expire to-marks)
9824                   (when (equal to-group gnus-newsgroup-name)
9825                     (push to-article gnus-newsgroup-expirable))
9826                   ;; Copy the expirable mark to other group.
9827                   (gnus-add-marked-articles
9828                    to-group 'expire (list to-article) info))
9829
9830                 (gnus-request-set-mark
9831                  to-group (list (list (list to-article) 'add to-marks))))
9832
9833               (gnus-dribble-enter
9834                (concat "(gnus-group-set-info '"
9835                        (gnus-prin1-to-string (gnus-get-info to-group))
9836                        ")"))))
9837
9838           ;; Update the Xref header in this article to point to
9839           ;; the new crossposted article we have just created.
9840           (when (eq action 'crosspost)
9841             (with-current-buffer copy-buf
9842               (gnus-request-article-this-buffer article gnus-newsgroup-name)
9843               (nnheader-replace-header "Xref" new-xref)
9844               (gnus-request-replace-article
9845                article gnus-newsgroup-name (current-buffer) t)))
9846
9847           ;; run the move/copy/crosspost/respool hook
9848           (run-hook-with-args 'gnus-summary-article-move-hook
9849                               action
9850                               (gnus-data-header
9851                                (assoc article (gnus-data-list nil)))
9852                               gnus-newsgroup-name
9853                               to-newsgroup
9854                               select-method))
9855
9856         ;;;!!!Why is this necessary?
9857         (set-buffer gnus-summary-buffer)
9858
9859         (gnus-summary-goto-subject article)
9860         (when (eq action 'move)
9861           (gnus-summary-mark-article article gnus-canceled-mark))))
9862       (push article articles-to-update-marks))
9863
9864     (apply 'gnus-summary-remove-process-mark articles-to-update-marks)
9865     ;; Re-activate all groups that have been moved to.
9866     (with-current-buffer gnus-group-buffer
9867       (let ((gnus-group-marked to-groups))
9868         (gnus-group-get-new-news-this-group nil t)))
9869
9870     (gnus-kill-buffer copy-buf)
9871     (gnus-summary-position-point)
9872     (gnus-set-mode-line 'summary)))
9873
9874 (defun gnus-summary-copy-article (&optional n to-newsgroup select-method)
9875   "Copy the current article to some other group.
9876 If TO-NEWSGROUP is string, do not prompt for a newsgroup to copy to.
9877 When called interactively, if TO-NEWSGROUP is nil, use the value of
9878 the variable `gnus-move-split-methods' for finding a default target
9879 newsgroup.
9880 If SELECT-METHOD is non-nil, do not move to a specific newsgroup, but
9881 re-spool using this method."
9882   (interactive "P")
9883   (gnus-summary-move-article n to-newsgroup select-method 'copy))
9884
9885 (defun gnus-summary-crosspost-article (&optional n)
9886   "Crosspost the current article to some other group."
9887   (interactive "P")
9888   (gnus-summary-move-article n nil nil 'crosspost))
9889
9890 (defcustom gnus-summary-respool-default-method nil
9891   "Default method type for respooling an article.
9892 If nil, use to the current newsgroup method."
9893   :type 'symbol
9894   :group 'gnus-summary-mail)
9895
9896 (defun gnus-summary-respool-article (&optional n method)
9897   "Respool the current article.
9898 The article will be squeezed through the mail spooling process again,
9899 which means that it will be put in some mail newsgroup or other
9900 depending on `nnmail-split-methods'.
9901 If N is a positive number, respool the N next articles.
9902 If N is a negative number, respool the N previous articles.
9903 If N is nil and any articles have been marked with the process mark,
9904 respool those articles instead.
9905
9906 Respooling can be done both from mail groups and \"real\" newsgroups.
9907 In the former case, the articles in question will be moved from the
9908 current group into whatever groups they are destined to.  In the
9909 latter case, they will be copied into the relevant groups."
9910   (interactive
9911    (list current-prefix-arg
9912          (let* ((methods (gnus-methods-using 'respool))
9913                 (methname
9914                  (symbol-name (or gnus-summary-respool-default-method
9915                                   (car (gnus-find-method-for-group
9916                                         gnus-newsgroup-name)))))
9917                 (method
9918                  (gnus-completing-read-with-default
9919                   methname "Backend to use when respooling"
9920                   methods nil t nil 'gnus-mail-method-history))
9921                 ms)
9922            (cond
9923             ((zerop (length (setq ms (gnus-servers-using-backend
9924                                       (intern method)))))
9925              (list (intern method) ""))
9926             ((= 1 (length ms))
9927              (car ms))
9928             (t
9929              (let ((ms-alist (mapcar (lambda (m) (cons (cadr m) m)) ms)))
9930                (cdr (assoc (completing-read "Server name: " ms-alist nil t)
9931                            ms-alist))))))))
9932   (unless method
9933     (error "No method given for respooling"))
9934   (if (assoc (symbol-name
9935               (car (gnus-find-method-for-group gnus-newsgroup-name)))
9936              (gnus-methods-using 'respool))
9937       (gnus-summary-move-article n nil method)
9938     (gnus-summary-copy-article n nil method)))
9939
9940 (defun gnus-summary-import-article (file &optional edit)
9941   "Import an arbitrary file into a mail newsgroup."
9942   (interactive "fImport file: \nP")
9943   (let ((group gnus-newsgroup-name)
9944         (now (current-time))
9945         atts lines group-art)
9946     (unless (gnus-check-backend-function 'request-accept-article group)
9947       (error "%s does not support article importing" group))
9948     (or (file-readable-p file)
9949         (not (file-regular-p file))
9950         (error "Can't read %s" file))
9951     (with-current-buffer (gnus-get-buffer-create " *import file*")
9952       (erase-buffer)
9953       (nnheader-insert-file-contents file)
9954       (goto-char (point-min))
9955       (if (nnheader-article-p)
9956           (save-restriction
9957             (goto-char (point-min))
9958             (search-forward "\n\n" nil t)
9959             (narrow-to-region (point-min) (1- (point)))
9960             (goto-char (point-min))
9961             (unless (re-search-forward "^date:" nil t)
9962               (goto-char (point-max))
9963               (insert "Date: " (message-make-date (nth 5 atts)) "\n")))
9964        ;; This doesn't look like an article, so we fudge some headers.
9965         (setq atts (file-attributes file)
9966               lines (count-lines (point-min) (point-max)))
9967         (insert "From: " (read-string "From: ") "\n"
9968                 "Subject: " (read-string "Subject: ") "\n"
9969                 "Date: " (message-make-date (nth 5 atts)) "\n"
9970                 "Message-ID: " (message-make-message-id) "\n"
9971                 "Lines: " (int-to-string lines) "\n"
9972                 "Chars: " (int-to-string (nth 7 atts)) "\n\n"))
9973       (setq group-art (gnus-request-accept-article group nil t))
9974       (kill-buffer (current-buffer)))
9975     (setq gnus-newsgroup-active (gnus-activate-group group))
9976     (forward-line 1)
9977     (gnus-summary-goto-article (cdr group-art) nil t)
9978     (when edit
9979       (gnus-summary-edit-article))))
9980
9981 (defun gnus-summary-create-article ()
9982   "Create an article in a mail newsgroup."
9983   (interactive)
9984   (let ((group gnus-newsgroup-name)
9985         (now (current-time))
9986         group-art)
9987     (unless (gnus-check-backend-function 'request-accept-article group)
9988       (error "%s does not support article importing" group))
9989     (with-current-buffer (gnus-get-buffer-create " *import file*")
9990       (erase-buffer)
9991       (goto-char (point-min))
9992       ;; This doesn't look like an article, so we fudge some headers.
9993       (insert "From: " (read-string "From: ") "\n"
9994               "Subject: " (read-string "Subject: ") "\n"
9995               "Date: " (message-make-date now) "\n"
9996               "Message-ID: " (message-make-message-id) "\n")
9997       (setq group-art (gnus-request-accept-article group nil t))
9998       (kill-buffer (current-buffer)))
9999     (setq gnus-newsgroup-active (gnus-activate-group group))
10000     (forward-line 1)
10001     (gnus-summary-goto-article (cdr group-art) nil t)
10002     (gnus-summary-edit-article)))
10003
10004 (defun gnus-summary-article-posted-p ()
10005   "Say whether the current (mail) article is available from news as well.
10006 This will be the case if the article has both been mailed and posted."
10007   (interactive)
10008   (let ((id (mail-header-references (gnus-summary-article-header)))
10009         (gnus-override-method (car (gnus-refer-article-methods))))
10010     (if (gnus-request-head id "")
10011         (gnus-message 2 "The current message was found on %s"
10012                       gnus-override-method)
10013       (gnus-message 2 "The current message couldn't be found on %s"
10014                     gnus-override-method)
10015       nil)))
10016
10017 (defun gnus-summary-expire-articles (&optional now)
10018   "Expire all articles that are marked as expirable in the current group."
10019   (interactive)
10020   (when (and (not gnus-group-is-exiting-without-update-p)
10021              (gnus-check-backend-function
10022               'request-expire-articles gnus-newsgroup-name))
10023     ;; This backend supports expiry.
10024     (let* ((total (gnus-group-total-expirable-p gnus-newsgroup-name))
10025            (expirable (if total
10026                           (progn
10027                             ;; We need to update the info for
10028                             ;; this group for `gnus-list-of-read-articles'
10029                             ;; to give us the right answer.
10030                             (gnus-run-hooks 'gnus-exit-group-hook)
10031                             (gnus-summary-update-info)
10032                             (gnus-list-of-read-articles gnus-newsgroup-name))
10033                         (setq gnus-newsgroup-expirable
10034                               (sort gnus-newsgroup-expirable '<))))
10035            (expiry-wait (if now 'immediate
10036                           (gnus-group-find-parameter
10037                            gnus-newsgroup-name 'expiry-wait)))
10038            (nnmail-expiry-target
10039             (or (gnus-group-find-parameter gnus-newsgroup-name 'expiry-target)
10040                 nnmail-expiry-target))
10041            es)
10042       (when expirable
10043         ;; There are expirable articles in this group, so we run them
10044         ;; through the expiry process.
10045         (gnus-message 6 "Expiring articles...")
10046         (unless (gnus-check-group gnus-newsgroup-name)
10047           (error "Can't open server for %s" gnus-newsgroup-name))
10048         ;; The list of articles that weren't expired is returned.
10049         (save-excursion
10050           (if expiry-wait
10051               (let ((nnmail-expiry-wait-function nil)
10052                     (nnmail-expiry-wait expiry-wait))
10053                 (setq es (gnus-request-expire-articles
10054                           expirable gnus-newsgroup-name)))
10055             (setq es (gnus-request-expire-articles
10056                       expirable gnus-newsgroup-name)))
10057           (unless total
10058             (setq gnus-newsgroup-expirable es))
10059           ;; We go through the old list of expirable, and mark all
10060           ;; really expired articles as nonexistent.
10061           (unless (eq es expirable) ;If nothing was expired, we don't mark.
10062             (let ((gnus-use-cache nil))
10063               (dolist (article expirable)
10064                 (when (and (not (memq article es))
10065                            (gnus-data-find article))
10066                   (gnus-summary-mark-article article gnus-canceled-mark)
10067                   (run-hook-with-args 'gnus-summary-article-expire-hook
10068                                       'delete
10069                                       (gnus-data-header
10070                                        (assoc article (gnus-data-list nil)))
10071                                       gnus-newsgroup-name
10072                                       nil
10073                                       nil))))))
10074         (gnus-message 6 "Expiring articles...done")))))
10075
10076 (defun gnus-summary-expire-articles-now ()
10077   "Expunge all expirable articles in the current group.
10078 This means that *all* articles that are marked as expirable will be
10079 deleted forever, right now."
10080   (interactive)
10081   (or gnus-expert-user
10082       (gnus-yes-or-no-p
10083        "Are you really, really sure you want to delete all expirable messages? ")
10084       (error "Phew!"))
10085   (gnus-summary-expire-articles t))
10086
10087 ;; Suggested by Jack Vinson <vinson@unagi.cis.upenn.edu>.
10088 (defun gnus-summary-delete-article (&optional n)
10089   "Delete the N next (mail) articles.
10090 This command actually deletes articles.  This is not a marking
10091 command.  The article will disappear forever from your life, never to
10092 return.
10093
10094 If N is negative, delete backwards.
10095 If N is nil and articles have been marked with the process mark,
10096 delete these instead.
10097
10098 If `gnus-novice-user' is non-nil you will be asked for
10099 confirmation before the articles are deleted."
10100   (interactive "P")
10101   (unless (gnus-check-backend-function 'request-expire-articles
10102                                        gnus-newsgroup-name)
10103     (error "The current newsgroup does not support article deletion"))
10104   (unless (gnus-check-server (gnus-find-method-for-group gnus-newsgroup-name))
10105     (error "Couldn't open server"))
10106   ;; Compute the list of articles to delete.
10107   (let ((articles (sort (copy-sequence (gnus-summary-work-articles n)) '<))
10108         (nnmail-expiry-target 'delete)
10109         not-deleted)
10110     (if (and gnus-novice-user
10111              (not (gnus-yes-or-no-p
10112                    (format "Do you really want to delete %s forever? "
10113                            (if (> (length articles) 1)
10114                                (format "these %s articles" (length articles))
10115                              "this article")))))
10116         ()
10117       ;; Delete the articles.
10118       (setq not-deleted (gnus-request-expire-articles
10119                          articles gnus-newsgroup-name 'force))
10120       (while articles
10121         (gnus-summary-remove-process-mark (car articles))
10122         ;; The backend might not have been able to delete the article
10123         ;; after all.
10124         (unless (memq (car articles) not-deleted)
10125           (gnus-summary-mark-article (car articles) gnus-canceled-mark))
10126         (let* ((article (car articles))
10127                (ghead  (gnus-data-header
10128                                     (assoc article (gnus-data-list nil)))))
10129           (run-hook-with-args 'gnus-summary-article-delete-hook
10130                               'delete ghead gnus-newsgroup-name nil
10131                               nil))
10132         (setq articles (cdr articles)))
10133       (when not-deleted
10134         (gnus-message 4 "Couldn't delete articles %s" not-deleted)))
10135     (gnus-summary-position-point)
10136     (gnus-set-mode-line 'summary)
10137     not-deleted))
10138
10139 (defun gnus-summary-edit-article (&optional arg)
10140   "Edit the current article.
10141 This will have permanent effect only in mail groups.
10142 If ARG is nil, edit the decoded articles.
10143 If ARG is 1, edit the raw articles.
10144 If ARG is 2, edit the raw articles even in read-only groups.
10145 If ARG is 3, edit the articles with the current handles.
10146 Otherwise, allow editing of articles even in read-only
10147 groups."
10148   (interactive "P")
10149   (let (force raw current-handles)
10150     (cond
10151      ((null arg))
10152      ((eq arg 1)
10153       (setq raw t))
10154      ((eq arg 2)
10155       (setq raw t
10156             force t))
10157      ((eq arg 3)
10158       (setq current-handles
10159             (and (gnus-buffer-live-p gnus-article-buffer)
10160                  (with-current-buffer gnus-article-buffer
10161                    (prog1
10162                        gnus-article-mime-handles
10163                      (setq gnus-article-mime-handles nil))))))
10164      (t
10165       (setq force t)))
10166     (when (and raw (not force)
10167                (member gnus-newsgroup-name '("nndraft:delayed"
10168                                              "nndraft:drafts"
10169                                              "nndraft:queue")))
10170       (error "Can't edit the raw article in group %s"
10171              gnus-newsgroup-name))
10172     (with-current-buffer gnus-summary-buffer
10173       (let ((mail-parse-charset gnus-newsgroup-charset)
10174             (mail-parse-ignored-charsets gnus-newsgroup-ignored-charsets))
10175         (gnus-set-global-variables)
10176         (when (and (not force)
10177                    (gnus-group-read-only-p))
10178           (error "The current newsgroup does not support article editing"))
10179         (gnus-summary-show-article t)
10180         (when (and (not raw) (gnus-buffer-live-p gnus-article-buffer))
10181           (with-current-buffer gnus-article-buffer
10182             (mm-enable-multibyte)))
10183         (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
10184             (setq raw t))
10185         (gnus-article-edit-article
10186          (if raw 'ignore
10187            `(lambda ()
10188               (let ((mbl mml-buffer-list))
10189                 (setq mml-buffer-list nil)
10190                 (let ((rfc2047-quote-decoded-words-containing-tspecials t))
10191                   (mime-to-mml ,'current-handles))
10192                 (let ((mbl1 mml-buffer-list))
10193                   (setq mml-buffer-list mbl)
10194                   (set (make-local-variable 'mml-buffer-list) mbl1))
10195                 (gnus-make-local-hook 'kill-buffer-hook)
10196                 (add-hook 'kill-buffer-hook 'mml-destroy-buffers t t))))
10197          `(lambda (no-highlight)
10198             (let ((mail-parse-charset ',gnus-newsgroup-charset)
10199                   (message-options message-options)
10200                   (message-options-set-recipient)
10201                   (mail-parse-ignored-charsets
10202                    ',gnus-newsgroup-ignored-charsets)
10203                   (rfc2047-header-encoding-alist
10204                    ',(let ((charset (gnus-group-name-charset
10205                                      (gnus-find-method-for-group
10206                                       gnus-newsgroup-name)
10207                                      gnus-newsgroup-name)))
10208                        (append (list (cons "Newsgroups" charset)
10209                                      (cons "Followup-To" charset)
10210                                      (cons "Xref" charset))
10211                                rfc2047-header-encoding-alist))))
10212               ,(if (not raw) '(progn
10213                                 (mml-to-mime)
10214                                 (mml-destroy-buffers)
10215                                 (remove-hook 'kill-buffer-hook
10216                                              'mml-destroy-buffers t)
10217                                 (kill-local-variable 'mml-buffer-list)))
10218               (gnus-summary-edit-article-done
10219                ,(or (mail-header-references gnus-current-headers) "")
10220                ,(gnus-group-read-only-p)
10221                ,gnus-summary-buffer no-highlight))))))))
10222
10223 (defalias 'gnus-summary-edit-article-postpone 'gnus-article-edit-exit)
10224
10225 (defun gnus-summary-edit-article-done (&optional references read-only buffer
10226                                                  no-highlight)
10227   "Make edits to the current article permanent."
10228   (interactive)
10229   (save-excursion
10230    ;; The buffer restriction contains the entire article if it exists.
10231     (when (article-goto-body)
10232       (let ((lines (count-lines (point) (point-max)))
10233             (length (- (point-max) (point)))
10234             (case-fold-search t)
10235             (body (copy-marker (point))))
10236         (goto-char (point-min))
10237         (when (re-search-forward "^content-length:[ \t]\\([0-9]+\\)" body t)
10238           (delete-region (match-beginning 1) (match-end 1))
10239           (insert (number-to-string length)))
10240         (goto-char (point-min))
10241         (when (re-search-forward
10242                "^x-content-length:[ \t]\\([0-9]+\\)" body t)
10243           (delete-region (match-beginning 1) (match-end 1))
10244           (insert (number-to-string length)))
10245         (goto-char (point-min))
10246         (when (re-search-forward "^lines:[ \t]\\([0-9]+\\)" body t)
10247           (delete-region (match-beginning 1) (match-end 1))
10248           (insert (number-to-string lines))))))
10249   ;; Replace the article.
10250   (let ((buf (current-buffer)))
10251     (with-temp-buffer
10252       (insert-buffer-substring buf)
10253
10254       (if (and (not read-only)
10255                (not (gnus-request-replace-article
10256                      (cdr gnus-article-current) (car gnus-article-current)
10257                      (current-buffer) t)))
10258           (error "Couldn't replace article")
10259         ;; Update the summary buffer.
10260         (if (and references
10261                  (equal (message-tokenize-header references " ")
10262                         (message-tokenize-header
10263                          (or (message-fetch-field "references") "") " ")))
10264             ;; We only have to update this line.
10265             (save-excursion
10266               (save-restriction
10267                 (message-narrow-to-head)
10268                 (let ((head (buffer-substring-no-properties
10269                              (point-min) (point-max)))
10270                       header)
10271                   (with-temp-buffer
10272                     (insert (format "211 %d Article retrieved.\n"
10273                                     (cdr gnus-article-current)))
10274                     (insert head)
10275                     (insert ".\n")
10276                     (let ((nntp-server-buffer (current-buffer)))
10277                       (setq header (car (gnus-get-newsgroup-headers
10278                                          nil t))))
10279                     (with-current-buffer gnus-summary-buffer
10280                       (gnus-data-set-header
10281                        (gnus-data-find (cdr gnus-article-current))
10282                        header)
10283                       (gnus-summary-update-article-line
10284                        (cdr gnus-article-current) header)
10285                       (if (gnus-summary-goto-subject
10286                            (cdr gnus-article-current) nil t)
10287                           (gnus-summary-update-secondary-mark
10288                            (cdr gnus-article-current))))))))
10289           ;; Update threads.
10290           (set-buffer (or buffer gnus-summary-buffer))
10291           (gnus-summary-update-article (cdr gnus-article-current))
10292           (if (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
10293               (gnus-summary-update-secondary-mark
10294                (cdr gnus-article-current))))
10295         ;; Prettify the article buffer again.
10296         (unless no-highlight
10297           (with-current-buffer gnus-article-buffer
10298             ;;;!!! Fix this -- article should be rehighlighted.
10299             ;;;(gnus-run-hooks 'gnus-article-display-hook)
10300             (set-buffer gnus-original-article-buffer)
10301             (gnus-request-article
10302              (cdr gnus-article-current)
10303              (car gnus-article-current) (current-buffer))))
10304         ;; Prettify the summary buffer line.
10305         (when (gnus-visual-p 'summary-highlight 'highlight)
10306           (gnus-run-hooks 'gnus-visual-mark-article-hook))))))
10307
10308 (defun gnus-summary-edit-wash (key)
10309   "Perform editing command KEY in the article buffer."
10310   (interactive
10311    (list
10312     (progn
10313       (message "%s" (concat (this-command-keys) "- "))
10314       (read-char))))
10315   (message "")
10316   (gnus-summary-edit-article)
10317   (execute-kbd-macro (concat (this-command-keys) key))
10318   (gnus-article-edit-done))
10319
10320 ;;; Respooling
10321
10322 (defun gnus-summary-respool-query (&optional silent trace)
10323   "Query where the respool algorithm would put this article."
10324   (interactive)
10325   (let (gnus-mark-article-hook)
10326     (gnus-summary-select-article)
10327     (with-current-buffer gnus-original-article-buffer
10328       (let ((groups (nnmail-article-group 'identity trace)))
10329         (unless silent
10330           (if groups
10331               (message "This message would go to %s"
10332                        (mapconcat 'car groups ", "))
10333             (message "This message would go to no groups"))
10334           groups)))))
10335
10336 (defun gnus-summary-respool-trace ()
10337   "Trace where the respool algorithm would put this article.
10338 Display a buffer showing all fancy splitting patterns which matched."
10339   (interactive)
10340   (gnus-summary-respool-query nil t))
10341
10342 ;; Summary marking commands.
10343
10344 (defun gnus-summary-kill-same-subject-and-select (&optional unmark)
10345   "Mark articles which has the same subject as read, and then select the next.
10346 If UNMARK is positive, remove any kind of mark.
10347 If UNMARK is negative, tick articles."
10348   (interactive "P")
10349   (when unmark
10350     (setq unmark (prefix-numeric-value unmark)))
10351   (let ((count
10352          (gnus-summary-mark-same-subject
10353           (gnus-summary-article-subject) unmark)))
10354     ;; Select next unread article.  If auto-select-same mode, should
10355     ;; select the first unread article.
10356     (gnus-summary-next-article t (and gnus-auto-select-same
10357                                       (gnus-summary-article-subject)))
10358     (gnus-message 7 "%d article%s marked as %s"
10359                   count (if (= count 1) " is" "s are")
10360                   (if unmark "unread" "read"))))
10361
10362 (defun gnus-summary-kill-same-subject (&optional unmark)
10363   "Mark articles which has the same subject as read.
10364 If UNMARK is positive, remove any kind of mark.
10365 If UNMARK is negative, tick articles."
10366   (interactive "P")
10367   (when unmark
10368     (setq unmark (prefix-numeric-value unmark)))
10369   (let ((count
10370          (gnus-summary-mark-same-subject
10371           (gnus-summary-article-subject) unmark)))
10372     ;; If marked as read, go to next unread subject.
10373     (when (null unmark)
10374       ;; Go to next unread subject.
10375       (gnus-summary-next-subject 1 t))
10376     (gnus-message 7 "%d articles are marked as %s"
10377                   count (if unmark "unread" "read"))))
10378
10379 (defun gnus-summary-mark-same-subject (subject &optional unmark)
10380   "Mark articles with same SUBJECT as read, and return marked number.
10381 If optional argument UNMARK is positive, remove any kinds of marks.
10382 If optional argument UNMARK is negative, mark articles as unread instead."
10383   (let ((count 1))
10384     (save-excursion
10385       (cond
10386        ((null unmark)                   ; Mark as read.
10387         (while (and
10388                 (progn
10389                   (gnus-summary-mark-article-as-read gnus-killed-mark)
10390                   (gnus-summary-show-thread) t)
10391                 (gnus-summary-find-subject subject))
10392           (setq count (1+ count))))
10393        ((> unmark 0)                    ; Tick.
10394         (while (and
10395                 (progn
10396                   (gnus-summary-mark-article-as-unread gnus-ticked-mark)
10397                   (gnus-summary-show-thread) t)
10398                 (gnus-summary-find-subject subject))
10399           (setq count (1+ count))))
10400        (t                               ; Mark as unread.
10401         (while (and
10402                 (progn
10403                   (gnus-summary-mark-article-as-unread gnus-unread-mark)
10404                   (gnus-summary-show-thread) t)
10405                 (gnus-summary-find-subject subject))
10406           (setq count (1+ count)))))
10407       (gnus-set-mode-line 'summary)
10408       ;; Return the number of marked articles.
10409       count)))
10410
10411 (defun gnus-summary-mark-as-processable (n &optional unmark)
10412   "Set the process mark on the next N articles.
10413 If N is negative, mark backward instead.  If UNMARK is non-nil, remove
10414 the process mark instead.  The difference between N and the actual
10415 number of articles marked is returned."
10416   (interactive "P")
10417   (if (and (null n) (gnus-region-active-p))
10418       (gnus-uu-mark-region (region-beginning) (region-end) unmark)
10419     (setq n (prefix-numeric-value n))
10420     (let ((backward (< n 0))
10421           (n (abs n)))
10422       (while (and
10423               (> n 0)
10424               (if unmark
10425                   (gnus-summary-remove-process-mark
10426                    (gnus-summary-article-number))
10427                 (gnus-summary-set-process-mark (gnus-summary-article-number)))
10428               (zerop (gnus-summary-next-subject (if backward -1 1) nil t)))
10429         (setq n (1- n)))
10430       (when (/= 0 n)
10431         (gnus-message 7 "No more articles"))
10432       (gnus-summary-recenter)
10433       (gnus-summary-position-point)
10434       n)))
10435
10436 (defun gnus-summary-unmark-as-processable (n)
10437   "Remove the process mark from the next N articles.
10438 If N is negative, unmark backward instead.  The difference between N and
10439 the actual number of articles unmarked is returned."
10440   (interactive "P")
10441   (gnus-summary-mark-as-processable n t))
10442
10443 (defun gnus-summary-unmark-all-processable ()
10444   "Remove the process mark from all articles."
10445   (interactive)
10446   (save-excursion
10447     (while gnus-newsgroup-processable
10448       (gnus-summary-remove-process-mark (car gnus-newsgroup-processable))))
10449   (gnus-summary-position-point))
10450
10451 (defun gnus-summary-add-mark (article type)
10452   "Mark ARTICLE with a mark of TYPE."
10453   (let ((vtype (car (assq type gnus-article-mark-lists)))
10454         var)
10455     (if (not vtype)
10456         (error "No such mark type: %s" type)
10457       (setq var (intern (format "gnus-newsgroup-%s" type)))
10458       (set var (cons article (symbol-value var)))
10459       (if (memq type '(processable cached replied forwarded recent saved))
10460           (gnus-summary-update-secondary-mark article)
10461         ;;; !!! This is bogus.  We should find out what primary
10462         ;;; !!! mark we want to set.
10463         (gnus-summary-update-mark gnus-del-mark 'unread)))))
10464
10465 (defun gnus-summary-mark-as-expirable (n)
10466   "Mark N articles forward as expirable.
10467 If N is negative, mark backward instead.  The difference between N and
10468 the actual number of articles marked is returned."
10469   (interactive "p")
10470   (gnus-summary-mark-forward n gnus-expirable-mark))
10471
10472 (defun gnus-summary-mark-as-spam (n)
10473   "Mark N articles forward as spam.
10474 If N is negative, mark backward instead.  The difference between N and
10475 the actual number of articles marked is returned."
10476   (interactive "p")
10477   (gnus-summary-mark-forward n gnus-spam-mark))
10478
10479 (defun gnus-summary-mark-article-as-replied (article)
10480   "Mark ARTICLE as replied to and update the summary line.
10481 ARTICLE can also be a list of articles."
10482   (interactive (list (gnus-summary-article-number)))
10483   (let ((articles (if (listp article) article (list article))))
10484     (dolist (article articles)
10485       (unless (numberp article)
10486         (error "%s is not a number" article))
10487       (push article gnus-newsgroup-replied)
10488       (let ((inhibit-read-only t))
10489         (when (gnus-summary-goto-subject article nil t)
10490           (gnus-summary-update-secondary-mark article))))))
10491
10492 (defun gnus-summary-mark-article-as-forwarded (article)
10493   "Mark ARTICLE as forwarded and update the summary line.
10494 ARTICLE can also be a list of articles."
10495   (let ((articles (if (listp article) article (list article))))
10496     (dolist (article articles)
10497       (push article gnus-newsgroup-forwarded)
10498       (let ((inhibit-read-only t))
10499         (when (gnus-summary-goto-subject article nil t)
10500           (gnus-summary-update-secondary-mark article))))))
10501
10502 (defun gnus-summary-set-bookmark (article)
10503   "Set a bookmark in current article."
10504   (interactive (list (gnus-summary-article-number)))
10505   (when (or (not (get-buffer gnus-article-buffer))
10506             (not gnus-current-article)
10507             (not gnus-article-current)
10508             (not (equal gnus-newsgroup-name (car gnus-article-current))))
10509     (error "No current article selected"))
10510   ;; Remove old bookmark, if one exists.
10511   (gnus-pull article gnus-newsgroup-bookmarks)
10512   ;; Set the new bookmark, which is on the form
10513   ;; (article-number . line-number-in-body).
10514   (push
10515    (cons article
10516          (with-current-buffer gnus-article-buffer
10517            (count-lines
10518             (min (point)
10519                  (save-excursion
10520                    (article-goto-body)
10521                    (point)))
10522             (point))))
10523    gnus-newsgroup-bookmarks)
10524   (gnus-message 6 "A bookmark has been added to the current article."))
10525
10526 (defun gnus-summary-remove-bookmark (article)
10527   "Remove the bookmark from the current article."
10528   (interactive (list (gnus-summary-article-number)))
10529   ;; Remove old bookmark, if one exists.
10530   (if (not (assq article gnus-newsgroup-bookmarks))
10531       (gnus-message 6 "No bookmark in current article.")
10532     (gnus-pull article gnus-newsgroup-bookmarks)
10533     (gnus-message 6 "Removed bookmark.")))
10534
10535 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10536 (defun gnus-summary-mark-as-dormant (n)
10537   "Mark N articles forward as dormant.
10538 If N is negative, mark backward instead.  The difference between N and
10539 the actual number of articles marked is returned."
10540   (interactive "p")
10541   (gnus-summary-mark-forward n gnus-dormant-mark))
10542
10543 (defun gnus-summary-set-process-mark (article)
10544   "Set the process mark on ARTICLE and update the summary line."
10545   (setq gnus-newsgroup-processable
10546         (cons article
10547               (delq article gnus-newsgroup-processable)))
10548   (when (gnus-summary-goto-subject article)
10549     (gnus-summary-show-thread)
10550     (gnus-summary-goto-subject article)
10551     (gnus-summary-update-secondary-mark article)))
10552
10553 (defun gnus-summary-remove-process-mark (&rest articles)
10554   "Remove the process mark from ARTICLES and update the summary line."
10555   (dolist (article articles)
10556     (setq gnus-newsgroup-processable (delq article gnus-newsgroup-processable))
10557     (when (gnus-summary-goto-subject article)
10558       (gnus-summary-show-thread)
10559       (gnus-summary-goto-subject article)
10560       (gnus-summary-update-secondary-mark article)))
10561   t)
10562
10563 (defun gnus-summary-set-saved-mark (article)
10564   "Set the process mark on ARTICLE and update the summary line."
10565   (push article gnus-newsgroup-saved)
10566   (when (gnus-summary-goto-subject article)
10567     (gnus-summary-update-secondary-mark article)))
10568
10569 (defun gnus-summary-mark-forward (n &optional mark no-expire)
10570   "Mark N articles as read forwards.
10571 If N is negative, mark backwards instead.  Mark with MARK, ?r by default.
10572 The difference between N and the actual number of articles marked is
10573 returned.
10574 If NO-EXPIRE, auto-expiry will be inhibited."
10575   (interactive "p")
10576   (gnus-summary-show-thread)
10577   (let ((backward (< n 0))
10578         (gnus-summary-goto-unread
10579          (and gnus-summary-goto-unread
10580               (not (eq gnus-summary-goto-unread 'never))
10581               (not (memq mark (list gnus-unread-mark gnus-spam-mark
10582                                     gnus-ticked-mark gnus-dormant-mark)))))
10583         (n (abs n))
10584         (mark (or mark gnus-del-mark)))
10585     (while (and (> n 0)
10586                 (gnus-summary-mark-article nil mark no-expire)
10587                 (zerop (gnus-summary-next-subject
10588                         (if backward -1 1)
10589                         (and gnus-summary-goto-unread
10590                              (not (eq gnus-summary-goto-unread 'never)))
10591                         t)))
10592       (setq n (1- n)))
10593     (when (/= 0 n)
10594       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
10595     (gnus-summary-recenter)
10596     (gnus-summary-position-point)
10597     (gnus-set-mode-line 'summary)
10598     n))
10599
10600 (defun gnus-summary-mark-article-as-read (mark)
10601   "Mark the current article quickly as read with MARK."
10602   (let ((article (gnus-summary-article-number)))
10603     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10604     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10605     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10606     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10607     (push (cons article mark) gnus-newsgroup-reads)
10608     ;; Possibly remove from cache, if that is used.
10609     (when gnus-use-cache
10610       (gnus-cache-enter-remove-article article))
10611     ;; Allow the backend to change the mark.
10612     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10613     ;; Check for auto-expiry.
10614     (when (and gnus-newsgroup-auto-expire
10615                (memq mark gnus-auto-expirable-marks))
10616       (setq mark gnus-expirable-mark)
10617       ;; Let the backend know about the mark change.
10618       (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10619       (push article gnus-newsgroup-expirable))
10620     ;; Set the mark in the buffer.
10621     (gnus-summary-update-mark mark 'unread)
10622     t))
10623
10624 (defun gnus-summary-mark-article-as-unread (mark)
10625   "Mark the current article quickly as unread with MARK."
10626   (let* ((article (gnus-summary-article-number))
10627          (old-mark (gnus-summary-article-mark article)))
10628     ;; Allow the backend to change the mark.
10629     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10630     (if (eq mark old-mark)
10631         t
10632       (if (<= article 0)
10633           (progn
10634             (gnus-error 1 "Can't mark negative article numbers")
10635             nil)
10636         (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10637         (setq gnus-newsgroup-spam-marked
10638               (delq article gnus-newsgroup-spam-marked))
10639         (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10640         (setq gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable))
10641         (setq gnus-newsgroup-reads (delq article gnus-newsgroup-reads))
10642         (cond ((= mark gnus-ticked-mark)
10643                (setq gnus-newsgroup-marked
10644                      (gnus-add-to-sorted-list gnus-newsgroup-marked
10645                                               article)))
10646               ((= mark gnus-spam-mark)
10647                (setq gnus-newsgroup-spam-marked
10648                      (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10649                                               article)))
10650               ((= mark gnus-dormant-mark)
10651                (setq gnus-newsgroup-dormant
10652                      (gnus-add-to-sorted-list gnus-newsgroup-dormant
10653                                               article)))
10654               (t
10655                (setq gnus-newsgroup-unreads
10656                      (gnus-add-to-sorted-list gnus-newsgroup-unreads
10657                                               article))))
10658         (gnus-pull article gnus-newsgroup-reads)
10659
10660         ;; See whether the article is to be put in the cache.
10661         (and gnus-use-cache
10662              (vectorp (gnus-summary-article-header article))
10663              (save-excursion
10664                (gnus-cache-possibly-enter-article
10665                 gnus-newsgroup-name article
10666                 (= mark gnus-ticked-mark)
10667                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10668
10669         ;; Fix the mark.
10670         (gnus-summary-update-mark mark 'unread)
10671         t))))
10672
10673 (defun gnus-summary-mark-article (&optional article mark no-expire)
10674   "Mark ARTICLE with MARK.  MARK can be any character.
10675 Four MARK strings are reserved: `? ' (unread), `?!' (ticked),
10676 `??' (dormant) and `?E' (expirable).
10677 If MARK is nil, then the default character `?r' is used.
10678 If ARTICLE is nil, then the article on the current line will be
10679 marked.
10680 If NO-EXPIRE, auto-expiry will be inhibited."
10681   ;; The mark might be a string.
10682   (when (stringp mark)
10683     (setq mark (aref mark 0)))
10684   ;; If no mark is given, then we check auto-expiring.
10685   (when (null mark)
10686     (setq mark gnus-del-mark))
10687   (when (and (not no-expire)
10688              gnus-newsgroup-auto-expire
10689              (memq mark gnus-auto-expirable-marks))
10690     (setq mark gnus-expirable-mark))
10691   (let ((article (or article (gnus-summary-article-number)))
10692         (old-mark (gnus-summary-article-mark article)))
10693     ;; Allow the backend to change the mark.
10694     (setq mark (gnus-request-update-mark gnus-newsgroup-name article mark))
10695     (if (eq mark old-mark)
10696         t
10697       (unless article
10698         (error "No article on current line"))
10699       (if (not (if (or (= mark gnus-unread-mark)
10700                        (= mark gnus-ticked-mark)
10701                        (= mark gnus-spam-mark)
10702                        (= mark gnus-dormant-mark))
10703                    (gnus-mark-article-as-unread article mark)
10704                  (gnus-mark-article-as-read article mark)))
10705           t
10706         ;; See whether the article is to be put in the cache.
10707         (and gnus-use-cache
10708              (not (= mark gnus-canceled-mark))
10709              (vectorp (gnus-summary-article-header article))
10710              (save-excursion
10711                (gnus-cache-possibly-enter-article
10712                 gnus-newsgroup-name article
10713                 (= mark gnus-ticked-mark)
10714                 (= mark gnus-dormant-mark) (= mark gnus-unread-mark))))
10715
10716         (when (gnus-summary-goto-subject article nil t)
10717           (let ((inhibit-read-only t))
10718             (gnus-summary-show-thread)
10719             ;; Fix the mark.
10720             (gnus-summary-update-mark mark 'unread)
10721             t))))))
10722
10723 (defun gnus-summary-update-secondary-mark (article)
10724   "Update the secondary (read, process, cache) mark."
10725   (gnus-summary-update-mark
10726    (cond ((memq article gnus-newsgroup-processable)
10727           gnus-process-mark)
10728          ((memq article gnus-newsgroup-cached)
10729           gnus-cached-mark)
10730          ((memq article gnus-newsgroup-replied)
10731           gnus-replied-mark)
10732          ((memq article gnus-newsgroup-forwarded)
10733           gnus-forwarded-mark)
10734          ((memq article gnus-newsgroup-saved)
10735           gnus-saved-mark)
10736          ((memq article gnus-newsgroup-recent)
10737           gnus-recent-mark)
10738          ((memq article gnus-newsgroup-unseen)
10739           gnus-unseen-mark)
10740          (t gnus-no-mark))
10741    'replied)
10742   (when (gnus-visual-p 'summary-highlight 'highlight)
10743     (gnus-run-hooks 'gnus-summary-update-hook))
10744   t)
10745
10746 (defun gnus-summary-update-download-mark (article)
10747   "Update the download mark."
10748   (gnus-summary-update-mark
10749    (cond ((memq article gnus-newsgroup-undownloaded)
10750           gnus-undownloaded-mark)
10751          (gnus-newsgroup-agentized
10752           gnus-downloaded-mark)
10753          (t
10754           gnus-no-mark))
10755    'download)
10756   (gnus-summary-update-line t)
10757   t)
10758
10759 (defun gnus-summary-update-mark (mark type)
10760   (let ((forward (cdr (assq type gnus-summary-mark-positions)))
10761         (inhibit-read-only t))
10762     (re-search-backward "[\n\r]" (point-at-bol) 'move-to-limit)
10763     (when forward
10764       (when (looking-at "\r")
10765         (incf forward))
10766       (when (<= (+ forward (point)) (point-max))
10767         ;; Go to the right position on the line.
10768         (goto-char (+ forward (point)))
10769         ;; Replace the old mark with the new mark.
10770         (subst-char-in-region (point) (1+ (point)) (char-after) mark)
10771         ;; Optionally update the marks by some user rule.
10772         (when (eq type 'unread)
10773           (gnus-data-set-mark
10774            (gnus-data-find (gnus-summary-article-number)) mark)
10775           (gnus-summary-update-line (eq mark gnus-unread-mark)))))))
10776
10777 (defun gnus-mark-article-as-read (article &optional mark)
10778   "Enter ARTICLE in the pertinent lists and remove it from others."
10779   ;; Make the article expirable.
10780   (let ((mark (or mark gnus-del-mark)))
10781     (setq gnus-newsgroup-expirable
10782           (if (= mark gnus-expirable-mark)
10783               (gnus-add-to-sorted-list gnus-newsgroup-expirable article)
10784             (delq article gnus-newsgroup-expirable)))
10785     ;; Remove from unread and marked lists.
10786     (setq gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10787     (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked))
10788     (setq gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked))
10789     (setq gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant))
10790     (push (cons article mark) gnus-newsgroup-reads)
10791     ;; Possibly remove from cache, if that is used.
10792     (when gnus-use-cache
10793       (gnus-cache-enter-remove-article article))
10794     t))
10795
10796 (defun gnus-mark-article-as-unread (article &optional mark)
10797   "Enter ARTICLE in the pertinent lists and remove it from others."
10798   (let ((mark (or mark gnus-ticked-mark)))
10799     (if (<= article 0)
10800         (progn
10801           (gnus-error 1 "Can't mark negative article numbers")
10802           nil)
10803       (setq gnus-newsgroup-marked (delq article gnus-newsgroup-marked)
10804             gnus-newsgroup-spam-marked (delq article gnus-newsgroup-spam-marked)
10805             gnus-newsgroup-dormant (delq article gnus-newsgroup-dormant)
10806             gnus-newsgroup-expirable (delq article gnus-newsgroup-expirable)
10807             gnus-newsgroup-unreads (delq article gnus-newsgroup-unreads))
10808
10809       ;; Unsuppress duplicates?
10810       (when gnus-suppress-duplicates
10811         (gnus-dup-unsuppress-article article))
10812
10813       (cond ((= mark gnus-ticked-mark)
10814              (setq gnus-newsgroup-marked
10815                    (gnus-add-to-sorted-list gnus-newsgroup-marked article)))
10816             ((= mark gnus-spam-mark)
10817              (setq gnus-newsgroup-spam-marked
10818                    (gnus-add-to-sorted-list gnus-newsgroup-spam-marked
10819                                             article)))
10820             ((= mark gnus-dormant-mark)
10821              (setq gnus-newsgroup-dormant
10822                    (gnus-add-to-sorted-list gnus-newsgroup-dormant article)))
10823             (t
10824              (setq gnus-newsgroup-unreads
10825                    (gnus-add-to-sorted-list gnus-newsgroup-unreads article))))
10826       (gnus-pull article gnus-newsgroup-reads)
10827       t)))
10828
10829 (defalias 'gnus-summary-mark-as-unread-forward
10830   'gnus-summary-tick-article-forward)
10831 (make-obsolete 'gnus-summary-mark-as-unread-forward
10832                'gnus-summary-tick-article-forward "Emacs 20.4")
10833 (defun gnus-summary-tick-article-forward (n)
10834   "Tick N articles forwards.
10835 If N is negative, tick backwards instead.
10836 The difference between N and the number of articles ticked is returned."
10837   (interactive "p")
10838   (gnus-summary-mark-forward n gnus-ticked-mark))
10839
10840 (defalias 'gnus-summary-mark-as-unread-backward
10841   'gnus-summary-tick-article-backward)
10842 (make-obsolete 'gnus-summary-mark-as-unread-backward
10843                'gnus-summary-tick-article-backward "Emacs 20.4")
10844 (defun gnus-summary-tick-article-backward (n)
10845   "Tick N articles backwards.
10846 The difference between N and the number of articles ticked is returned."
10847   (interactive "p")
10848   (gnus-summary-mark-forward (- n) gnus-ticked-mark))
10849
10850 (defalias 'gnus-summary-mark-as-unread 'gnus-summary-tick-article)
10851 (make-obsolete 'gnus-summary-mark-as-unread 'gnus-summary-tick-article "Emacs 20.4")
10852 (defun gnus-summary-tick-article (&optional article clear-mark)
10853   "Mark current article as unread.
10854 Optional 1st argument ARTICLE specifies article number to be marked as unread.
10855 Optional 2nd argument CLEAR-MARK remove any kinds of mark."
10856   (interactive)
10857   (gnus-summary-mark-article article (if clear-mark gnus-unread-mark
10858                                        gnus-ticked-mark)))
10859
10860 (defun gnus-summary-mark-as-read-forward (n)
10861   "Mark N articles as read forwards.
10862 If N is negative, mark backwards instead.
10863 The difference between N and the actual number of articles marked is
10864 returned."
10865   (interactive "p")
10866   (gnus-summary-mark-forward n gnus-del-mark gnus-inhibit-user-auto-expire))
10867
10868 (defun gnus-summary-mark-as-read-backward (n)
10869   "Mark the N articles as read backwards.
10870 The difference between N and the actual number of articles marked is
10871 returned."
10872   (interactive "p")
10873   (gnus-summary-mark-forward
10874    (- n) gnus-del-mark gnus-inhibit-user-auto-expire))
10875
10876 (defun gnus-summary-mark-as-read (&optional article mark)
10877   "Mark current article as read.
10878 ARTICLE specifies the article to be marked as read.
10879 MARK specifies a string to be inserted at the beginning of the line."
10880   (gnus-summary-mark-article article mark))
10881
10882 (defun gnus-summary-clear-mark-forward (n)
10883   "Clear marks from N articles forward.
10884 If N is negative, clear backward instead.
10885 The difference between N and the number of marks cleared is returned."
10886   (interactive "p")
10887   (gnus-summary-mark-forward n gnus-unread-mark))
10888
10889 (defun gnus-summary-clear-mark-backward (n)
10890   "Clear marks from N articles backward.
10891 The difference between N and the number of marks cleared is returned."
10892   (interactive "p")
10893   (gnus-summary-mark-forward (- n) gnus-unread-mark))
10894
10895 (defun gnus-summary-mark-unread-as-read ()
10896   "Intended to be used by `gnus-mark-article-hook'."
10897   (when (memq gnus-current-article gnus-newsgroup-unreads)
10898     (gnus-summary-mark-article gnus-current-article gnus-read-mark)))
10899
10900 (defun gnus-summary-mark-read-and-unread-as-read (&optional new-mark)
10901   "Intended to be used by `gnus-mark-article-hook'."
10902   (let ((mark (gnus-summary-article-mark)))
10903     (when (or (gnus-unread-mark-p mark)
10904               (gnus-read-mark-p mark))
10905       (gnus-summary-mark-article gnus-current-article
10906                                  (or new-mark gnus-read-mark)))))
10907
10908 (defun gnus-summary-mark-current-read-and-unread-as-read (&optional new-mark)
10909   "Intended to be used by `gnus-mark-article-hook'."
10910   (let ((mark (gnus-summary-article-mark)))
10911     (when (or (gnus-unread-mark-p mark)
10912               (gnus-read-mark-p mark))
10913       (gnus-summary-mark-article (gnus-summary-article-number)
10914                                  (or new-mark gnus-read-mark)))))
10915
10916 (defun gnus-summary-mark-unread-as-ticked ()
10917   "Intended to be used by `gnus-mark-article-hook'."
10918   (when (memq gnus-current-article gnus-newsgroup-unreads)
10919     (gnus-summary-mark-article gnus-current-article gnus-ticked-mark)))
10920
10921 (defun gnus-summary-mark-region-as-read (point mark all)
10922   "Mark all unread articles between point and mark as read.
10923 If given a prefix, mark all articles between point and mark as read,
10924 even ticked and dormant ones."
10925   (interactive "r\nP")
10926   (save-excursion
10927     (let (article)
10928       (goto-char point)
10929       (beginning-of-line)
10930       (while (and
10931               (< (point) mark)
10932               (progn
10933                 (when (or all
10934                           (memq (setq article (gnus-summary-article-number))
10935                                 gnus-newsgroup-unreads))
10936                   (gnus-summary-mark-article article gnus-del-mark))
10937                 t)
10938               (gnus-summary-find-next))))))
10939
10940 (defun gnus-summary-mark-below (score mark)
10941   "Mark articles with score less than SCORE with MARK."
10942   (interactive "P\ncMark: ")
10943   (setq score (if score
10944                   (prefix-numeric-value score)
10945                 (or gnus-summary-default-score 0)))
10946   (with-current-buffer gnus-summary-buffer
10947     (goto-char (point-min))
10948     (while
10949         (progn
10950           (and (< (gnus-summary-article-score) score)
10951                (gnus-summary-mark-article nil mark))
10952           (gnus-summary-find-next)))))
10953
10954 (defun gnus-summary-kill-below (&optional score)
10955   "Mark articles with score below SCORE as read."
10956   (interactive "P")
10957   (gnus-summary-mark-below score gnus-killed-mark))
10958
10959 (defun gnus-summary-clear-above (&optional score)
10960   "Clear all marks from articles with score above SCORE."
10961   (interactive "P")
10962   (gnus-summary-mark-above score gnus-unread-mark))
10963
10964 (defun gnus-summary-tick-above (&optional score)
10965   "Tick all articles with score above SCORE."
10966   (interactive "P")
10967   (gnus-summary-mark-above score gnus-ticked-mark))
10968
10969 (defun gnus-summary-mark-above (score mark)
10970   "Mark articles with score over SCORE with MARK."
10971   (interactive "P\ncMark: ")
10972   (setq score (if score
10973                   (prefix-numeric-value score)
10974                 (or gnus-summary-default-score 0)))
10975   (with-current-buffer gnus-summary-buffer
10976     (goto-char (point-min))
10977     (while (and (progn
10978                   (when (> (gnus-summary-article-score) score)
10979                     (gnus-summary-mark-article nil mark))
10980                   t)
10981                 (gnus-summary-find-next)))))
10982
10983 ;; Suggested by Daniel Quinlan <quinlan@best.com>.
10984 (defalias 'gnus-summary-show-all-expunged 'gnus-summary-limit-include-expunged)
10985 (defun gnus-summary-limit-include-expunged (&optional no-error)
10986   "Display all the hidden articles that were expunged for low scores."
10987   (interactive)
10988   (let ((inhibit-read-only t))
10989     (let ((scored gnus-newsgroup-scored)
10990           headers h)
10991       (while scored
10992         (unless (gnus-summary-article-header (caar scored))
10993           (and (setq h (gnus-number-to-header (caar scored)))
10994                (< (cdar scored) gnus-summary-expunge-below)
10995                (push h headers)))
10996         (setq scored (cdr scored)))
10997       (if (not headers)
10998           (when (not no-error)
10999             (error "No expunged articles hidden"))
11000         (goto-char (point-min))
11001         (push gnus-newsgroup-limit gnus-newsgroup-limits)
11002         (setq gnus-newsgroup-limit (copy-sequence gnus-newsgroup-limit))
11003         (dolist (x headers)
11004           (push (mail-header-number x) gnus-newsgroup-limit))
11005         (gnus-summary-prepare-unthreaded (nreverse headers))
11006         (goto-char (point-min))
11007         (gnus-summary-position-point)
11008         t))))
11009
11010 (defun gnus-summary-catchup (&optional all quietly to-here not-mark reverse)
11011   "Mark all unread articles in this newsgroup as read.
11012 If prefix argument ALL is non-nil, ticked and dormant articles will
11013 also be marked as read.
11014 If QUIETLY is non-nil, no questions will be asked.
11015
11016 If TO-HERE is non-nil, it should be a point in the buffer.  All
11017 articles before (after, if REVERSE is set) this point will be marked
11018 as read.
11019
11020 Note that this function will only catch up the unread article
11021 in the current summary buffer limitation.
11022
11023 The number of articles marked as read is returned."
11024   (interactive "P")
11025   (prog1
11026       (save-excursion
11027         (when (or quietly
11028                   (not gnus-interactive-catchup) ;Without confirmation?
11029                   gnus-expert-user
11030                   (gnus-y-or-n-p
11031                    (if all
11032                        "Mark absolutely all articles as read? "
11033                      "Mark all unread articles as read? ")))
11034           (if (and not-mark
11035                    (not gnus-newsgroup-adaptive)
11036                    (not gnus-newsgroup-auto-expire)
11037                    (not gnus-suppress-duplicates)
11038                    (or (not gnus-use-cache)
11039                        (eq gnus-use-cache 'passive)))
11040               (progn
11041                 (when all
11042                   (setq gnus-newsgroup-marked nil
11043                         gnus-newsgroup-spam-marked nil
11044                         gnus-newsgroup-dormant nil))
11045                 (setq gnus-newsgroup-unreads
11046                       (gnus-sorted-nunion
11047                        (gnus-sorted-intersection gnus-newsgroup-unreads
11048                                                  gnus-newsgroup-downloadable)
11049                        (gnus-sorted-difference gnus-newsgroup-unfetched
11050                                                gnus-newsgroup-cached))))
11051             ;; We actually mark all articles as canceled, which we
11052             ;; have to do when using auto-expiry or adaptive scoring.
11053             (gnus-summary-show-all-threads)
11054             (if (and to-here reverse)
11055                 (progn
11056                   (goto-char to-here)
11057                   (gnus-summary-mark-current-read-and-unread-as-read
11058                    gnus-catchup-mark)
11059                   (while (gnus-summary-find-next (not all))
11060                     (gnus-summary-mark-article-as-read gnus-catchup-mark)))
11061               (when (gnus-summary-first-subject (not all))
11062                 (while (and
11063                         (if to-here (< (point) to-here) t)
11064                         (gnus-summary-mark-article-as-read gnus-catchup-mark)
11065                         (gnus-summary-find-next (not all))))))
11066             (gnus-set-mode-line 'summary))
11067           t))
11068     (gnus-summary-position-point)))
11069
11070 (defun gnus-summary-catchup-to-here (&optional all)
11071   "Mark all unticked articles before the current one as read.
11072 If ALL is non-nil, also mark ticked and dormant articles as read."
11073   (interactive "P")
11074   (save-excursion
11075     (gnus-save-hidden-threads
11076       (let ((beg (point)))
11077         ;; We check that there are unread articles.
11078         (when (or all (gnus-summary-find-prev))
11079           (gnus-summary-catchup all t beg)))))
11080   (gnus-summary-position-point))
11081
11082 (defun gnus-summary-catchup-from-here (&optional all)
11083   "Mark all unticked articles after (and including) the current one as read.
11084 If ALL is non-nil, also mark ticked and dormant articles as read."
11085   (interactive "P")
11086   (save-excursion
11087     (gnus-save-hidden-threads
11088       (let ((beg (point)))
11089         ;; We check that there are unread articles.
11090         (when (or all (gnus-summary-find-next))
11091           (gnus-summary-catchup all t beg nil t)))))
11092   (gnus-summary-position-point))
11093
11094 (defun gnus-summary-catchup-all (&optional quietly)
11095   "Mark all articles in this newsgroup as read.
11096 This command is dangerous.  Normally, you want \\[gnus-summary-catchup]
11097 instead, which marks only unread articles as read."
11098   (interactive "P")
11099   (gnus-summary-catchup t quietly))
11100
11101 (defun gnus-summary-catchup-and-exit (&optional all quietly)
11102   "Mark all unread articles in this group as read, then exit.
11103 If prefix argument ALL is non-nil, all articles are marked as read.
11104 If QUIETLY is non-nil, no questions will be asked."
11105   (interactive "P")
11106   (when (gnus-summary-catchup all quietly nil 'fast)
11107     ;; Select next newsgroup or exit.
11108     (if (and (not (gnus-group-quit-config gnus-newsgroup-name))
11109              (eq gnus-auto-select-next 'quietly))
11110         (gnus-summary-next-group nil)
11111       (gnus-summary-exit))))
11112
11113 (defun gnus-summary-catchup-all-and-exit (&optional quietly)
11114   "Mark all articles in this newsgroup as read, and then exit.
11115 This command is dangerous.  Normally, you want \\[gnus-summary-catchup-and-exit]
11116 instead, which marks only unread articles as read."
11117   (interactive "P")
11118   (gnus-summary-catchup-and-exit t quietly))
11119
11120 (defun gnus-summary-catchup-and-goto-next-group (&optional all)
11121   "Mark all articles in this group as read and select the next group.
11122 If given a prefix, mark all articles, unread as well as ticked, as
11123 read."
11124   (interactive "P")
11125   (save-excursion
11126     (gnus-summary-catchup all))
11127   (gnus-summary-next-group))
11128
11129 (defun gnus-summary-catchup-and-goto-prev-group (&optional all)
11130   "Mark all articles in this group as read and select the previous group.
11131 If given a prefix, mark all articles, unread as well as ticked, as
11132 read."
11133   (interactive "P")
11134   (save-excursion
11135     (gnus-summary-catchup all))
11136   (gnus-summary-next-group nil nil t))
11137
11138 ;;;
11139 ;;; with article
11140 ;;;
11141
11142 (defmacro gnus-with-article (article &rest forms)
11143   "Select ARTICLE and perform FORMS in the original article buffer.
11144 Then replace the article with the result."
11145   `(progn
11146      ;; We don't want the article to be marked as read.
11147      (let (gnus-mark-article-hook)
11148        (gnus-summary-select-article t t nil ,article))
11149      (set-buffer gnus-original-article-buffer)
11150      ,@forms
11151      (if (not (gnus-check-backend-function
11152                'request-replace-article (car gnus-article-current)))
11153          (gnus-message 5 "Read-only group; not replacing")
11154        (unless (gnus-request-replace-article
11155                 ,article (car gnus-article-current)
11156                 (current-buffer) t)
11157          (error "Couldn't replace article")))
11158      ;; The cache and backlog have to be flushed somewhat.
11159      (when gnus-keep-backlog
11160        (gnus-backlog-remove-article
11161         (car gnus-article-current) (cdr gnus-article-current)))
11162      (when gnus-use-cache
11163        (gnus-cache-update-article
11164         (car gnus-article-current) (cdr gnus-article-current)))))
11165
11166 (put 'gnus-with-article 'lisp-indent-function 1)
11167 (put 'gnus-with-article 'edebug-form-spec '(form body))
11168
11169 ;; Thread-based commands.
11170
11171 (defun gnus-summary-articles-in-thread (&optional article)
11172   "Return a list of all articles in the current thread.
11173 If ARTICLE is non-nil, return all articles in the thread that starts
11174 with that article."
11175   (let* ((article (or article (gnus-summary-article-number)))
11176          (data (gnus-data-find-list article))
11177          (top-level (gnus-data-level (car data)))
11178          (top-subject
11179           (cond ((null gnus-thread-operation-ignore-subject)
11180                  (gnus-simplify-subject-re
11181                   (mail-header-subject (gnus-data-header (car data)))))
11182                 ((eq gnus-thread-operation-ignore-subject 'fuzzy)
11183                  (gnus-simplify-subject-fuzzy
11184                   (mail-header-subject (gnus-data-header (car data)))))
11185                 (t nil)))
11186          (end-point (save-excursion
11187                       (if (gnus-summary-go-to-next-thread)
11188                           (point) (point-max))))
11189          articles)
11190     (while (and data
11191                 (< (gnus-data-pos (car data)) end-point))
11192       (when (or (not top-subject)
11193                 (string= top-subject
11194                          (if (eq gnus-thread-operation-ignore-subject 'fuzzy)
11195                              (gnus-simplify-subject-fuzzy
11196                               (mail-header-subject
11197                                (gnus-data-header (car data))))
11198                            (gnus-simplify-subject-re
11199                             (mail-header-subject
11200                              (gnus-data-header (car data)))))))
11201         (push (gnus-data-number (car data)) articles))
11202       (unless (and (setq data (cdr data))
11203                    (> (gnus-data-level (car data)) top-level))
11204         (setq data nil)))
11205     ;; Return the list of articles.
11206     (nreverse articles)))
11207
11208 (defun gnus-summary-rethread-current ()
11209   "Rethread the thread the current article is part of."
11210   (interactive)
11211   (let* ((gnus-show-threads t)
11212          (article (gnus-summary-article-number))
11213          (id (mail-header-id (gnus-summary-article-header)))
11214          (gnus-newsgroup-threads (list (gnus-id-to-thread (gnus-root-id id)))))
11215     (unless id
11216       (error "No article on the current line"))
11217     (gnus-rebuild-thread id)
11218     (gnus-summary-goto-subject article)))
11219
11220 (defun gnus-summary-reparent-thread ()
11221   "Make the current article child of the marked (or previous) article.
11222
11223 Note that the re-threading will only work if `gnus-thread-ignore-subject'
11224 is non-nil or the Subject: of both articles are the same."
11225   (interactive)
11226   (unless (not (gnus-group-read-only-p))
11227     (error "The current newsgroup does not support article editing"))
11228   (unless (<= (length gnus-newsgroup-processable) 1)
11229     (error "No more than one article may be marked"))
11230   (let ((child (gnus-summary-article-number))
11231         ;; First grab the marked article, otherwise one line up.
11232         (parent (if (not (null gnus-newsgroup-processable))
11233                     (car gnus-newsgroup-processable)
11234                   (save-excursion
11235                     (if (eq (forward-line -1) 0)
11236                         (gnus-summary-article-number)
11237                       (error "Beginning of summary buffer"))))))
11238     (gnus-summary-reparent-children parent (list child))))
11239
11240 (defun gnus-summary-reparent-children (parent children)
11241   "Make PARENT the parent of CHILDREN.
11242 When called interactively, PARENT is the current article and CHILDREN
11243 are the process-marked articles."
11244   (interactive
11245    (list (gnus-summary-article-number)
11246          (gnus-summary-work-articles nil)))
11247   (dolist (child children)
11248     (save-window-excursion
11249       (let ((gnus-article-buffer " *reparent*"))
11250         (unless (not (eq parent child))
11251           (error "An article may not be self-referential"))
11252         (let ((message-id (mail-header-id
11253                            (gnus-summary-article-header parent))))
11254           (unless (and message-id (not (equal message-id "")))
11255             (error "No message-id in desired parent"))
11256           (gnus-with-article child
11257             (save-restriction
11258               (goto-char (point-min))
11259               (message-narrow-to-head)
11260               (if (re-search-forward "^References: " nil t)
11261                   (progn
11262                     (re-search-forward "^[^ \t]" nil t)
11263                     (forward-line -1)
11264                     (end-of-line)
11265                     (insert " " message-id))
11266                 (insert "References: " message-id "\n"))))
11267           (set-buffer gnus-summary-buffer)
11268           (gnus-summary-unmark-all-processable)
11269           (gnus-summary-update-article child)
11270           (when (gnus-summary-goto-subject (cdr gnus-article-current) nil t)
11271             (gnus-summary-update-secondary-mark (cdr gnus-article-current)))
11272           (gnus-summary-rethread-current)
11273           (gnus-message 3 "Article %d is now the child of article %d"
11274                         child parent))))))
11275
11276 (defun gnus-summary-toggle-threads (&optional arg)
11277   "Toggle showing conversation threads.
11278 If ARG is positive number, turn showing conversation threads on."
11279   (interactive "P")
11280   (let ((current (or (gnus-summary-article-number) gnus-newsgroup-end)))
11281     (setq gnus-show-threads
11282           (if (null arg) (not gnus-show-threads)
11283             (> (prefix-numeric-value arg) 0)))
11284     (gnus-summary-prepare)
11285     (gnus-summary-goto-subject current)
11286     (gnus-message 6 "Threading is now %s" (if gnus-show-threads "on" "off"))
11287     (gnus-summary-position-point)))
11288
11289 (eval-and-compile
11290   (if (fboundp 'remove-overlays)
11291       (defalias 'gnus-remove-overlays 'remove-overlays)
11292     (defun gnus-remove-overlays (beg end name val)
11293       "Clear BEG and END of overlays whose property NAME has value VAL.
11294 For compatibility with Emacs 21 and XEmacs."
11295       (dolist (ov (gnus-overlays-in beg end))
11296         (when (eq (gnus-overlay-get ov name) val)
11297           (gnus-delete-overlay ov))))))
11298
11299 (defun gnus-summary-show-all-threads ()
11300   "Show all threads."
11301   (interactive)
11302   (gnus-remove-overlays (point-min) (point-max) 'invisible 'gnus-sum)
11303   (gnus-summary-position-point))
11304
11305 (defun gnus-summary-show-thread ()
11306   "Show thread subtrees.
11307 Returns nil if no thread was there to be shown."
11308   (interactive)
11309   (let* ((orig (point))
11310          (end (point-at-eol))
11311          ;; Leave point at bol
11312          (beg (progn (beginning-of-line) (if (bobp) (point) (1- (point)))))
11313          (eoi (when (eq (get-char-property end 'invisible) 'gnus-sum)
11314                 (if (fboundp 'next-single-char-property-change)
11315                     (or (next-single-char-property-change end 'invisible)
11316                         (point-max))
11317                   (while (progn
11318                            (end-of-line 2)
11319                            (and (not (eobp))
11320                                 (eq (get-char-property (point) 'invisible)
11321                                     'gnus-sum))))
11322                   (point)))))
11323     (when eoi
11324       (gnus-remove-overlays beg eoi 'invisible 'gnus-sum)
11325       (goto-char orig)
11326       (gnus-summary-position-point)
11327       eoi)))
11328
11329 (defun gnus-summary-maybe-hide-threads ()
11330   "If requested, hide the threads that should be hidden."
11331   (when (and gnus-show-threads
11332              gnus-thread-hide-subtree)
11333     (gnus-summary-hide-all-threads
11334      (if (or (consp gnus-thread-hide-subtree)
11335              (functionp gnus-thread-hide-subtree))
11336          (gnus-make-predicate gnus-thread-hide-subtree)
11337        nil))))
11338
11339 ;;; Hiding predicates.
11340
11341 (defun gnus-article-unread-p (header)
11342   (memq (mail-header-number header) gnus-newsgroup-unreads))
11343
11344 (defun gnus-article-unseen-p (header)
11345   (memq (mail-header-number header) gnus-newsgroup-unseen))
11346
11347 (defun gnus-map-articles (predicate articles)
11348   "Map PREDICATE over ARTICLES and return non-nil if any predicate is non-nil."
11349   (apply 'gnus-or (mapcar predicate
11350                           (mapcar (lambda (number)
11351                                     (gnus-summary-article-header number))
11352                                   articles))))
11353
11354 (defun gnus-summary-hide-all-threads (&optional predicate)
11355   "Hide all thread subtrees.
11356 If PREDICATE is supplied, threads that satisfy this predicate
11357 will not be hidden."
11358   (interactive)
11359   (save-excursion
11360     (goto-char (point-min))
11361     (let ((end nil))
11362       (while (not end)
11363         (when (or (not predicate)
11364                   (gnus-map-articles
11365                    predicate (gnus-summary-article-children)))
11366             (gnus-summary-hide-thread))
11367         (setq end (not (zerop (gnus-summary-next-thread 1 t)))))))
11368   (gnus-summary-position-point))
11369
11370 (defun gnus-summary-hide-thread ()
11371   "Hide thread subtrees.
11372 If PREDICATE is supplied, threads that satisfy this predicate
11373 will not be hidden.
11374 Returns nil if no threads were there to be hidden."
11375   (interactive)
11376   (let ((start (point))
11377         (starteol (line-end-position))
11378         (article (gnus-summary-article-number)))
11379     (goto-char start)
11380     ;; Go forward until either the buffer ends or the subthread ends.
11381     (when (and (not (eobp))
11382                (or (zerop (gnus-summary-next-thread 1 t))
11383                    (goto-char (point-max))))
11384       (if (and (> (point) start)
11385                ;; FIXME: this should actually search for a non-invisible \n.
11386                (search-backward "\n" start t))
11387           (progn
11388             (when (> (point) starteol)
11389               (gnus-remove-overlays starteol (point) 'invisible 'gnus-sum)
11390               (let ((ol (gnus-make-overlay starteol (point) nil t nil)))
11391                 (gnus-overlay-put ol 'invisible 'gnus-sum)
11392                 (gnus-overlay-put ol 'evaporate t)))
11393             (gnus-summary-goto-subject article))
11394         (goto-char start)
11395         nil))))
11396
11397 (defun gnus-summary-go-to-next-thread (&optional previous)
11398   "Go to the same level (or less) next thread.
11399 If PREVIOUS is non-nil, go to previous thread instead.
11400 Return the article number moved to, or nil if moving was impossible."
11401   (let ((level (gnus-summary-thread-level))
11402         (way (if previous -1 1))
11403         (beg (point)))
11404     (forward-line way)
11405     (while (and (not (eobp))
11406                 (< level (gnus-summary-thread-level)))
11407       (forward-line way))
11408     (if (eobp)
11409         (progn
11410           (goto-char beg)
11411           nil)
11412       (setq beg (point))
11413       (prog1
11414           (gnus-summary-article-number)
11415         (goto-char beg)))))
11416
11417 (defun gnus-summary-next-thread (n &optional silent)
11418   "Go to the same level next N'th thread.
11419 If N is negative, search backward instead.
11420 Returns the difference between N and the number of skips actually
11421 done.
11422
11423 If SILENT, don't output messages."
11424   (interactive "p")
11425   (let ((backward (< n 0))
11426         (n (abs n)))
11427     (while (and (> n 0)
11428                 (gnus-summary-go-to-next-thread backward))
11429       (decf n))
11430     (unless silent
11431       (gnus-summary-position-point))
11432     (when (and (not silent) (/= 0 n))
11433       (gnus-message 7 "No more threads"))
11434     n))
11435
11436 (defun gnus-summary-prev-thread (n)
11437   "Go to the same level previous N'th thread.
11438 Returns the difference between N and the number of skips actually
11439 done."
11440   (interactive "p")
11441   (gnus-summary-next-thread (- n)))
11442
11443 (defun gnus-summary-go-down-thread ()
11444   "Go down one level in the current thread."
11445   (let ((children (gnus-summary-article-children)))
11446     (when children
11447       (gnus-summary-goto-subject (car children)))))
11448
11449 (defun gnus-summary-go-up-thread ()
11450   "Go up one level in the current thread."
11451   (let ((parent (gnus-summary-article-parent)))
11452     (when parent
11453       (gnus-summary-goto-subject parent))))
11454
11455 (defun gnus-summary-down-thread (n)
11456   "Go down thread N steps.
11457 If N is negative, go up instead.
11458 Returns the difference between N and how many steps down that were
11459 taken."
11460   (interactive "p")
11461   (let ((up (< n 0))
11462         (n (abs n)))
11463     (while (and (> n 0)
11464                 (if up (gnus-summary-go-up-thread)
11465                   (gnus-summary-go-down-thread)))
11466       (setq n (1- n)))
11467     (gnus-summary-position-point)
11468     (when (/= 0 n)
11469       (gnus-message 7 "Can't go further"))
11470     n))
11471
11472 (defun gnus-summary-up-thread (n)
11473   "Go up thread N steps.
11474 If N is negative, go down instead.
11475 Returns the difference between N and how many steps down that were
11476 taken."
11477   (interactive "p")
11478   (gnus-summary-down-thread (- n)))
11479
11480 (defun gnus-summary-top-thread ()
11481   "Go to the top of the thread."
11482   (interactive)
11483   (while (gnus-summary-go-up-thread))
11484   (gnus-summary-article-number))
11485
11486 (defun gnus-summary-expire-thread ()
11487   "Mark articles under current thread as expired."
11488   (interactive)
11489   (gnus-summary-kill-thread 0))
11490
11491 (defun gnus-summary-kill-thread (&optional unmark)
11492   "Mark articles under current thread as read.
11493 If the prefix argument is positive, remove any kinds of marks.
11494 If the prefix argument is zero, mark thread as expired.
11495 If the prefix argument is negative, tick articles instead."
11496   (interactive "P")
11497   (when unmark
11498     (setq unmark (prefix-numeric-value unmark)))
11499   (let ((articles (gnus-summary-articles-in-thread))
11500         (hide (or (null unmark) (= unmark 0))))
11501     (save-excursion
11502       ;; Expand the thread.
11503       (gnus-summary-show-thread)
11504       ;; Mark all the articles.
11505       (while articles
11506         (gnus-summary-goto-subject (car articles))
11507         (cond ((null unmark)
11508                (gnus-summary-mark-article-as-read gnus-killed-mark))
11509               ((> unmark 0)
11510                (gnus-summary-mark-article-as-unread gnus-unread-mark))
11511               ((= unmark 0)
11512                (gnus-summary-mark-article-as-unread gnus-expirable-mark))
11513               (t
11514                (gnus-summary-mark-article-as-unread gnus-ticked-mark)))
11515         (setq articles (cdr articles))))
11516     ;; Hide killed subtrees when hide is true.
11517     (and hide
11518          gnus-thread-hide-killed
11519          (gnus-summary-hide-thread))
11520     ;; If hide is t, go to next unread subject.
11521     (when hide
11522       ;; Go to next unread subject.
11523       (gnus-summary-next-subject 1 t)))
11524   (gnus-set-mode-line 'summary))
11525
11526 ;; Summary sorting commands
11527
11528 (defun gnus-summary-sort-by-number (&optional reverse)
11529   "Sort the summary buffer by article number.
11530 Argument REVERSE means reverse order."
11531   (interactive "P")
11532   (gnus-summary-sort 'number reverse))
11533
11534 (defun gnus-summary-sort-by-most-recent-number (&optional reverse)
11535   "Sort the summary buffer by most recent article number.
11536 Argument REVERSE means reverse order."
11537   (interactive "P")
11538   (gnus-summary-sort 'most-recent-number reverse))
11539
11540 (defun gnus-summary-sort-by-random (&optional reverse)
11541   "Randomize the order in the summary buffer.
11542 Argument REVERSE means to randomize in reverse order."
11543   (interactive "P")
11544   (gnus-summary-sort 'random reverse))
11545
11546 (defun gnus-summary-sort-by-author (&optional reverse)
11547   "Sort the summary buffer by author name alphabetically.
11548 If `case-fold-search' is non-nil, case of letters is ignored.
11549 Argument REVERSE means reverse order."
11550   (interactive "P")
11551   (gnus-summary-sort 'author reverse))
11552
11553 (defun gnus-summary-sort-by-recipient (&optional reverse)
11554   "Sort the summary buffer by recipient name alphabetically.
11555 If `case-fold-search' is non-nil, case of letters is ignored.
11556 Argument REVERSE means reverse order."
11557   (interactive "P")
11558   (gnus-summary-sort 'recipient reverse))
11559
11560 (defun gnus-summary-sort-by-subject (&optional reverse)
11561   "Sort the summary buffer by subject alphabetically.  `Re:'s are ignored.
11562 If `case-fold-search' is non-nil, case of letters is ignored.
11563 Argument REVERSE means reverse order."
11564   (interactive "P")
11565   (gnus-summary-sort 'subject reverse))
11566
11567 (defun gnus-summary-sort-by-date (&optional reverse)
11568   "Sort the summary buffer by date.
11569 Argument REVERSE means reverse order."
11570   (interactive "P")
11571   (gnus-summary-sort 'date reverse))
11572
11573 (defun gnus-summary-sort-by-most-recent-date (&optional reverse)
11574   "Sort the summary buffer by most recent date.
11575 Argument REVERSE means reverse order."
11576   (interactive "P")
11577   (gnus-summary-sort 'most-recent-date reverse))
11578
11579 (defun gnus-summary-sort-by-score (&optional reverse)
11580   "Sort the summary buffer by score.
11581 Argument REVERSE means reverse order."
11582   (interactive "P")
11583   (gnus-summary-sort 'score reverse))
11584
11585 (defun gnus-summary-sort-by-lines (&optional reverse)
11586   "Sort the summary buffer by the number of lines.
11587 Argument REVERSE means reverse order."
11588   (interactive "P")
11589   (gnus-summary-sort 'lines reverse))
11590
11591 (defun gnus-summary-sort-by-chars (&optional reverse)
11592   "Sort the summary buffer by article length.
11593 Argument REVERSE means reverse order."
11594   (interactive "P")
11595   (gnus-summary-sort 'chars reverse))
11596
11597 (defun gnus-summary-sort-by-original (&optional reverse)
11598   "Sort the summary buffer using the default sorting method.
11599 Argument REVERSE means reverse order."
11600   (interactive "P")
11601   (let* ((inhibit-read-only t)
11602          (gnus-summary-prepare-hook nil))
11603     ;; We do the sorting by regenerating the threads.
11604     (gnus-summary-prepare)
11605     ;; Hide subthreads if needed.
11606     (gnus-summary-maybe-hide-threads)))
11607
11608 (defun gnus-summary-sort (predicate reverse)
11609   "Sort summary buffer by PREDICATE.  REVERSE means reverse order."
11610   (let* ((thread (intern (format "gnus-thread-sort-by-%s" predicate)))
11611          (article (intern (format "gnus-article-sort-by-%s" predicate)))
11612          (gnus-thread-sort-functions
11613           (if (not reverse)
11614               thread
11615             `(lambda (t1 t2)
11616                (,thread t2 t1))))
11617          (gnus-sort-gathered-threads-function
11618           gnus-thread-sort-functions)
11619          (gnus-article-sort-functions
11620           (if (not reverse)
11621               article
11622             `(lambda (t1 t2)
11623                (,article t2 t1))))
11624          (inhibit-read-only t)
11625          (gnus-summary-prepare-hook nil))
11626     ;; We do the sorting by regenerating the threads.
11627     (gnus-summary-prepare)
11628     ;; Hide subthreads if needed.
11629     (gnus-summary-maybe-hide-threads)))
11630
11631 ;; Summary saving commands.
11632
11633 (defun gnus-summary-save-article (&optional n not-saved)
11634   "Save the current article using the default saver function.
11635 If N is a positive number, save the N next articles.
11636 If N is a negative number, save the N previous articles.
11637 If N is nil and any articles have been marked with the process mark,
11638 save those articles instead.
11639 The variable `gnus-default-article-saver' specifies the saver function.
11640
11641 If the optional second argument NOT-SAVED is non-nil, articles saved
11642 will not be marked as saved."
11643   (interactive "P")
11644   (require 'gnus-art)
11645   (let* ((articles (gnus-summary-work-articles n))
11646          (save-buffer (save-excursion
11647                         (nnheader-set-temp-buffer " *Gnus Save*")))
11648          (num (length articles))
11649          ;; Whether to save decoded articles or raw articles.
11650          (decode (when gnus-article-save-coding-system
11651                    (get gnus-default-article-saver :decode)))
11652          ;; When saving many articles in a single file, use the other
11653          ;; function to save articles other than the first one.
11654          (saver2 (get gnus-default-article-saver :function))
11655          (gnus-prompt-before-saving (if saver2
11656                                         t
11657                                       gnus-prompt-before-saving))
11658          (gnus-default-article-saver gnus-default-article-saver)
11659          header file)
11660     (dolist (article articles)
11661       (setq header (gnus-summary-article-header article))
11662       (if (not (vectorp header))
11663           ;; This is a pseudo-article.
11664           (if (assq 'name header)
11665               (gnus-copy-file (cdr (assq 'name header)))
11666             (gnus-message 1 "Article %d is unsaveable" article))
11667         ;; This is a real article.
11668         (save-window-excursion
11669           (let ((gnus-display-mime-function (when decode
11670                                               gnus-display-mime-function))
11671                 (gnus-article-prepare-hook (when decode
11672                                              gnus-article-prepare-hook)))
11673             (gnus-summary-select-article t t nil article)
11674             (gnus-summary-goto-subject article)))
11675         (with-current-buffer save-buffer
11676           (erase-buffer)
11677           (insert-buffer-substring (if decode
11678                                        gnus-article-buffer
11679                                      gnus-original-article-buffer)))
11680         (setq file (gnus-article-save save-buffer file num))
11681         (gnus-summary-remove-process-mark article)
11682         (unless not-saved
11683           (gnus-summary-set-saved-mark article)))
11684       (when saver2
11685         (setq gnus-default-article-saver saver2
11686               saver2 nil)))
11687     (gnus-kill-buffer save-buffer)
11688     (gnus-summary-position-point)
11689     (gnus-set-mode-line 'summary)
11690     n))
11691
11692 (defun gnus-summary-pipe-output (&optional n sym)
11693   "Pipe the current article to a subprocess.
11694 If N is a positive number, pipe the N next articles.
11695 If N is a negative number, pipe the N previous articles.
11696 If N is nil and any articles have been marked with the process mark,
11697 pipe those articles instead.
11698 The default command to which articles are piped is specified by the
11699 variable `gnus-summary-pipe-output-default-command'; if it is nil, you
11700 will be prompted for the command.
11701
11702 The properties `:decode' and `:headers' that are put to the function
11703 symbol `gnus-summary-save-in-pipe' control whether this function
11704 decodes articles and what headers to keep (see the doc string for the
11705 `gnus-default-article-saver' variable).  If SYM (the symbolic prefix)
11706 is neither omitted nor the symbol `r', force including all headers
11707 regardless of the `:headers' property.  If it is the symbol `r',
11708 articles that are not decoded and include all headers will be piped
11709 no matter what the properties `:decode' and `:headers' are."
11710   (interactive (gnus-interactive "P\ny"))
11711   (require 'gnus-art)
11712   (let* ((articles (gnus-summary-work-articles n))
11713          (result-buffer "*Shell Command Output*")
11714          (all-headers (not (memq sym '(nil r))))
11715          (gnus-save-all-headers (or all-headers gnus-save-all-headers))
11716          (raw (eq sym 'r))
11717          (headers (get 'gnus-summary-save-in-pipe :headers))
11718          command result)
11719     (unless (numberp (car articles))
11720       (error "No article to pipe"))
11721     (setq command (gnus-read-shell-command
11722                    (concat "Shell command on "
11723                            (if (cdr articles)
11724                                (format "these %d articles" (length articles))
11725                              "this article")
11726                            ": ")
11727                    gnus-summary-pipe-output-default-command))
11728     (when (string-equal command "")
11729       (error "A command is required"))
11730     (when all-headers
11731       (put 'gnus-summary-save-in-pipe :headers nil))
11732     (unwind-protect
11733         (while articles
11734           (gnus-summary-goto-subject (pop articles))
11735           (save-window-excursion (gnus-summary-save-in-pipe command raw))
11736           (when (and (get-buffer result-buffer)
11737                      (not (zerop (buffer-size (get-buffer result-buffer)))))
11738             (setq result (concat result (with-current-buffer result-buffer
11739                                           (buffer-string))))))
11740       (put 'gnus-summary-save-in-pipe :headers headers))
11741     (unless (zerop (length result))
11742       (if (with-current-buffer (get-buffer-create result-buffer)
11743             (erase-buffer)
11744             (insert result)
11745             (prog1
11746                 (and (= (count-lines (point-min) (point)) 1)
11747                      (progn
11748                        (end-of-line 0)
11749                        (<= (current-column)
11750                            (window-width (minibuffer-window)))))
11751               (goto-char (point-min))))
11752           (message "%s" (substring result 0 -1))
11753         (message nil)
11754         (gnus-configure-windows 'pipe)))))
11755
11756 (defun gnus-summary-save-article-mail (&optional arg)
11757   "Append the current article to a Unix mail box file.
11758 If N is a positive number, save the N next articles.
11759 If N is a negative number, save the N previous articles.
11760 If N is nil and any articles have been marked with the process mark,
11761 save those articles instead."
11762   (interactive "P")
11763   (require 'gnus-art)
11764   (let ((gnus-default-article-saver 'gnus-summary-save-in-mail))
11765     (gnus-summary-save-article arg)))
11766
11767 (defun gnus-summary-save-article-rmail (&optional arg)
11768   "Append the current article to an rmail file.
11769 If N is a positive number, save the N next articles.
11770 If N is a negative number, save the N previous articles.
11771 If N is nil and any articles have been marked with the process mark,
11772 save those articles instead."
11773   (interactive "P")
11774   (require 'gnus-art)
11775   (let ((gnus-default-article-saver 'gnus-summary-save-in-rmail))
11776     (gnus-summary-save-article arg)))
11777
11778 (defun gnus-summary-save-article-file (&optional arg)
11779   "Append the current article to a file.
11780 If N is a positive number, save the N next articles.
11781 If N is a negative number, save the N previous articles.
11782 If N is nil and any articles have been marked with the process mark,
11783 save those articles instead."
11784   (interactive "P")
11785   (require 'gnus-art)
11786   (let ((gnus-default-article-saver 'gnus-summary-save-in-file))
11787     (gnus-summary-save-article arg)))
11788
11789 (defun gnus-summary-write-article-file (&optional arg)
11790   "Write the current article to a file, deleting the previous file.
11791 If N is a positive number, save the N next articles.
11792 If N is a negative number, save the N previous articles.
11793 If N is nil and any articles have been marked with the process mark,
11794 save those articles instead."
11795   (interactive "P")
11796   (require 'gnus-art)
11797   (let ((gnus-default-article-saver 'gnus-summary-write-to-file))
11798     (gnus-summary-save-article arg)))
11799
11800 (defun gnus-summary-save-article-body-file (&optional arg)
11801   "Append the current article body to a file.
11802 If N is a positive number, save the N next articles.
11803 If N is a negative number, save the N previous articles.
11804 If N is nil and any articles have been marked with the process mark,
11805 save those articles instead."
11806   (interactive "P")
11807   (require 'gnus-art)
11808   (let ((gnus-default-article-saver 'gnus-summary-save-body-in-file))
11809     (gnus-summary-save-article arg)))
11810
11811 (defun gnus-summary-write-article-body-file (&optional arg)
11812   "Write the current article body to a file, deleting the previous file.
11813 If N is a positive number, save the N next articles.
11814 If N is a negative number, save the N previous articles.
11815 If N is nil and any articles have been marked with the process mark,
11816 save those articles instead."
11817   (interactive "P")
11818   (require 'gnus-art)
11819   (let ((gnus-default-article-saver 'gnus-summary-write-body-to-file))
11820     (gnus-summary-save-article arg)))
11821
11822 (defun gnus-summary-muttprint (&optional arg)
11823   "Print the current article using Muttprint.
11824 If N is a positive number, save the N next articles.
11825 If N is a negative number, save the N previous articles.
11826 If N is nil and any articles have been marked with the process mark,
11827 save those articles instead."
11828   (interactive "P")
11829   (require 'gnus-art)
11830   (let ((gnus-default-article-saver 'gnus-summary-pipe-to-muttprint))
11831     (gnus-summary-save-article arg t)))
11832
11833 (defun gnus-summary-pipe-message (program)
11834   "Pipe the current article through PROGRAM."
11835   (interactive "sProgram: ")
11836   (gnus-summary-select-article)
11837   (let ((mail-header-separator ""))
11838     (gnus-eval-in-buffer-window gnus-article-buffer
11839       (save-restriction
11840         (widen)
11841         (let ((start (window-start))
11842               (inhibit-read-only t))
11843           (message-pipe-buffer-body program)
11844           (set-window-start (get-buffer-window (current-buffer)) start))))))
11845
11846 (defun gnus-get-split-value (methods)
11847   "Return a value based on the split METHODS."
11848   (let (split-name method result match)
11849     (when methods
11850       (with-current-buffer gnus-original-article-buffer
11851         (save-restriction
11852           (nnheader-narrow-to-headers)
11853           (while (and methods (not split-name))
11854             (goto-char (point-min))
11855             (setq method (pop methods))
11856             (setq match (car method))
11857             (when (cond
11858                    ((stringp match)
11859                     ;; Regular expression.
11860                     (ignore-errors
11861                       (re-search-forward match nil t)))
11862                    ((functionp match)
11863                     ;; Function.
11864                     (save-restriction
11865                       (widen)
11866                       (setq result (funcall match gnus-newsgroup-name))))
11867                    ((consp match)
11868                     ;; Form.
11869                     (save-restriction
11870                       (widen)
11871                       (setq result (eval match)))))
11872               (setq split-name (cdr method))
11873               (cond ((stringp result)
11874                      (push (expand-file-name
11875                             result gnus-article-save-directory)
11876                            split-name))
11877                     ((consp result)
11878                      (setq split-name (append result split-name)))))))))
11879     (nreverse split-name)))
11880
11881 (defun gnus-valid-move-group-p (group)
11882   (and (boundp group)
11883        (symbol-name group)
11884        (symbol-value group)
11885        (gnus-get-function (gnus-find-method-for-group
11886                            (symbol-name group)) 'request-accept-article t)))
11887
11888 (defun gnus-read-move-group-name (prompt default articles prefix)
11889   "Read a group name."
11890   (let* ((split-name (gnus-get-split-value gnus-move-split-methods))
11891          (minibuffer-confirm-incomplete nil) ; XEmacs
11892          (prom
11893           (format "%s %s to"
11894                   prompt
11895                   (if (> (length articles) 1)
11896                       (format "these %d articles" (length articles))
11897                     "this article")))
11898          (to-newsgroup
11899           (let (active group)
11900             (when (or (null split-name) (= 1 (length split-name)))
11901               (setq active (gnus-make-hashtable (length gnus-active-hashtb)))
11902               (mapatoms (lambda (symbol)
11903                           (setq group (symbol-name symbol))
11904                           (when (string-match "[^\000-\177]" group)
11905                             (setq group (gnus-group-decoded-name group)))
11906                           (set (intern group active) group))
11907                         gnus-active-hashtb))
11908             (cond
11909              ((null split-name)
11910               (gnus-completing-read-with-default
11911                default prom active 'gnus-valid-move-group-p nil prefix
11912                'gnus-group-history))
11913              ((= 1 (length split-name))
11914               (gnus-completing-read-with-default
11915                (car split-name) prom active 'gnus-valid-move-group-p nil nil
11916                'gnus-group-history))
11917              (t
11918               (gnus-completing-read-with-default
11919                nil prom (mapcar 'list (nreverse split-name)) nil nil nil
11920                'gnus-group-history)))))
11921          (to-method (gnus-server-to-method (gnus-group-method to-newsgroup)))
11922          encoded)
11923     (when to-newsgroup
11924       (if (or (string= to-newsgroup "")
11925               (string= to-newsgroup prefix))
11926           (setq to-newsgroup default))
11927       (unless to-newsgroup
11928         (error "No group name entered"))
11929       (setq encoded (mm-encode-coding-string
11930                      to-newsgroup
11931                      (gnus-group-name-charset to-method to-newsgroup)))
11932       (or (gnus-active encoded)
11933           (gnus-activate-group encoded nil nil to-method)
11934           (if (gnus-y-or-n-p (format "No such group: %s.  Create it? "
11935                                      to-newsgroup))
11936               (or (and (gnus-request-create-group encoded to-method)
11937                        (gnus-activate-group encoded nil nil to-method)
11938                        (gnus-subscribe-group encoded))
11939                   (error "Couldn't create group %s" to-newsgroup)))
11940           (error "No such group: %s" to-newsgroup))
11941       encoded)))
11942
11943 (defvar gnus-summary-save-parts-counter)
11944 (declare-function mm-uu-dissect "mm-uu" (&optional noheader mime-type))
11945
11946 (defun gnus-summary-save-parts (type dir n &optional reverse)
11947   "Save parts matching TYPE to DIR.
11948 If REVERSE, save parts that do not match TYPE."
11949   (interactive
11950    (list (read-string "Save parts of type: "
11951                       (or (car gnus-summary-save-parts-type-history)
11952                           gnus-summary-save-parts-default-mime)
11953                       'gnus-summary-save-parts-type-history)
11954          (setq gnus-summary-save-parts-last-directory
11955                (read-file-name "Save to directory: "
11956                                gnus-summary-save-parts-last-directory
11957                                nil t))
11958          current-prefix-arg))
11959   (gnus-summary-iterate n
11960     (let ((gnus-display-mime-function nil)
11961           gnus-article-prepare-hook
11962           gnus-article-decode-hook
11963           gnus-display-mime-function
11964           gnus-break-pages
11965           (gnus-inhibit-treatment t))
11966       (gnus-summary-select-article))
11967     (with-current-buffer gnus-article-buffer
11968       (let ((handles (or gnus-article-mime-handles
11969                          (mm-dissect-buffer nil gnus-article-loose-mime)
11970                          (and gnus-article-emulate-mime
11971                               (mm-uu-dissect))))
11972             (gnus-summary-save-parts-counter 1))
11973         (when handles
11974           (gnus-summary-save-parts-1 type dir handles reverse)
11975           (unless gnus-article-mime-handles ;; Don't destroy this case.
11976             (mm-destroy-parts handles)))))))
11977
11978 (defun gnus-summary-save-parts-1 (type dir handle reverse)
11979   (if (stringp (car handle))
11980       (mapcar (lambda (h) (gnus-summary-save-parts-1 type dir h reverse))
11981               (cdr handle))
11982     (when (if reverse
11983               (not (string-match type (mm-handle-media-type handle)))
11984             (string-match type (mm-handle-media-type handle)))
11985       (let ((file (expand-file-name
11986                    (gnus-map-function
11987                     mm-file-name-rewrite-functions
11988                     (file-name-nondirectory
11989                      (or
11990                       (mail-content-type-get
11991                        (mm-handle-disposition handle) 'filename)
11992                       (mail-content-type-get
11993                        (mm-handle-type handle) 'name)
11994                       (format "%s.%d.%d" gnus-newsgroup-name
11995                               (cdr gnus-article-current)
11996                               gnus-summary-save-parts-counter))))
11997                    dir)))
11998         (incf gnus-summary-save-parts-counter)
11999         (unless (file-exists-p file)
12000           (mm-save-part-to-file handle file))))))
12001
12002 ;; Summary extract commands
12003
12004 (defun gnus-summary-insert-pseudos (pslist &optional not-view)
12005   (let ((inhibit-read-only t)
12006         (article (gnus-summary-article-number))
12007         after-article b e)
12008     (unless (gnus-summary-goto-subject article)
12009       (error "No such article: %d" article))
12010     (gnus-summary-position-point)
12011     ;; If all commands are to be bunched up on one line, we collect
12012     ;; them here.
12013     (unless gnus-view-pseudos-separately
12014       (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
12015             files action)
12016         (while ps
12017           (setq action (cdr (assq 'action (car ps))))
12018           (setq files (list (cdr (assq 'name (car ps)))))
12019           (while (and ps (cdr ps)
12020                       (string= (or action "1")
12021                                (or (cdr (assq 'action (cadr ps))) "2")))
12022             (push (cdr (assq 'name (cadr ps))) files)
12023             (setcdr ps (cddr ps)))
12024           (when files
12025             (when (not (string-match "%s" action))
12026               (push " " files))
12027             (push " " files)
12028             (when (assq 'execute (car ps))
12029               (setcdr (assq 'execute (car ps))
12030                       (funcall (if (string-match "%s" action)
12031                                    'format 'concat)
12032                                action
12033                                (mapconcat
12034                                 (lambda (f)
12035                                   (if (equal f " ")
12036                                       f
12037                                     (shell-quote-argument f)))
12038                                 files " ")))))
12039           (setq ps (cdr ps)))))
12040     (if (and gnus-view-pseudos (not not-view))
12041         (while pslist
12042           (when (assq 'execute (car pslist))
12043             (gnus-execute-command (cdr (assq 'execute (car pslist)))
12044                                   (eq gnus-view-pseudos 'not-confirm)))
12045           (setq pslist (cdr pslist)))
12046       (save-excursion
12047         (while pslist
12048           (setq after-article (or (cdr (assq 'article (car pslist)))
12049                                   (gnus-summary-article-number)))
12050           (gnus-summary-goto-subject after-article)
12051           (forward-line 1)
12052           (setq b (point))
12053           (insert "    " (file-name-nondirectory
12054                           (cdr (assq 'name (car pslist))))
12055                   ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
12056           (setq e (point))
12057           (forward-line -1)             ; back to `b'
12058           (gnus-add-text-properties
12059            b (1- e) (list 'gnus-number gnus-reffed-article-number
12060                           gnus-mouse-face-prop gnus-mouse-face))
12061           (gnus-data-enter
12062            after-article gnus-reffed-article-number
12063            gnus-unread-mark b (car pslist) 0 (- e b))
12064           (setq gnus-newsgroup-unreads
12065                 (gnus-add-to-sorted-list gnus-newsgroup-unreads
12066                                          gnus-reffed-article-number))
12067           (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
12068           (setq pslist (cdr pslist)))))))
12069
12070 (defun gnus-pseudos< (p1 p2)
12071   (let ((c1 (cdr (assq 'action p1)))
12072         (c2 (cdr (assq 'action p2))))
12073     (and c1 c2 (string< c1 c2))))
12074
12075 (defun gnus-request-pseudo-article (props)
12076   (cond ((assq 'execute props)
12077          (gnus-execute-command (cdr (assq 'execute props)))))
12078   (let ((gnus-current-article (gnus-summary-article-number)))
12079     (gnus-run-hooks 'gnus-mark-article-hook)))
12080
12081 (defun gnus-execute-command (command &optional automatic)
12082   (save-excursion
12083     (gnus-article-setup-buffer)
12084     (set-buffer gnus-article-buffer)
12085     (setq buffer-read-only nil)
12086     (let ((command (if automatic command
12087                      (read-string "Command: " (cons command 0)))))
12088       (erase-buffer)
12089       (insert "$ " command "\n\n")
12090       (if gnus-view-pseudo-asynchronously
12091           (start-process "gnus-execute" (current-buffer) shell-file-name
12092                          shell-command-switch command)
12093         (call-process shell-file-name nil t nil
12094                       shell-command-switch command)))))
12095
12096 ;; Summary kill commands.
12097
12098 (defun gnus-summary-edit-global-kill (article)
12099   "Edit the \"global\" kill file."
12100   (interactive (list (gnus-summary-article-number)))
12101   (gnus-group-edit-global-kill article))
12102
12103 (defun gnus-summary-edit-local-kill ()
12104   "Edit a local kill file applied to the current newsgroup."
12105   (interactive)
12106   (setq gnus-current-headers (gnus-summary-article-header))
12107   (gnus-group-edit-local-kill
12108    (gnus-summary-article-number) gnus-newsgroup-name))
12109
12110 ;;; Header reading.
12111
12112 (defun gnus-read-header (id &optional header)
12113   "Read the headers of article ID and enter them into the Gnus system."
12114   (let ((group gnus-newsgroup-name)
12115         (gnus-override-method
12116          (or
12117           gnus-override-method
12118           (and (gnus-news-group-p gnus-newsgroup-name)
12119                (car (gnus-refer-article-methods)))))
12120         where)
12121     ;; First we check to see whether the header in question is already
12122     ;; fetched.
12123     (if (stringp id)
12124         ;; This is a Message-ID.
12125         (setq header (or header (gnus-id-to-header id)))
12126       ;; This is an article number.
12127       (setq header (or header (gnus-summary-article-header id))))
12128     (if (and header
12129              (not (gnus-summary-article-sparse-p (mail-header-number header))))
12130         ;; We have found the header.
12131         header
12132       ;; We have to really fetch the header to this article.
12133       (with-current-buffer nntp-server-buffer
12134         (when (setq where (gnus-request-head id group))
12135           (nnheader-fold-continuation-lines)
12136           (goto-char (point-max))
12137           (insert ".\n")
12138           (goto-char (point-min))
12139           (insert "211 ")
12140           (princ (cond
12141                   ((numberp id) id)
12142                   ((cdr where) (cdr where))
12143                   (header (mail-header-number header))
12144                   (t gnus-reffed-article-number))
12145                  (current-buffer))
12146           (insert " Article retrieved.\n"))
12147         (if (or (not where)
12148                 (not (setq header (car (gnus-get-newsgroup-headers nil t)))))
12149             ()                          ; Malformed head.
12150           (unless (gnus-summary-article-sparse-p (mail-header-number header))
12151             (when (and (stringp id)
12152                        (or
12153                         (not (string= (gnus-group-real-name group)
12154                                       (car where)))
12155                         (not (gnus-server-equal gnus-override-method
12156                                                 (gnus-group-method group)))))
12157               ;; If we fetched by Message-ID and the article came from
12158               ;; a different group (or server), we fudge some bogus
12159               ;; article numbers for this article.
12160               (mail-header-set-number header gnus-reffed-article-number))
12161             (with-current-buffer gnus-summary-buffer
12162               (decf gnus-reffed-article-number)
12163               (gnus-remove-header (mail-header-number header))
12164               (push header gnus-newsgroup-headers)
12165               (setq gnus-current-headers header)
12166               (push (mail-header-number header) gnus-newsgroup-limit)))
12167           header)))))
12168
12169 (defun gnus-remove-header (number)
12170   "Remove header NUMBER from `gnus-newsgroup-headers'."
12171   (if (and gnus-newsgroup-headers
12172            (= number (mail-header-number (car gnus-newsgroup-headers))))
12173       (pop gnus-newsgroup-headers)
12174     (let ((headers gnus-newsgroup-headers))
12175       (while (and (cdr headers)
12176                   (not (= number (mail-header-number (cadr headers)))))
12177         (pop headers))
12178       (when (cdr headers)
12179         (setcdr headers (cddr headers))))))
12180
12181 ;;;
12182 ;;; summary highlights
12183 ;;;
12184
12185 (defun gnus-highlight-selected-summary ()
12186   "Highlight selected article in summary buffer."
12187   ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
12188   (when gnus-summary-selected-face
12189     (save-excursion
12190       (let* ((beg (point-at-bol))
12191              (end (point-at-eol))
12192              ;; Fix by Mike Dugan <dugan@bucrf16.bu.edu>.
12193              (from (if (get-text-property beg gnus-mouse-face-prop)
12194                        beg
12195                      (or (next-single-property-change
12196                           beg gnus-mouse-face-prop nil end)
12197                          beg)))
12198              (to
12199               (if (= from end)
12200                   (- from 2)
12201                 (or (next-single-property-change
12202                      from gnus-mouse-face-prop nil end)
12203                     end))))
12204         ;; If no mouse-face prop on line we will have to = from = end,
12205         ;; so we highlight the entire line instead.
12206         (when (= (+ to 2) from)
12207           (setq from beg)
12208           (setq to end))
12209         (if gnus-newsgroup-selected-overlay
12210             ;; Move old overlay.
12211             (gnus-move-overlay
12212              gnus-newsgroup-selected-overlay from to (current-buffer))
12213           ;; Create new overlay.
12214           (gnus-overlay-put
12215            (setq gnus-newsgroup-selected-overlay (gnus-make-overlay from to))
12216            'face gnus-summary-selected-face))))))
12217
12218 (defvar gnus-summary-highlight-line-cached nil)
12219 (defvar gnus-summary-highlight-line-trigger nil)
12220
12221 (defun gnus-summary-highlight-line-0 ()
12222   (if (and (eq gnus-summary-highlight-line-trigger
12223                gnus-summary-highlight)
12224            gnus-summary-highlight-line-cached)
12225       gnus-summary-highlight-line-cached
12226     (setq gnus-summary-highlight-line-trigger gnus-summary-highlight
12227           gnus-summary-highlight-line-cached
12228           (let* ((cond (list 'cond))
12229                  (c cond)
12230                  (list gnus-summary-highlight))
12231             (while list
12232               (setcdr c (cons (list (caar list) (list 'quote (cdar list)))
12233                               nil))
12234               (setq c (cdr c)
12235                     list (cdr list)))
12236             (gnus-byte-compile (list 'lambda nil cond))))))
12237
12238 (defun gnus-summary-highlight-line ()
12239   "Highlight current line according to `gnus-summary-highlight'."
12240   (let* ((beg (point-at-bol))
12241          (article (or (gnus-summary-article-number) gnus-current-article))
12242          (score (or (cdr (assq article
12243                                gnus-newsgroup-scored))
12244                     gnus-summary-default-score 0))
12245          (mark (or (gnus-summary-article-mark) gnus-unread-mark))
12246          (inhibit-read-only t)
12247          (default gnus-summary-default-score)
12248          (default-high gnus-summary-default-high-score)
12249          (default-low gnus-summary-default-low-score)
12250          (uncached (and gnus-summary-use-undownloaded-faces
12251                         (memq article gnus-newsgroup-undownloaded)
12252                         (not (memq article gnus-newsgroup-cached)))))
12253     (let ((face (funcall (gnus-summary-highlight-line-0))))
12254       (unless (eq face (get-text-property beg 'face))
12255         (gnus-put-text-property-excluding-characters-with-faces
12256          beg (point-at-eol) 'face
12257          (setq face (if (boundp face) (symbol-value face) face)))
12258         (when gnus-summary-highlight-line-function
12259           (funcall gnus-summary-highlight-line-function article face))))))
12260
12261 (defun gnus-update-read-articles (group unread &optional compute)
12262   "Update the list of read articles in GROUP.
12263 UNREAD is a sorted list."
12264   (let ((active (or gnus-newsgroup-active (gnus-active group)))
12265         (info (gnus-get-info group))
12266         (prev 1)
12267         read)
12268     (if (or (not info) (not active))
12269         ;; There is no info on this group if it was, in fact,
12270         ;; killed.  Gnus stores no information on killed groups, so
12271         ;; there's nothing to be done.
12272         ;; One could store the information somewhere temporarily,
12273         ;; perhaps...  Hmmm...
12274         ()
12275       ;; Remove any negative articles numbers.
12276       (while (and unread (< (car unread) 0))
12277         (setq unread (cdr unread)))
12278       ;; Remove any expired article numbers
12279       (while (and unread (< (car unread) (car active)))
12280         (setq unread (cdr unread)))
12281       ;; Compute the ranges of read articles by looking at the list of
12282       ;; unread articles.
12283       (while unread
12284         (when (/= (car unread) prev)
12285           (push (if (= prev (1- (car unread))) prev
12286                   (cons prev (1- (car unread))))
12287                 read))
12288         (setq prev (1+ (car unread)))
12289         (setq unread (cdr unread)))
12290       (when (<= prev (cdr active))
12291         (push (cons prev (cdr active)) read))
12292       (setq read (if (> (length read) 1) (nreverse read) read))
12293       (if compute
12294           read
12295         (save-excursion
12296           (let (setmarkundo)
12297             ;; Propagate the read marks to the backend.
12298             (when (and gnus-propagate-marks
12299                        (gnus-check-backend-function 'request-set-mark group))
12300               (let ((del (gnus-remove-from-range (gnus-info-read info) read))
12301                     (add (gnus-remove-from-range read (gnus-info-read info))))
12302                 (when (or add del)
12303                   (unless (gnus-check-group group)
12304                     (error "Can't open server for %s" group))
12305                   (gnus-request-set-mark
12306                    group (delq nil (list (if add (list add 'add '(read)))
12307                                          (if del (list del 'del '(read))))))
12308                   (setq setmarkundo
12309                         `(gnus-request-set-mark
12310                           ,group
12311                           ',(delq nil (list
12312                                        (if del (list del 'add '(read)))
12313                                        (if add (list add 'del '(read))))))))))
12314             (set-buffer gnus-group-buffer)
12315             (gnus-undo-register
12316               `(progn
12317                  (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
12318                  (gnus-info-set-read ',info ',(gnus-info-read info))
12319                  (gnus-get-unread-articles-in-group ',info
12320                                                     (gnus-active ,group))
12321                  (gnus-group-update-group ,group t)
12322                  ,setmarkundo))))
12323         ;; Enter this list into the group info.
12324         (gnus-info-set-read info read)
12325         ;; Set the number of unread articles in gnus-newsrc-hashtb.
12326         (gnus-get-unread-articles-in-group info (gnus-active group))
12327         t))))
12328
12329 (defun gnus-offer-save-summaries ()
12330   "Offer to save all active summary buffers."
12331   (let (buffers)
12332     ;; Go through all buffers and find all summaries.
12333     (dolist (buffer (buffer-list))
12334       (when (and (setq buffer (buffer-name buffer))
12335                  (string-match "Summary" buffer)
12336                  (with-current-buffer buffer
12337                    ;; We check that this is, indeed, a summary buffer.
12338                    (and (eq major-mode 'gnus-summary-mode)
12339                         ;; Also make sure this isn't bogus.
12340                         gnus-newsgroup-prepared
12341                         ;; Also make sure that this isn't a
12342                         ;; dead summary buffer.
12343                         (not gnus-dead-summary-mode))))
12344         (push buffer buffers)))
12345     ;; Go through all these summary buffers and offer to save them.
12346     (when buffers
12347       (save-excursion
12348         (map-y-or-n-p
12349          "Update summary buffer %s? "
12350          (lambda (buf)
12351            (switch-to-buffer buf)
12352            (gnus-summary-exit))
12353          buffers)))))
12354
12355 (defun gnus-summary-setup-default-charset ()
12356   "Setup newsgroup default charset."
12357   (if (member gnus-newsgroup-name '("nndraft:delayed" "nndraft:drafts"))
12358       (setq gnus-newsgroup-charset nil)
12359     (let* ((ignored-charsets
12360             (or gnus-newsgroup-ephemeral-ignored-charsets
12361                 (append
12362                  (and gnus-newsgroup-name
12363                       (gnus-parameter-ignored-charsets gnus-newsgroup-name))
12364                  gnus-newsgroup-ignored-charsets))))
12365       (setq gnus-newsgroup-charset
12366             (or gnus-newsgroup-ephemeral-charset
12367                 (and gnus-newsgroup-name
12368                      (gnus-parameter-charset gnus-newsgroup-name))
12369                 gnus-default-charset))
12370       (set (make-local-variable 'gnus-newsgroup-ignored-charsets)
12371            ignored-charsets))))
12372
12373 ;;;
12374 ;;; Mime Commands
12375 ;;;
12376
12377 (defun gnus-summary-display-buttonized (&optional show-all-parts)
12378   "Display the current article buffer fully MIME-buttonized.
12379 If SHOW-ALL-PARTS (the prefix) is non-nil, all multipart/* parts are
12380 treated as multipart/mixed."
12381   (interactive "P")
12382   (require 'gnus-art)
12383   (let ((gnus-unbuttonized-mime-types nil)
12384         (gnus-mime-display-multipart-as-mixed show-all-parts))
12385     (gnus-summary-show-article)))
12386
12387 (defun gnus-summary-repair-multipart (article)
12388   "Add a Content-Type header to a multipart article without one."
12389   (interactive (list (gnus-summary-article-number)))
12390   (gnus-with-article article
12391     (message-narrow-to-head)
12392     (message-remove-header "Mime-Version")
12393     (goto-char (point-max))
12394     (insert "Mime-Version: 1.0\n")
12395     (widen)
12396     (when (search-forward "\n--" nil t)
12397       (let ((separator (buffer-substring (point) (point-at-eol))))
12398         (message-narrow-to-head)
12399         (message-remove-header "Content-Type")
12400         (goto-char (point-max))
12401         (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
12402                         separator))
12403         (widen))))
12404   (let (gnus-mark-article-hook)
12405     (gnus-summary-select-article t t nil article)))
12406
12407 (defun gnus-summary-toggle-display-buttonized ()
12408   "Toggle the buttonizing of the article buffer."
12409   (interactive)
12410   (require 'gnus-art)
12411   (if (setq gnus-inhibit-mime-unbuttonizing
12412             (not gnus-inhibit-mime-unbuttonizing))
12413       (let ((gnus-unbuttonized-mime-types nil))
12414         (gnus-summary-show-article))
12415     (gnus-summary-show-article)))
12416
12417 ;;;
12418 ;;; Generic summary marking commands
12419 ;;;
12420
12421 (defvar gnus-summary-marking-alist
12422   '((read gnus-del-mark "d")
12423     (unread gnus-unread-mark "u")
12424     (ticked gnus-ticked-mark "!")
12425     (dormant gnus-dormant-mark "?")
12426     (expirable gnus-expirable-mark "e"))
12427   "An alist of names/marks/keystrokes.")
12428
12429 (defvar gnus-summary-generic-mark-map (make-sparse-keymap))
12430 (defvar gnus-summary-mark-map)
12431
12432 (defun gnus-summary-make-all-marking-commands ()
12433   (define-key gnus-summary-mark-map "M" gnus-summary-generic-mark-map)
12434   (dolist (elem gnus-summary-marking-alist)
12435     (apply 'gnus-summary-make-marking-command elem)))
12436
12437 (defun gnus-summary-make-marking-command (name mark keystroke)
12438   (let ((map (make-sparse-keymap)))
12439     (define-key gnus-summary-generic-mark-map keystroke map)
12440     (dolist (lway `((next "next" next nil "n")
12441                     (next-unread "next unread" next t "N")
12442                     (prev "previous" prev nil "p")
12443                     (prev-unread "previous unread" prev t "P")
12444                     (nomove "" nil nil ,keystroke)))
12445       (let ((func (gnus-summary-make-marking-command-1
12446                    mark (car lway) lway name)))
12447         (setq func (eval func))
12448         (define-key map (nth 4 lway) func)))))
12449
12450 (defun gnus-summary-make-marking-command-1 (mark way lway name)
12451   `(defun ,(intern
12452             (format "gnus-summary-put-mark-as-%s%s"
12453                     name (if (eq way 'nomove)
12454                              ""
12455                            (concat "-" (symbol-name way)))))
12456      (n)
12457      ,(format
12458        "Mark the current article as %s%s.
12459 If N, the prefix, then repeat N times.
12460 If N is negative, move in reverse order.
12461 The difference between N and the actual number of articles marked is
12462 returned."
12463        name (cadr lway))
12464      (interactive "p")
12465      (gnus-summary-generic-mark n ,mark ',(nth 2 lway) ,(nth 3 lway))))
12466
12467 (defun gnus-summary-generic-mark (n mark move unread)
12468   "Mark N articles with MARK."
12469   (unless (eq major-mode 'gnus-summary-mode)
12470     (error "This command can only be used in the summary buffer"))
12471   (gnus-summary-show-thread)
12472   (let ((nummove
12473          (cond
12474           ((eq move 'next) 1)
12475           ((eq move 'prev) -1)
12476           (t 0))))
12477     (if (zerop nummove)
12478         (setq n 1)
12479       (when (< n 0)
12480         (setq n (abs n)
12481               nummove (* -1 nummove))))
12482     (while (and (> n 0)
12483                 (gnus-summary-mark-article nil mark)
12484                 (zerop (gnus-summary-next-subject nummove unread t)))
12485       (setq n (1- n)))
12486     (when (/= 0 n)
12487       (gnus-message 7 "No more %sarticles" (if mark "" "unread ")))
12488     (gnus-summary-recenter)
12489     (gnus-summary-position-point)
12490     (gnus-set-mode-line 'summary)
12491     n))
12492
12493 (defun gnus-summary-insert-articles (articles)
12494   (when (setq articles
12495               (gnus-sorted-difference articles
12496                                       (mapcar (lambda (h)
12497                                                 (mail-header-number h))
12498                                               gnus-newsgroup-headers)))
12499     (setq gnus-newsgroup-headers
12500           (gnus-merge 'list
12501                       gnus-newsgroup-headers
12502                       (gnus-fetch-headers articles)
12503                       'gnus-article-sort-by-number))
12504     ;; Suppress duplicates?
12505     (when gnus-suppress-duplicates
12506       (gnus-dup-suppress-articles))
12507
12508     (if (and gnus-fetch-old-headers
12509              (eq gnus-headers-retrieved-by 'nov))
12510         ;; We might want to build some more threads first.
12511         (if (eq gnus-fetch-old-headers 'invisible)
12512             (gnus-build-all-threads)
12513           (gnus-build-old-threads))
12514       ;; Mark the inserted articles that are unread as unread.
12515       (setq gnus-newsgroup-unreads
12516             (gnus-sorted-nunion
12517              gnus-newsgroup-unreads
12518              (gnus-sorted-nintersection
12519               (gnus-list-of-unread-articles gnus-newsgroup-name)
12520               articles)))
12521       ;; Mark the inserted articles as selected so that the information
12522       ;; of the marks having been changed by a user may be updated when
12523       ;; exiting this group.  See `gnus-summary-update-info'.
12524       (dolist (art articles)
12525         (setq gnus-newsgroup-unselected (delq art gnus-newsgroup-unselected))))
12526     ;; Let the Gnus agent mark articles as read.
12527     (when gnus-agent
12528       (gnus-agent-get-undownloaded-list))
12529     ;; Remove list identifiers from subject
12530     (when gnus-list-identifiers
12531       (gnus-summary-remove-list-identifiers))
12532     ;; First and last article in this newsgroup.
12533     (when gnus-newsgroup-headers
12534       (setq gnus-newsgroup-begin
12535             (mail-header-number (car gnus-newsgroup-headers))
12536             gnus-newsgroup-end
12537             (mail-header-number
12538              (gnus-last-element gnus-newsgroup-headers))))
12539     (when gnus-use-scoring
12540       (gnus-possibly-score-headers))))
12541
12542 (defun gnus-summary-insert-old-articles (&optional all)
12543   "Insert all old articles in this group.
12544 If ALL is non-nil, already read articles become readable.
12545 If ALL is a number, fetch this number of articles."
12546   (interactive "P")
12547   (prog1
12548       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12549             older len)
12550         (setq older
12551               ;; Some nntp servers lie about their active range.  When
12552               ;; this happens, the active range can be in the millions.
12553               ;; Use a compressed range to avoid creating a huge list.
12554               (gnus-range-difference (list gnus-newsgroup-active) old))
12555         (setq len (gnus-range-length older))
12556         (cond
12557          ((null older) nil)
12558          ((numberp all)
12559           (if (< all len)
12560               (let ((older-range (nreverse older)))
12561                 (setq older nil)
12562
12563                 (while (> all 0)
12564                   (let* ((r (pop older-range))
12565                          (min (if (numberp r) r (car r)))
12566                          (max (if (numberp r) r (cdr r))))
12567                     (while (and (<= min max)
12568                                 (> all 0))
12569                       (push max older)
12570                       (setq all (1- all)
12571                             max (1- max))))))
12572             (setq older (gnus-uncompress-range older))))
12573          (all
12574           (setq older (gnus-uncompress-range older)))
12575          (t
12576           (when (and (numberp gnus-large-newsgroup)
12577                    (> len gnus-large-newsgroup))
12578               (let* ((cursor-in-echo-area nil)
12579                      (initial (gnus-parameter-large-newsgroup-initial
12580                                gnus-newsgroup-name))
12581                      (input
12582                       (read-string
12583                        (format
12584                         "How many articles from %s (%s %d): "
12585                         (gnus-group-decoded-name gnus-newsgroup-name)
12586                         (if initial "max" "default")
12587                         len)
12588                        (if initial
12589                            (cons (number-to-string initial)
12590                                  0)))))
12591                 (unless (string-match "^[ \t]*$" input)
12592                   (setq all (string-to-number input))
12593                   (if (< all len)
12594                       (let ((older-range (nreverse older)))
12595                         (setq older nil)
12596
12597                         (while (> all 0)
12598                           (let* ((r (pop older-range))
12599                                  (min (if (numberp r) r (car r)))
12600                                  (max (if (numberp r) r (cdr r))))
12601                             (while (and (<= min max)
12602                                         (> all 0))
12603                               (push max older)
12604                               (setq all (1- all)
12605                                     max (1- max))))))))))
12606           (setq older (gnus-uncompress-range older))))
12607         (if (not older)
12608             (message "No old news.")
12609           (gnus-summary-insert-articles older)
12610           (gnus-summary-limit (gnus-sorted-nunion old older))))
12611     (gnus-summary-position-point)))
12612
12613 (defun gnus-summary-insert-new-articles ()
12614   "Insert all new articles in this group."
12615   (interactive)
12616   (prog1
12617       (let ((old (sort (mapcar 'car gnus-newsgroup-data) '<))
12618             (old-active gnus-newsgroup-active)
12619             (nnmail-fetched-sources (list t))
12620             i new)
12621         (setq gnus-newsgroup-active
12622               (gnus-activate-group gnus-newsgroup-name 'scan))
12623         (setq i (cdr gnus-newsgroup-active))
12624         (while (> i (cdr old-active))
12625           (push i new)
12626           (decf i))
12627         (if (not new)
12628             (message "No gnus is bad news")
12629           (gnus-summary-insert-articles new)
12630           (setq gnus-newsgroup-unreads
12631                 (gnus-sorted-nunion gnus-newsgroup-unreads new))
12632           (gnus-summary-limit (gnus-sorted-nunion old new))))
12633     (gnus-summary-position-point)))
12634
12635 ;;; Bookmark support for Gnus.
12636 (declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
12637 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
12638 (declare-function bookmark-default-handler "bookmark" (bmk))
12639 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
12640
12641 (defun gnus-summary-bookmark-make-record ()
12642   "Make a bookmark entry for a Gnus summary buffer."
12643   (unless (and (derived-mode-p 'gnus-summary-mode) gnus-article-current)
12644     (error "Please retry from the Gnus summary buffer")) ;[1]
12645   (let* ((subject (elt (gnus-summary-article-header) 1))
12646          (grp     (car gnus-article-current))
12647          (art     (cdr gnus-article-current))
12648          (head    (gnus-summary-article-header art))
12649          (id      (mail-header-id head)))
12650     `(,subject
12651       ,@(bookmark-make-record-default 'point-only)
12652       (location . ,(format "Gnus %s:%d:%s" grp art id))
12653       (group . ,grp) (article . ,art)
12654       (message-id . ,id) (handler . gnus-summary-bookmark-jump))))
12655
12656 ;;;###autoload
12657 (defun gnus-summary-bookmark-jump (bookmark)
12658   "Handler function for record returned by `gnus-summary-bookmark-make-record'.
12659 BOOKMARK is a bookmark name or a bookmark record."
12660   (let ((group    (bookmark-prop-get bookmark 'group))
12661         (article  (bookmark-prop-get bookmark 'article))
12662         (id       (bookmark-prop-get bookmark 'message-id)))
12663     (gnus-fetch-group group (list article))
12664     (gnus-summary-insert-cached-articles)
12665     (gnus-summary-goto-article id nil 'force)
12666     (bookmark-default-handler
12667      `(""
12668        (buffer . ,(current-buffer))
12669        . ,(bookmark-get-bookmark-record bookmark)))))
12670
12671 (gnus-summary-make-all-marking-commands)
12672
12673 (gnus-ems-redefine)
12674
12675 (provide 'gnus-sum)
12676
12677 (run-hooks 'gnus-sum-load-hook)
12678
12679 ;; Local Variables:
12680 ;; coding: iso-8859-1
12681 ;; End:
12682
12683 ;; arch-tag: 17c6748f-6d00-4d36-bf01-835c42f31235
12684 ;;; gnus-sum.el ends here