Yet another try at getting the image sizing right.
[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-summary-stop-at-end-of-message nil
80   "If non-nil, don't select the next message when using `SPC'."
81   :link '(custom-manual "(gnus)Group Maneuvering")
82   :group 'gnus-summary-maneuvering
83   :version "24.1"
84   :type 'boolean)
85
86 (defcustom gnus-fetch-old-headers nil
87   "*Non-nil means that Gnus will try to build threads by grabbing old headers.
88 If an unread article in the group refers to an older, already
89 read (or just marked as read) article, the old article will not
90 normally be displayed in the Summary buffer.  If this variable is
91 t, Gnus will attempt to grab the headers to the old articles, and
92 thereby build complete threads.  If it has the value `some', all
93 old headers will be fetched but only enough headers to connect
94 otherwise loose threads will be displayed.  This variable can
95 also be a number.  In that case, no more than that number of old
96 headers will be fetched.  If it has the value `invisible', all
97 old headers will be fetched, but none will be displayed.
98
99 The server has to support NOV for any of this to work.
100
101 This feature can seriously impact performance it ignores all
102 locally cached header entries.  Setting it to t for groups for a
103 server that doesn't expire articles (such as news.gmane.org),
104 leads to very slow summary generation."
105   :group 'gnus-thread
106   :type '(choice (const :tag "off" nil)
107                  (const :tag "on" t)
108                  (const some)
109                  (const invisible)
110                  number
111                  (sexp :menu-tag "other" t)))
112
113 (defcustom gnus-refer-thread-limit 500
114   "*The number of old headers to fetch when doing \\<gnus-summary-mode-map>\\[gnus-summary-refer-thread].
115 If t, fetch all the available old headers."
116   :group 'gnus-thread
117   :type '(choice number
118                  (sexp :menu-tag "other" t)))
119
120 (defcustom gnus-summary-make-false-root 'adopt
121   "*nil means that Gnus won't gather loose threads.
122 If the root of a thread has expired or been read in a previous
123 session, the information necessary to build a complete thread has been
124 lost.  Instead of having many small sub-threads from this original thread
125 scattered all over the summary buffer, Gnus can gather them.
126
127 If non-nil, Gnus will try to gather all loose sub-threads from an
128 original thread into one large thread.
129
130 If this variable is non-nil, it should be one of `none', `adopt',
131 `dummy' or `empty'.
132
133 If this variable is `none', Gnus will not make a false root, but just
134 present the sub-threads after another.
135 If this variable is `dummy', Gnus will create a dummy root that will
136 have all the sub-threads as children.
137 If this variable is `adopt', Gnus will make one of the \"children\"
138 the parent and mark all the step-children as such.
139 If this variable is `empty', the \"children\" are printed with empty
140 subject fields.  (Or rather, they will be printed with a string
141 given by the `gnus-summary-same-subject' variable.)"
142   :group 'gnus-thread
143   :type '(choice (const :tag "off" nil)
144                  (const none)
145                  (const dummy)
146                  (const adopt)
147                  (const empty)))
148
149 (defcustom gnus-summary-make-false-root-always nil
150   "Always make a false dummy root."
151   :version "22.1"
152   :group 'gnus-thread
153   :type 'boolean)
154
155 (defcustom gnus-summary-gather-exclude-subject "^ *$\\|^(none)$"
156   "*A regexp to match subjects to be excluded from loose thread gathering.
157 As loose thread gathering is done on subjects only, that means that
158 there can be many false gatherings performed.  By rooting out certain
159 common subjects, gathering might become saner."
160   :group 'gnus-thread
161   :type 'regexp)
162
163 (defcustom gnus-summary-gather-subject-limit nil
164   "*Maximum length of subject comparisons when gathering loose threads.
165 Use nil to compare full subjects.  Setting this variable to a low
166 number will help gather threads that have been corrupted by
167 newsreaders chopping off subject lines, but it might also mean that
168 unrelated articles that have subject that happen to begin with the
169 same few characters will be incorrectly gathered.
170
171 If this variable is `fuzzy', Gnus will use a fuzzy algorithm when
172 comparing subjects."
173   :group 'gnus-thread
174   :type '(choice (const :tag "off" nil)
175                  (const fuzzy)
176                  (sexp :menu-tag "on" t)))
177
178 (defcustom gnus-simplify-subject-functions nil
179   "List of functions taking a string argument that simplify subjects.
180 The functions are applied recursively.
181
182 Useful functions to put in this list include:
183 `gnus-simplify-subject-re', `gnus-simplify-subject-fuzzy',
184 `gnus-simplify-whitespace', and `gnus-simplify-all-whitespace'."
185   :group 'gnus-thread
186   :type '(repeat function))
187
188 (defcustom gnus-simplify-ignored-prefixes nil
189   "*Remove matches for this regexp from subject lines when simplifying fuzzily."
190   :group 'gnus-thread
191   :type '(choice (const :tag "off" nil)
192                  regexp))
193
194 (defcustom gnus-build-sparse-threads nil
195   "*If non-nil, fill in the gaps in threads.
196 If `some', only fill in the gaps that are needed to tie loose threads
197 together.  If `more', fill in all leaf nodes that Gnus can find.  If
198 non-nil and non-`some', fill in all gaps that Gnus manages to guess."
199   :group 'gnus-thread
200   :type '(choice (const :tag "off" nil)
201                  (const some)
202                  (const more)
203                  (sexp :menu-tag "all" t)))
204
205 (defcustom gnus-summary-thread-gathering-function
206   'gnus-gather-threads-by-subject
207   "*Function used for gathering loose threads.
208 There are two pre-defined functions: `gnus-gather-threads-by-subject',
209 which only takes Subjects into consideration; and
210 `gnus-gather-threads-by-references', which compared the References
211 headers of the articles to find matches."
212   :group 'gnus-thread
213   :type '(radio (function-item gnus-gather-threads-by-subject)
214                 (function-item gnus-gather-threads-by-references)
215                 (function :tag "other")))
216
217 (defcustom gnus-summary-same-subject ""
218   "*String indicating that the current article has the same subject as the previous.
219 This variable will only be used if the value of
220 `gnus-summary-make-false-root' is `empty'."
221   :group 'gnus-summary-format
222   :type 'string)
223
224 (defcustom gnus-summary-goto-unread t
225   "*If t, many commands will go to the next unread article.
226 This applies to marking commands as well as other commands that
227 \"naturally\" select the next article, like, for instance, `SPC' at
228 the end of an article.
229
230 If nil, the marking commands do NOT go to the next unread article
231 \(they go to the next article instead).  If `never', commands that
232 usually go to the next unread article, will go to the next article,
233 whether it is read or not."
234   :group 'gnus-summary-marks
235   :link '(custom-manual "(gnus)Setting Marks")
236   :type '(choice (const :tag "off" nil)
237                  (const never)
238                  (sexp :menu-tag "on" t)))
239
240 (defcustom gnus-summary-default-score 0
241   "*Default article score level.
242 All scores generated by the score files will be added to this score.
243 If this variable is nil, scoring will be disabled."
244   :group 'gnus-score-default
245   :type '(choice (const :tag "disable")
246                  integer))
247
248 (defcustom gnus-summary-default-high-score 0
249   "*Default threshold for a high scored article.
250 An article will be highlighted as high scored if its score is greater
251 than this score."
252   :version "22.1"
253   :group 'gnus-score-default
254   :type 'integer)
255
256 (defcustom gnus-summary-default-low-score 0
257   "*Default threshold for a low scored article.
258 An article will be highlighted as low scored if its score is smaller
259 than this score."
260   :version "22.1"
261   :group 'gnus-score-default
262   :type 'integer)
263
264 (defcustom gnus-summary-zcore-fuzz 0
265   "*Fuzziness factor for the zcore in the summary buffer.
266 Articles with scores closer than this to `gnus-summary-default-score'
267 will not be marked."
268   :group 'gnus-summary-format
269   :type 'integer)
270
271 (defcustom gnus-simplify-subject-fuzzy-regexp nil
272   "*Strings to be removed when doing fuzzy matches.
273 This can either be a regular expression or list of regular expressions
274 that will be removed from subject strings if fuzzy subject
275 simplification is selected."
276   :group 'gnus-thread
277   :type '(repeat regexp))
278
279 (defcustom gnus-show-threads t
280   "*If non-nil, display threads in summary mode."
281   :group 'gnus-thread
282   :type 'boolean)
283
284 (defcustom gnus-thread-hide-subtree nil
285   "*If non-nil, hide all threads initially.
286 This can be a predicate specifier which says which threads to hide.
287 If threads are hidden, you have to run the command
288 `gnus-summary-show-thread' by hand or select an article."
289   :group 'gnus-thread
290   :type '(radio (sexp :format "Non-nil\n"
291                       :match (lambda (widget value)
292                                (not (or (consp value) (functionp value))))
293                       :value t)
294                 (const nil)
295                 (sexp :tag "Predicate specifier")))
296
297 (defcustom gnus-thread-hide-killed t
298   "*If non-nil, hide killed threads automatically."
299   :group 'gnus-thread
300   :type 'boolean)
301
302 (defcustom gnus-thread-ignore-subject t
303   "*If non-nil, which is the default, ignore subjects and do all threading based on the Reference header.
304 If nil, articles that have different subjects from their parents will
305 start separate threads."
306   :group 'gnus-thread
307   :type 'boolean)
308
309 (defcustom gnus-thread-operation-ignore-subject t
310   "*If non-nil, subjects will be ignored when doing thread commands.
311 This affects commands like `gnus-summary-kill-thread' and
312 `gnus-summary-lower-thread'.
313
314 If this variable is nil, articles in the same thread with different
315 subjects will not be included in the operation in question.  If this
316 variable is `fuzzy', only articles that have subjects that are fuzzily
317 equal will be included."
318   :group 'gnus-thread
319   :type '(choice (const :tag "off" nil)
320                  (const fuzzy)
321                  (sexp :tag "on" t)))
322
323 (defcustom gnus-thread-indent-level 4
324   "*Number that says how much each sub-thread should be indented."
325   :group 'gnus-thread
326   :type 'integer)
327
328 (defcustom gnus-auto-extend-newsgroup t
329   "*If non-nil, extend newsgroup forward and backward when requested."
330   :group 'gnus-summary-choose
331   :type 'boolean)
332
333 (defcustom gnus-auto-select-first t
334   "If non-nil, select an article on group entry.
335 An article is selected automatically when entering a group
336 e.g. with \\<gnus-group-mode-map>\\[gnus-group-read-group], or via `gnus-summary-next-page' or
337 `gnus-summary-catchup-and-goto-next-group'.
338
339 Which article is selected is controlled by the variable
340 `gnus-auto-select-subject'.
341
342 If you want to prevent automatic selection of articles in some
343 newsgroups, set the variable to nil in `gnus-select-group-hook'."
344   ;; Commands include...
345   ;; \\<gnus-group-mode-map>\\[gnus-group-read-group]
346   ;; \\<gnus-summary-mode-map>\\[gnus-summary-next-page]
347   ;; \\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]
348   :group 'gnus-group-select
349   :type '(choice (const :tag "none" nil)
350                  (sexp :menu-tag "first" t)))
351
352 (defcustom gnus-auto-select-subject 'unread
353   "*Says what subject to place under point when entering a group.
354
355 This variable can either be the symbols `first' (place point on the
356 first subject), `unread' (place point on the subject line of the first
357 unread article), `best' (place point on the subject line of the
358 higest-scored article), `unseen' (place point on the subject line of
359 the first unseen article), `unseen-or-unread' (place point on the subject
360 line of the first unseen article or, if all article have been seen, on the
361 subject line of the first unread article), or a function to be called to
362 place point on some subject line."
363   :version "22.1"
364   :group 'gnus-group-select
365   :type '(choice (const best)
366                  (const unread)
367                  (const first)
368                  (const unseen)
369                  (const unseen-or-unread)))
370
371 (defcustom gnus-auto-select-next t
372   "*If non-nil, offer to go to the next group from the end of the previous.
373 If the value is t and the next newsgroup is empty, Gnus will exit
374 summary mode and go back to group mode.  If the value is neither nil
375 nor t, Gnus will select the following unread newsgroup.  In
376 particular, if the value is the symbol `quietly', the next unread
377 newsgroup will be selected without any confirmation, and if it is
378 `almost-quietly', the next group will be selected without any
379 confirmation if you are located on the last article in the group.
380 Finally, if this variable is `slightly-quietly', the `\\<gnus-summary-mode-map>\\[gnus-summary-catchup-and-goto-next-group]' command
381 will go to the next group without confirmation."
382   :group 'gnus-summary-maneuvering
383   :type '(choice (const :tag "off" nil)
384                  (const quietly)
385                  (const almost-quietly)
386                  (const slightly-quietly)
387                  (sexp :menu-tag "on" t)))
388
389 (defcustom gnus-auto-select-same nil
390   "*If non-nil, select the next article with the same subject.
391 If there are no more articles with the same subject, go to
392 the first unread article."
393   :group 'gnus-summary-maneuvering
394   :type 'boolean)
395
396 (defcustom gnus-auto-select-on-ephemeral-exit 'next-noselect
397   "What article should be selected after exiting an ephemeral group.
398 Valid values include:
399
400 `next'
401   Select the next article.
402 `next-unread'
403   Select the next unread article.
404 `next-noselect'
405   Move the cursor to the next article.  This is the default.
406 `next-unread-noselect'
407   Move the cursor to the next unread article.
408
409 If it has any other value or there is no next (unread) article, the
410 article selected before entering to the ephemeral group will appear."
411   :version "23.1" ;; No Gnus
412   :group 'gnus-summary-maneuvering
413   :type '(choice :format "%{%t%}:\n %[Value Menu%] %v"
414                  (const next) (const next-unread)
415                  (const next-noselect) (const next-unread-noselect)
416                  (sexp :tag "other" :value nil)))
417
418 (defcustom gnus-auto-goto-ignores 'unfetched
419   "*Says how to handle unfetched articles when maneuvering.
420
421 This variable can either be the symbols nil (maneuver to any
422 article), `undownloaded' (maneuvering while unplugged ignores articles
423 that have not been fetched), `always-undownloaded' (maneuvering always
424 ignores articles that have not been fetched), `unfetched' (maneuvering
425 ignores articles whose headers have not been fetched).
426
427 NOTE: The list of unfetched articles will always be nil when plugged
428 and, when unplugged, a subset of the undownloaded article list."
429   :version "22.1"
430   :group 'gnus-summary-maneuvering
431   :type '(choice (const :tag "None" nil)
432                  (const :tag "Undownloaded when unplugged" undownloaded)
433                  (const :tag "Undownloaded" always-undownloaded)
434                  (const :tag "Unfetched" unfetched)))
435
436 (defcustom gnus-summary-check-current nil
437   "*If non-nil, consider the current article when moving.
438 The \"unread\" movement commands will stay on the same line if the
439 current article is unread."
440   :group 'gnus-summary-maneuvering
441   :type 'boolean)
442
443 (defcustom gnus-auto-center-summary 2
444   "*If non-nil, always center the current summary buffer.
445 In particular, if `vertical' do only vertical recentering.  If non-nil
446 and non-`vertical', do both horizontal and vertical recentering."
447   :group 'gnus-summary-maneuvering
448   :type '(choice (const :tag "none" nil)
449                  (const vertical)
450                  (integer :tag "height")
451                  (sexp :menu-tag "both" t)))
452
453 (defvar gnus-auto-center-group t
454   "*If non-nil, always center the group buffer.")
455
456 (defcustom gnus-show-all-headers nil
457   "*If non-nil, don't hide any headers."
458   :group 'gnus-article-hiding
459   :group 'gnus-article-headers
460   :type 'boolean)
461
462 (defcustom gnus-summary-ignore-duplicates nil
463   "*If non-nil, ignore articles with identical Message-ID headers."
464   :group 'gnus-summary
465   :type 'boolean)
466
467 (defcustom gnus-single-article-buffer t
468   "*If non-nil, display all articles in the same buffer.
469 If nil, each group will get its own article buffer."
470   :group 'gnus-article-various
471   :type 'boolean)
472
473 (defcustom gnus-break-pages t
474   "*If non-nil, do page breaking on articles.
475 The page delimiter is specified by the `gnus-page-delimiter'
476 variable."
477   :group 'gnus-article-various
478   :type 'boolean)
479
480 (defcustom gnus-move-split-methods nil
481   "*Variable used to suggest where articles are to be moved to.
482 It uses the same syntax as the `gnus-split-methods' variable.
483 However, whereas `gnus-split-methods' specifies file names as targets,
484 this variable specifies group names."
485   :group 'gnus-summary-mail
486   :type '(repeat (choice (list :value (fun) function)
487                          (cons :value ("" "") regexp (repeat string))
488                          (sexp :value nil))))
489
490 (defcustom gnus-move-group-prefix-function 'gnus-group-real-prefix
491   "Function used to compute default prefix for article move/copy/etc prompts.
492 The function should take one argument, a group name, and return a
493 string with the suggested prefix."
494   :group 'gnus-summary-mail
495   :type 'function)
496
497 ;; FIXME: Although the custom type is `character' for the following variables,
498 ;; using multibyte characters (Latin-1, UTF-8) doesn't work.  -- rs
499
500 (defcustom gnus-unread-mark ?           ;Whitespace
501   "*Mark used for unread articles."
502   :group 'gnus-summary-marks
503   :type 'character)
504
505 (defcustom gnus-ticked-mark ?!
506   "*Mark used for ticked articles."
507   :group 'gnus-summary-marks
508   :type 'character)
509
510 (defcustom gnus-dormant-mark ??
511   "*Mark used for dormant articles."
512   :group 'gnus-summary-marks
513   :type 'character)
514
515 (defcustom gnus-del-mark ?r
516   "*Mark used for del'd articles."
517   :group 'gnus-summary-marks
518   :type 'character)
519
520 (defcustom gnus-read-mark ?R
521   "*Mark used for read articles."
522   :group 'gnus-summary-marks
523   :type 'character)
524
525 (defcustom gnus-expirable-mark ?E
526   "*Mark used for expirable articles."
527   :group 'gnus-summary-marks
528   :type 'character)
529
530 (defcustom gnus-killed-mark ?K
531   "*Mark used for killed articles."
532   :group 'gnus-summary-marks
533   :type 'character)
534
535 (defcustom gnus-spam-mark ?$
536   "*Mark used for spam articles."
537   :version "22.1"
538   :group 'gnus-summary-marks
539   :type 'character)
540
541 (defcustom gnus-kill-file-mark ?X
542   "*Mark used for articles killed by kill files."
543   :group 'gnus-summary-marks
544   :type 'character)
545
546 (defcustom gnus-low-score-mark ?Y
547   "*Mark used for articles with a low score."
548   :group 'gnus-summary-marks
549   :type 'character)
550
551 (defcustom gnus-catchup-mark ?C
552   "*Mark used for articles that are caught up."
553   :group 'gnus-summary-marks
554   :type 'character)
555
556 (defcustom gnus-replied-mark ?A
557   "*Mark used for articles that have been replied to."
558   :group 'gnus-summary-marks
559   :type 'character)
560
561 (defcustom gnus-forwarded-mark ?F
562   "*Mark used for articles that have been forwarded."
563   :version "22.1"
564   :group 'gnus-summary-marks
565   :type 'character)
566
567 (defcustom gnus-recent-mark ?N
568   "*Mark used for articles that are recent."
569   :version "22.1"
570   :group 'gnus-summary-marks
571   :type 'character)
572
573 (defcustom gnus-cached-mark ?*
574   "*Mark used for articles that are in the cache."
575   :group 'gnus-summary-marks
576   :type 'character)
577
578 (defcustom gnus-saved-mark ?S
579   "*Mark used for articles that have been saved."
580   :group 'gnus-summary-marks
581   :type 'character)
582
583 (defcustom gnus-unseen-mark ?.
584   "*Mark used for articles that haven't been seen."
585   :version "22.1"
586   :group 'gnus-summary-marks
587   :type 'character)
588
589 (defcustom gnus-no-mark ?               ;Whitespace
590   "*Mark used for articles that have no other secondary mark."
591   :version "22.1"
592   :group 'gnus-summary-marks
593   :type 'character)
594
595 (defcustom gnus-ancient-mark ?O
596   "*Mark used for ancient articles."
597   :group 'gnus-summary-marks
598   :type 'character)
599
600 (defcustom gnus-sparse-mark ?Q
601   "*Mark used for sparsely reffed articles."
602   :group 'gnus-summary-marks
603   :type 'character)
604
605 (defcustom gnus-canceled-mark ?G
606   "*Mark used for canceled articles."
607   :group 'gnus-summary-marks
608   :type 'character)
609
610 (defcustom gnus-duplicate-mark ?M
611   "*Mark used for duplicate articles."
612   :group 'gnus-summary-marks
613   :type 'character)
614
615 (defcustom gnus-undownloaded-mark ?-
616   "*Mark used for articles that weren't downloaded."
617   :version "22.1"
618   :group 'gnus-summary-marks
619   :type 'character)
620
621 (defcustom gnus-downloaded-mark ?+
622   "*Mark used for articles that were downloaded."
623   :group 'gnus-summary-marks
624   :type 'character)
625
626 (defcustom gnus-downloadable-mark ?%
627   "*Mark used for articles that are to be downloaded."
628   :group 'gnus-summary-marks
629   :type 'character)
630
631 (defcustom gnus-unsendable-mark ?=
632   "*Mark used for articles that won't be sent."
633   :group 'gnus-summary-marks
634   :type 'character)
635
636 (defcustom gnus-score-over-mark ?+
637   "*Score mark used for articles with high scores."
638   :group 'gnus-summary-marks
639   :type 'character)
640
641 (defcustom gnus-score-below-mark ?-
642   "*Score mark used for articles with low scores."
643   :group 'gnus-summary-marks
644   :type 'character)
645
646 (defcustom gnus-empty-thread-mark ?     ;Whitespace
647   "*There is no thread under the article."
648   :group 'gnus-summary-marks
649   :type 'character)
650
651 (defcustom gnus-not-empty-thread-mark ?=
652   "*There is a thread under the article."
653   :group 'gnus-summary-marks
654   :type 'character)
655
656 (defcustom gnus-view-pseudo-asynchronously nil
657   "*If non-nil, Gnus will view pseudo-articles asynchronously."
658   :group 'gnus-extract-view
659   :type 'boolean)
660
661 (defcustom gnus-auto-expirable-marks
662   (list gnus-killed-mark gnus-del-mark gnus-catchup-mark
663         gnus-low-score-mark gnus-ancient-mark gnus-read-mark
664         gnus-duplicate-mark)
665   "*The list of marks converted into expiration if a group is auto-expirable."
666   :version "24.1"
667   :group 'gnus-summary
668   :type '(repeat character))
669
670 (defcustom gnus-inhibit-user-auto-expire t
671   "*If non-nil, user marking commands will not mark an article as expirable, even if the group has auto-expire turned on."
672   :version "21.1"
673   :group 'gnus-summary
674   :type 'boolean)
675
676 (defcustom gnus-mark-copied-or-moved-articles-as-expirable nil
677   "If non-nil, mark articles copied or moved to auto-expire group as expirable.
678 If nil, the expirable marks will be unchanged except that the marks
679 will be removed when copying or moving articles to a group that has
680 not turned auto-expire on.  If non-nil, articles that have been read
681 will be marked as expirable when being copied or moved to a group in
682 which auto-expire is turned on."
683   :version "23.2"
684   :type 'boolean
685   :group 'gnus-summary-marks)
686
687 (defcustom gnus-view-pseudos nil
688   "*If `automatic', pseudo-articles will be viewed automatically.
689 If `not-confirm', pseudos will be viewed automatically, and the user
690 will not be asked to confirm the command."
691   :group 'gnus-extract-view
692   :type '(choice (const :tag "off" nil)
693                  (const automatic)
694                  (const not-confirm)))
695
696 (defcustom gnus-view-pseudos-separately t
697   "*If non-nil, one pseudo-article will be created for each file to be viewed.
698 If nil, all files that use the same viewing command will be given as a
699 list of parameters to that command."
700   :group 'gnus-extract-view
701   :type 'boolean)
702
703 (defcustom gnus-insert-pseudo-articles t
704   "*If non-nil, insert pseudo-articles when decoding articles."
705   :group 'gnus-extract-view
706   :type 'boolean)
707
708 (defcustom gnus-summary-dummy-line-format
709   "   %(:                             :%) %S\n"
710   "*The format specification for the dummy roots in the summary buffer.
711 It works along the same lines as a normal formatting string,
712 with some simple extensions.
713
714 %S  The subject
715
716 General format specifiers can also be used.
717 See `(gnus)Formatting Variables'."
718   :link '(custom-manual "(gnus)Formatting Variables")
719   :group 'gnus-threading
720   :type 'string)
721
722 (defcustom gnus-summary-mode-line-format "Gnus: %g [%A] %Z"
723   "*The format specification for the summary mode line.
724 It works along the same lines as a normal formatting string,
725 with some simple extensions:
726
727 %G  Group name
728 %p  Unprefixed group name
729 %A  Current article number
730 %z  Current article score
731 %V  Gnus version
732 %U  Number of unread articles in the group
733 %e  Number of unselected articles in the group
734 %Z  A string with unread/unselected article counts
735 %g  Shortish group name
736 %S  Subject of the current article
737 %u  User-defined spec
738 %s  Current score file name
739 %d  Number of dormant articles
740 %r  Number of articles that have been marked as read in this session
741 %E  Number of articles expunged by the score files"
742   :group 'gnus-summary-format
743   :type 'string)
744
745 (defcustom gnus-list-identifiers nil
746   "Regexp that matches list identifiers to be removed from subject.
747 This can also be a list of regexps."
748   :version "21.1"
749   :group 'gnus-summary-format
750   :group 'gnus-article-hiding
751   :type '(choice (const :tag "none" nil)
752                  (regexp :value ".*")
753                  (repeat :value (".*") regexp)))
754
755 (defcustom gnus-summary-mark-below 0
756   "*Mark all articles with a score below this variable as read.
757 This variable is local to each summary buffer and usually set by the
758 score file."
759   :group 'gnus-score-default
760   :type 'integer)
761
762 (defun gnus-widget-reversible-match (widget value)
763   "Ignoring WIDGET, convert VALUE to internal form.
764 VALUE should have the form `FOO' or `(not FOO)', where FOO is an symbol."
765   ;; (debug value)
766   (or (symbolp value)
767       (and (listp value)
768            (eq (length value) 2)
769            (eq (nth 0 value) 'not)
770            (symbolp (nth 1 value)))))
771
772 (defun gnus-widget-reversible-to-internal (widget value)
773   "Ignoring WIDGET, convert VALUE to internal form.
774 VALUE should have the form `FOO' or `(not FOO)', where FOO is an atom.
775 FOO is converted to (FOO nil) and (not FOO) is converted to (FOO t)."
776   ;; (debug value)
777   (if (atom value)
778       (list value nil)
779     (list (nth 1 value) t)))
780
781 (defun gnus-widget-reversible-to-external (widget value)
782   "Ignoring WIDGET, convert VALUE to external form.
783 VALUE should have the form `(FOO nil)' or `(FOO t)', where FOO is an atom.
784 \(FOO  nil) is converted to FOO and (FOO t) is converted to (not FOO)."
785   ;; (debug value)
786   (if (nth 1 value)
787       (list 'not (nth 0 value))
788     (nth 0 value)))
789
790 (define-widget 'gnus-widget-reversible 'group
791   "A `group' that convert values."
792   :match 'gnus-widget-reversible-match
793   :value-to-internal 'gnus-widget-reversible-to-internal
794   :value-to-external 'gnus-widget-reversible-to-external)
795
796 (defcustom gnus-article-sort-functions '(gnus-article-sort-by-number)
797   "*List of functions used for sorting articles in the summary buffer.
798
799 Each function takes two articles and returns non-nil if the first
800 article should be sorted before the other.  If you use more than one
801 function, the primary sort function should be the last.  You should
802 probably always include `gnus-article-sort-by-number' in the list of
803 sorting functions -- preferably first.  Also note that sorting by date
804 is often much slower than sorting by number, and the sorting order is
805 very similar.  (Sorting by date means sorting by the time the message
806 was sent, sorting by number means sorting by arrival time.)
807
808 Each item can also be a list `(not F)' where F is a function;
809 this reverses the sort order.
810
811 Ready-made functions include `gnus-article-sort-by-number',
812 `gnus-article-sort-by-author', `gnus-article-sort-by-subject',
813 `gnus-article-sort-by-date', `gnus-article-sort-by-random'
814 and `gnus-article-sort-by-score'.
815
816 When threading is turned on, the variable `gnus-thread-sort-functions'
817 controls how articles are sorted."
818   :group 'gnus-summary-sort
819   :type '(repeat (gnus-widget-reversible
820                   (choice (function-item gnus-article-sort-by-number)
821                           (function-item gnus-article-sort-by-author)
822                           (function-item gnus-article-sort-by-subject)
823                           (function-item gnus-article-sort-by-date)
824                           (function-item gnus-article-sort-by-score)
825                           (function-item gnus-article-sort-by-random)
826                           (function :tag "other"))
827                   (boolean :tag "Reverse order"))))
828
829
830 (defcustom gnus-thread-sort-functions '(gnus-thread-sort-by-number)
831   "*List of functions used for sorting threads in the summary buffer.
832 By default, threads are sorted by article number.
833
834 Each function takes two threads and returns non-nil if the first
835 thread should be sorted before the other.  If you use more than one
836 function, the primary sort function should be the last.  You should
837 probably always include `gnus-thread-sort-by-number' in the list of
838 sorting functions -- preferably first.  Also note that sorting by date
839 is often much slower than sorting by number, and the sorting order is
840 very similar.  (Sorting by date means sorting by the time the message
841 was sent, sorting by number means sorting by arrival time.)
842
843 Each list item can also be a list `(not F)' where F is a
844 function; this specifies reversed sort order.
845
846 Ready-made functions include `gnus-thread-sort-by-number',
847 `gnus-thread-sort-by-author', `gnus-thread-sort-by-recipient'
848 `gnus-thread-sort-by-subject', `gnus-thread-sort-by-date',
849 `gnus-thread-sort-by-score', `gnus-thread-sort-by-most-recent-number',
850 `gnus-thread-sort-by-most-recent-date', `gnus-thread-sort-by-random',
851 and `gnus-thread-sort-by-total-score' (see
852 `gnus-thread-score-function').
853
854 When threading is turned off, the variable
855 `gnus-article-sort-functions' controls how articles are sorted."
856   :group 'gnus-summary-sort
857   :type '(repeat
858           (gnus-widget-reversible
859            (choice (function-item gnus-thread-sort-by-number)
860                    (function-item gnus-thread-sort-by-author)
861                    (function-item gnus-thread-sort-by-recipient)
862                    (function-item gnus-thread-sort-by-subject)
863                    (function-item gnus-thread-sort-by-date)
864                    (function-item gnus-thread-sort-by-score)
865                    (function-item gnus-thread-sort-by-most-recent-number)
866                    (function-item gnus-thread-sort-by-most-recent-date)
867                    (function-item gnus-thread-sort-by-random)
868                    (function-item gnus-thread-sort-by-total-score)
869                    (function :tag "other"))
870            (boolean :tag "Reverse order"))))
871
872 (defcustom gnus-thread-score-function '+
873   "*Function used for calculating the total score of a thread.
874
875 The function is called with the scores of the article and each
876 subthread and should then return the score of the thread.
877
878 Some functions you can use are `+', `max', or `min'."
879   :group 'gnus-summary-sort
880   :type 'function)
881
882 (defcustom gnus-summary-expunge-below nil
883   "All articles that have a score less than this variable will be expunged.
884 This variable is local to the summary buffers."
885   :group 'gnus-score-default
886   :type '(choice (const :tag "off" nil)
887                  integer))
888
889 (defcustom gnus-thread-expunge-below nil
890   "All threads that have a total score less than this variable will be expunged.
891 See `gnus-thread-score-function' for en explanation of what a
892 \"thread score\" is.
893
894 This variable is local to the summary buffers."
895   :group 'gnus-threading
896   :group 'gnus-score-default
897   :type '(choice (const :tag "off" nil)
898                  integer))
899
900 (defcustom gnus-summary-mode-hook nil
901   "*A hook for Gnus summary mode.
902 This hook is run before any variables are set in the summary buffer."
903   :options '(turn-on-gnus-mailing-list-mode gnus-pick-mode)
904   :group 'gnus-summary-various
905   :type 'hook)
906
907 ;; Extracted from gnus-xmas-redefine in order to preserve user settings
908 (when (featurep 'xemacs)
909   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-summary-menu-add)
910   (add-hook 'gnus-summary-mode-hook 'gnus-xmas-setup-summary-toolbar)
911   (add-hook 'gnus-summary-mode-hook
912             'gnus-xmas-switch-horizontal-scrollbar-off))
913
914 (defcustom gnus-summary-menu-hook nil
915   "*Hook run after the creation of the summary mode menu."
916   :group 'gnus-summary-visual
917   :type 'hook)
918
919 (defcustom gnus-summary-exit-hook nil
920   "*A hook called on exit from the summary buffer.
921 It will be called with point in the group buffer."
922   :group 'gnus-summary-exit
923   :type 'hook)
924
925 (defcustom gnus-summary-prepare-hook nil
926   "*A hook called after the summary buffer has been generated.
927 If you want to modify the summary buffer, you can use this hook."
928   :group 'gnus-summary-various
929   :type 'hook)
930
931 (defcustom gnus-summary-prepared-hook nil
932   "*A hook called as the last thing after the summary buffer has been generated."
933   :group 'gnus-summary-various
934   :type 'hook)
935
936 (defcustom gnus-summary-generate-hook nil
937   "*A hook run just before generating the summary buffer.
938 This hook is commonly used to customize threading variables and the
939 like."
940   :group 'gnus-summary-various
941   :type 'hook)
942
943 (defcustom gnus-select-group-hook nil
944   "*A hook called when a newsgroup is selected.
945
946 If you'd like to simplify subjects like the
947 `gnus-summary-next-same-subject' command does, you can use the
948 following hook:
949
950  (add-hook gnus-select-group-hook
951            (lambda ()
952              (mapcar (lambda (header)
953                        (mail-header-set-subject
954                         header
955                         (gnus-simplify-subject
956                          (mail-header-subject header) 're-only)))
957                      gnus-newsgroup-headers)))"
958   :group 'gnus-group-select
959   :type 'hook)
960
961 (defcustom gnus-select-article-hook nil
962   "*A hook called when an article is selected."
963   :group 'gnus-summary-choose
964   :options '(gnus-agent-fetch-selected-article)
965   :type 'hook)
966
967 (defcustom gnus-visual-mark-article-hook
968   (list 'gnus-highlight-selected-summary)
969   "*Hook run after selecting an article in the summary buffer.
970 It is meant to be used for highlighting the article in some way.  It
971 is not run if `gnus-visual' is nil."
972   :group 'gnus-summary-visual
973   :type 'hook)
974
975 (defcustom gnus-parse-headers-hook nil
976   "*A hook called before parsing the headers."
977   :group 'gnus-various
978   :type 'hook)
979
980 (defcustom gnus-exit-group-hook nil
981   "*A hook called when exiting summary mode.
982 This hook is not called from the non-updating exit commands like `Q'."
983   :group 'gnus-various
984   :type 'hook)
985
986 (defcustom gnus-summary-update-hook
987   (list 'gnus-summary-highlight-line)
988   "*A hook called when a summary line is changed.
989 The hook will not be called if `gnus-visual' is nil.
990
991 The default function `gnus-summary-highlight-line' will
992 highlight the line according to the `gnus-summary-highlight'
993 variable."
994   :group 'gnus-summary-visual
995   :type 'hook)
996
997 (defcustom gnus-mark-article-hook '(gnus-summary-mark-read-and-unread-as-read)
998   "*A hook called when an article is selected for the first time.
999 The hook is intended to mark an article as read (or unread)
1000 automatically when it is selected."
1001   :group 'gnus-summary-choose
1002   :type 'hook)
1003
1004 (defcustom gnus-group-no-more-groups-hook nil
1005   "*A hook run when returning to group mode having no more (unread) groups."
1006   :group 'gnus-group-select
1007   :type 'hook)
1008
1009 (defcustom gnus-ps-print-hook nil
1010   "*A hook run before ps-printing something from Gnus."
1011   :group 'gnus-summary
1012   :type 'hook)
1013
1014 (defcustom gnus-summary-article-move-hook nil
1015   "*A hook called after an article is moved, copied, respooled, or crossposted."
1016   :version "22.1"
1017   :group 'gnus-summary
1018   :type 'hook)
1019
1020 (defcustom gnus-summary-article-delete-hook nil
1021   "*A hook called after an article is deleted."
1022   :version "22.1"
1023   :group 'gnus-summary
1024   :type 'hook)
1025
1026 (defcustom gnus-summary-article-expire-hook nil
1027   "*A hook called after an article is expired."
1028   :version "22.1"
1029   :group 'gnus-summary
1030   :type 'hook)
1031
1032 (defcustom gnus-summary-display-arrow
1033   (and (fboundp 'display-graphic-p)
1034        (display-graphic-p))
1035   "*If non-nil, display an arrow highlighting the current article."
1036   :version "22.1"
1037   :group 'gnus-summary
1038   :type 'boolean)
1039
1040 (defcustom gnus-summary-selected-face 'gnus-summary-selected
1041   "Face used for highlighting the current article in the summary buffer."
1042   :group 'gnus-summary-visual
1043   :type 'face)
1044
1045 (defvar gnus-tmp-downloaded nil)
1046
1047 (defcustom gnus-summary-highlight
1048   '(((eq mark gnus-canceled-mark)
1049      . gnus-summary-cancelled)
1050     ((and uncached (> score default-high))
1051      . gnus-summary-high-undownloaded)
1052     ((and uncached (< score default-low))
1053      . gnus-summary-low-undownloaded)
1054     (uncached
1055      . gnus-summary-normal-undownloaded)
1056     ((and (> score default-high)
1057           (or (eq mark gnus-dormant-mark)
1058               (eq mark gnus-ticked-mark)))
1059      . gnus-summary-high-ticked)
1060     ((and (< score default-low)
1061           (or (eq mark gnus-dormant-mark)
1062               (eq mark gnus-ticked-mark)))
1063      . gnus-summary-low-ticked)
1064     ((or (eq mark gnus-dormant-mark)
1065          (eq mark gnus-ticked-mark))
1066      . gnus-summary-normal-ticked)
1067     ((and (> score default-high) (eq mark gnus-ancient-mark))
1068      . gnus-summary-high-ancient)
1069     ((and (< score default-low) (eq mark gnus-ancient-mark))
1070      . gnus-summary-low-ancient)
1071     ((eq mark gnus-ancient-mark)
1072      . gnus-summary-normal-ancient)
1073     ((and (> score default-high) (eq mark gnus-unread-mark))
1074      . gnus-summary-high-unread)
1075     ((and (< score default-low) (eq mark gnus-unread-mark))
1076      . gnus-summary-low-unread)
1077     ((eq mark gnus-unread-mark)
1078      . gnus-summary-normal-unread)
1079     ((> score default-high)
1080      . gnus-summary-high-read)
1081     ((< score default-low)
1082      . gnus-summary-low-read)
1083     (t
1084      . gnus-summary-normal-read))
1085   "*Controls the highlighting of summary buffer lines.
1086
1087 A list of (FORM . FACE) pairs.  When deciding how a particular
1088 summary line should be displayed, each form is evaluated.  The content
1089 of the face field after the first true form is used.  You can change
1090 how those summary lines are displayed, by editing the face field.
1091
1092 You can use the following variables in the FORM field.
1093
1094 score:        The article's score.
1095 default:      The default article score.
1096 default-high: The default score for high scored articles.
1097 default-low:  The default score for low scored articles.
1098 below:        The score below which articles are automatically marked as read.
1099 mark:         The article's mark.
1100 uncached:     Non-nil if the article is uncached."
1101   :group 'gnus-summary-visual
1102   :type '(repeat (cons (sexp :tag "Form" nil)
1103                        face)))
1104 (put 'gnus-summary-highlight 'risky-local-variable t)
1105
1106 (defcustom gnus-alter-header-function nil
1107   "Function called to allow alteration of article header structures.
1108 The function is called with one parameter, the article header vector,
1109 which it may alter in any way."
1110   :type '(choice (const :tag "None" nil)
1111                  function)
1112   :group 'gnus-summary)
1113
1114 (defvar gnus-decode-encoded-word-function 'mail-decode-encoded-word-string
1115   "Function used to decode a string with encoded words.")
1116
1117 (defvar gnus-decode-encoded-address-function
1118   'mail-decode-encoded-address-string
1119   "Function used to decode addresses with encoded words.")
1120
1121 (defcustom gnus-extra-headers '(To Newsgroups)
1122   "*Extra headers to parse."
1123   :version "21.1"
1124   :group 'gnus-summary
1125   :type '(repeat symbol))
1126
1127 (defcustom gnus-ignored-from-addresses
1128   (and user-mail-address
1129        (not (string= user-mail-address ""))
1130        (regexp-quote user-mail-address))
1131   "*From headers that may be suppressed in favor of To headers.
1132 This can be a regexp or a list of regexps."
1133   :version "21.1"
1134   :group 'gnus-summary
1135   :type '(choice regexp
1136                  (repeat :tag "Regexp List" regexp)))
1137
1138 (defsubst gnus-ignored-from-addresses ()
1139   (gmm-regexp-concat gnus-ignored-from-addresses))
1140
1141 (defcustom gnus-summary-to-prefix "-> "
1142   "*String prefixed to the To field in the summary line when
1143 using `gnus-ignored-from-addresses'."
1144   :version "22.1"
1145   :group 'gnus-summary
1146   :type 'string)
1147
1148 (defcustom gnus-summary-newsgroup-prefix "=> "
1149   "*String prefixed to the Newsgroup field in the summary
1150 line when using `gnus-ignored-from-addresses'."
1151   :version "22.1"
1152   :group 'gnus-summary
1153   :type 'string)
1154
1155 (defcustom gnus-newsgroup-ignored-charsets '(unknown-8bit x-unknown)
1156   "List of charsets that should be ignored.
1157 When these charsets are used in the \"charset\" parameter, the
1158 default charset will be used instead."
1159   :version "21.1"
1160   :type '(repeat symbol)
1161   :group 'gnus-charset)
1162
1163 (defcustom gnus-newsgroup-maximum-articles nil
1164   "The maximum number of articles a newsgroup.
1165 If this is a number, old articles in a newsgroup exceeding this number
1166 are silently ignored.  If it is nil, no article is ignored.  Note that
1167 setting this variable to a number might prevent you from reading very
1168 old articles."
1169   :group 'gnus-group-select
1170   :version "22.2"
1171   :type '(choice (const :tag "No limit" nil)
1172                  integer))
1173
1174 (gnus-define-group-parameter
1175  ignored-charsets
1176  :type list
1177  :function-document
1178  "Return the ignored charsets of GROUP."
1179  :variable gnus-group-ignored-charsets-alist
1180  :variable-default
1181  '(("alt\\.chinese\\.text" iso-8859-1))
1182  :variable-document
1183  "Alist of regexps (to match group names) and charsets that should be ignored.
1184 When these charsets are used in the \"charset\" parameter, the
1185 default charset will be used instead."
1186  :variable-group gnus-charset
1187  :variable-type '(repeat (cons (regexp :tag "Group")
1188                                (repeat symbol)))
1189  :parameter-type '(choice :tag "Ignored charsets"
1190                           :value nil
1191                           (repeat (symbol)))
1192  :parameter-document       "\
1193 List of charsets that should be ignored.
1194
1195 When these charsets are used in the \"charset\" parameter, the
1196 default charset will be used instead.")
1197
1198 (defcustom gnus-group-highlight-words-alist nil
1199   "Alist of group regexps and highlight regexps.
1200 This variable uses the same syntax as `gnus-emphasis-alist'."
1201   :version "21.1"
1202   :type '(repeat (cons (regexp :tag "Group")
1203                        (repeat (list (regexp :tag "Highlight regexp")
1204                                      (number :tag "Group for entire word" 0)
1205                                      (number :tag "Group for displayed part" 0)
1206                                      (symbol :tag "Face"
1207                                              gnus-emphasis-highlight-words)))))
1208   :group 'gnus-summary-visual)
1209
1210 (defcustom gnus-summary-show-article-charset-alist
1211   nil
1212   "Alist of number and charset.
1213 The article will be shown with the charset corresponding to the
1214 numbered argument.
1215 For example: ((1 . cn-gb-2312) (2 . big5))."
1216   :version "21.1"
1217   :type '(repeat (cons (number :tag "Argument" 1)
1218                        (symbol :tag "Charset")))
1219   :group 'gnus-charset)
1220
1221 (defcustom gnus-preserve-marks t
1222   "Whether marks are preserved when moving, copying and respooling messages."
1223   :version "21.1"
1224   :type 'boolean
1225   :group 'gnus-summary-marks)
1226
1227 (defcustom gnus-propagate-marks t
1228   "If non-nil, do not propagate marks to the backends."
1229   :version "23.1" ;; No Gnus
1230   :type 'boolean
1231   :group 'gnus-summary-marks)
1232
1233 (defcustom gnus-alter-articles-to-read-function nil
1234   "Function to be called to alter the list of articles to be selected."
1235   :type '(choice (const nil) function)
1236   :group 'gnus-summary)
1237
1238 (defcustom gnus-orphan-score nil
1239   "*All orphans get this score added.  Set in the score file."
1240   :group 'gnus-score-default
1241   :type '(choice (const nil)
1242                  integer))
1243
1244 (defcustom gnus-summary-save-parts-default-mime "image/.*"
1245   "*A regexp to match MIME parts when saving multiple parts of a
1246 message with `gnus-summary-save-parts' (\\<gnus-summary-mode-map>\\[gnus-summary-save-parts]).
1247 This regexp will be used by default when prompting the user for which
1248 type of files to save."
1249   :group 'gnus-summary
1250   :type 'regexp)
1251
1252 (defcustom gnus-read-all-available-headers nil
1253   "Whether Gnus should parse all headers made available to it.
1254 This is mostly relevant for slow back ends where the user may
1255 wish to widen the summary buffer to include all headers
1256 that were fetched."
1257   :version "22.1"
1258   :group 'gnus-summary
1259   :type '(choice boolean regexp))
1260
1261 (defcustom gnus-summary-pipe-output-default-command nil
1262   "Command (and optional arguments) used to pipe article to subprocess.
1263 This will be used as the default command if it is non-nil.  The value
1264 will be updated if you modify it when executing the command
1265 `gnus-summary-pipe-output' or the function `gnus-summary-save-in-pipe'."
1266   :version "23.1" ;; No Gnus
1267   :group 'gnus-summary
1268   :type '(radio (const :tag "None" nil) (string :tag "Command")))
1269
1270 (defcustom gnus-summary-muttprint-program "muttprint"
1271   "Command (and optional arguments) used to run Muttprint.
1272 The value will be updated if you modify it when executing the command
1273 `gnus-summary-muttprint'."
1274   :version "22.1"
1275   :group 'gnus-summary
1276   :type 'string)
1277
1278 (defcustom gnus-article-loose-mime t
1279   "If non-nil, don't require MIME-Version header.
1280 Some brain-damaged MUA/MTA, e.g. Lotus Domino 5.0.6 clients, does not
1281 supply the MIME-Version header or deliberately strip it from the mail.
1282 If non-nil (the default), Gnus will treat some articles as MIME
1283 even if the MIME-Version header is missing."
1284   :version "22.1"
1285   :type 'boolean
1286   :group 'gnus-article-mime)
1287
1288 (defcustom gnus-article-emulate-mime t
1289   "If non-nil, use MIME emulation for uuencode and the like.
1290 This means that Gnus will search message bodies for text that look
1291 like uuencoded bits, yEncoded bits, and so on, and present that using
1292 the normal Gnus MIME machinery."
1293   :version "22.1"
1294   :type 'boolean
1295   :group 'gnus-article-mime)
1296
1297 ;;; Internal variables
1298
1299 (defvar gnus-summary-display-cache nil)
1300 (defvar gnus-article-mime-handles nil)
1301 (defvar gnus-article-decoded-p nil)
1302 (defvar gnus-article-charset nil)
1303 (defvar gnus-article-ignored-charsets nil)
1304 (defvar gnus-scores-exclude-files nil)
1305 (defvar gnus-page-broken nil)
1306
1307 (defvar gnus-original-article nil)
1308 (defvar gnus-article-internal-prepare-hook nil)
1309 (defvar gnus-newsgroup-process-stack nil)
1310
1311 (defvar gnus-thread-indent-array nil)
1312 (defvar gnus-thread-indent-array-level gnus-thread-indent-level)
1313 (defvar gnus-sort-gathered-threads-function 'gnus-thread-sort-by-number
1314   "Function called to sort the articles within a thread after it has been gathered together.")
1315
1316 (defvar gnus-summary-save-parts-type-history nil)
1317 (defvar gnus-summary-save-parts-last-directory mm-default-directory)
1318
1319 ;; Avoid highlighting in kill files.
1320 (defvar gnus-summary-inhibit-highlight nil)
1321 (defvar gnus-newsgroup-selected-overlay nil)
1322 (defvar gnus-inhibit-limiting nil)
1323 (defvar gnus-newsgroup-adaptive-score-file nil)
1324 (defvar gnus-current-score-file nil)
1325 (defvar gnus-current-move-group nil)
1326 (defvar gnus-current-copy-group nil)
1327 (defvar gnus-current-crosspost-group nil)
1328 (defvar gnus-newsgroup-display nil)
1329
1330 (defvar gnus-newsgroup-dependencies nil)
1331 (defvar gnus-newsgroup-adaptive nil)
1332 (defvar gnus-summary-display-article-function nil)
1333 (defvar gnus-summary-highlight-line-function nil
1334   "Function called after highlighting a summary line.")
1335
1336 (defvar gnus-summary-line-format-alist
1337   `((?N ,(macroexpand '(mail-header-number gnus-tmp-header)) ?d)
1338     (?S ,(macroexpand '(mail-header-subject gnus-tmp-header)) ?s)
1339     (?s gnus-tmp-subject-or-nil ?s)
1340     (?n gnus-tmp-name ?s)
1341     (?A (car (cdr (funcall gnus-extract-address-components gnus-tmp-from)))
1342         ?s)
1343     (?a (or (car (funcall gnus-extract-address-components gnus-tmp-from))
1344             gnus-tmp-from) ?s)
1345     (?F gnus-tmp-from ?s)
1346     (?x ,(macroexpand '(mail-header-xref gnus-tmp-header)) ?s)
1347     (?D ,(macroexpand '(mail-header-date gnus-tmp-header)) ?s)
1348     (?d (gnus-dd-mmm (mail-header-date gnus-tmp-header)) ?s)
1349     (?o (gnus-date-iso8601 (mail-header-date gnus-tmp-header)) ?s)
1350     (?M ,(macroexpand '(mail-header-id gnus-tmp-header)) ?s)
1351     (?r ,(macroexpand '(mail-header-references gnus-tmp-header)) ?s)
1352     (?c (or (mail-header-chars gnus-tmp-header) 0) ?d)
1353     (?k (gnus-summary-line-message-size gnus-tmp-header) ?s)
1354     (?L gnus-tmp-lines ?s)
1355     (?O gnus-tmp-downloaded ?c)
1356     (?I gnus-tmp-indentation ?s)
1357     (?T (if (= gnus-tmp-level 0) "" (make-string (frame-width) ? )) ?s)
1358     (?R gnus-tmp-replied ?c)
1359     (?\[ gnus-tmp-opening-bracket ?c)
1360     (?\] gnus-tmp-closing-bracket ?c)
1361     (?\> (make-string gnus-tmp-level ? ) ?s)
1362     (?\< (make-string (max 0 (- 20 gnus-tmp-level)) ? ) ?s)
1363     (?i gnus-tmp-score ?d)
1364     (?z gnus-tmp-score-char ?c)
1365     (?V (gnus-thread-total-score (and (boundp 'thread) (car thread))) ?d)
1366     (?U gnus-tmp-unread ?c)
1367     (?f (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)
1368         ?s)
1369     (?t (gnus-summary-number-of-articles-in-thread
1370          (and (boundp 'thread) (car thread)) gnus-tmp-level)
1371         ?d)
1372     (?e (gnus-summary-number-of-articles-in-thread
1373          (and (boundp 'thread) (car thread)) gnus-tmp-level t)
1374         ?c)
1375     (?u gnus-tmp-user-defined ?s)
1376     (?P (gnus-pick-line-number) ?d)
1377     (?B gnus-tmp-thread-tree-header-string ?s)
1378     (user-date (gnus-user-date
1379                 ,(macroexpand '(mail-header-date gnus-tmp-header))) ?s))
1380   "An alist of format specifications that can appear in summary lines.
1381 These are paired with what variables they correspond with, along with
1382 the type of the variable (string, integer, character, etc).")
1383
1384 (defvar gnus-summary-dummy-line-format-alist
1385   `((?S gnus-tmp-subject ?s)
1386     (?N gnus-tmp-number ?d)
1387     (?u gnus-tmp-user-defined ?s)))
1388
1389 (defvar gnus-summary-mode-line-format-alist
1390   `((?G gnus-tmp-group-name ?s)
1391     (?g (gnus-short-group-name gnus-tmp-group-name) ?s)
1392     (?p (gnus-group-real-name gnus-tmp-group-name) ?s)
1393     (?A gnus-tmp-article-number ?d)
1394     (?Z gnus-tmp-unread-and-unselected ?s)
1395     (?V gnus-version ?s)
1396     (?U gnus-tmp-unread-and-unticked ?d)
1397     (?S gnus-tmp-subject ?s)
1398     (?e gnus-tmp-unselected ?d)
1399     (?u gnus-tmp-user-defined ?s)
1400     (?d (length gnus-newsgroup-dormant) ?d)
1401     (?t (length gnus-newsgroup-marked) ?d)
1402     (?h (length gnus-newsgroup-spam-marked) ?d)
1403     (?r (length gnus-newsgroup-reads) ?d)
1404     (?z (gnus-summary-article-score gnus-tmp-article-number) ?d)
1405     (?E gnus-newsgroup-expunged-tally ?d)
1406     (?s (gnus-current-score-file-nondirectory) ?s)))
1407
1408 ;; This is here rather than in gnus-art for compilation reasons.
1409 (defvar gnus-article-mode-line-format-alist
1410   (nconc '((?w (gnus-article-wash-status) ?s)
1411            (?m (gnus-article-mime-part-status) ?s))
1412          gnus-summary-mode-line-format-alist))
1413
1414 (defvar gnus-last-search-regexp nil
1415   "Default regexp for article search command.")
1416
1417 (defvar gnus-last-shell-command nil
1418   "Default shell command on article.")
1419
1420 (defvar gnus-newsgroup-agentized nil
1421   "Locally bound in each summary buffer to indicate whether the server has been agentized.")
1422 (defvar gnus-newsgroup-begin nil)
1423 (defvar gnus-newsgroup-end nil)
1424 (defvar gnus-newsgroup-last-rmail nil)
1425 (defvar gnus-newsgroup-last-mail nil)
1426 (defvar gnus-newsgroup-last-folder nil)
1427 (defvar gnus-newsgroup-last-file nil)
1428 (defvar gnus-newsgroup-last-directory nil)
1429 (defvar gnus-newsgroup-auto-expire nil)
1430 (defvar gnus-newsgroup-active nil)
1431
1432 (defvar gnus-newsgroup-data nil)
1433 (defvar gnus-newsgroup-data-reverse nil)
1434 (defvar gnus-newsgroup-limit nil)
1435 (defvar gnus-newsgroup-limits nil)
1436 (defvar gnus-summary-use-undownloaded-faces nil)
1437
1438 (defvar gnus-newsgroup-unreads nil
1439   "Sorted list of unread articles in the current newsgroup.")
1440
1441 (defvar gnus-newsgroup-unselected nil
1442   "Sorted list of unselected unread articles in the current newsgroup.")
1443
1444 (defvar gnus-newsgroup-reads nil
1445   "Alist of read articles and article marks in the current newsgroup.")
1446
1447 (defvar gnus-newsgroup-expunged-tally nil)
1448
1449 (defvar gnus-newsgroup-marked nil
1450   "Sorted list of ticked articles in the current newsgroup (a subset of unread art).")
1451
1452 (defvar gnus-newsgroup-spam-marked nil
1453   "List of ranges of articles that have been marked as spam.")
1454
1455 (defvar gnus-newsgroup-killed nil
1456   "List of ranges of articles that have been through the scoring process.")
1457
1458 (defvar gnus-newsgroup-cached nil
1459   "Sorted list of articles that come from the article cache.")
1460
1461 (defvar gnus-newsgroup-saved nil
1462   "List of articles that have been saved.")
1463
1464 (defvar gnus-newsgroup-kill-headers nil)
1465
1466 (defvar gnus-newsgroup-replied nil
1467   "List of articles that have been replied to in the current newsgroup.")
1468
1469 (defvar gnus-newsgroup-forwarded nil
1470   "List of articles that have been forwarded in the current newsgroup.")
1471
1472 (defvar gnus-newsgroup-recent nil
1473   "List of articles that have are recent in the current newsgroup.")
1474
1475 (defvar gnus-newsgroup-expirable nil
1476   "Sorted list of articles in the current newsgroup that can be expired.")
1477
1478 (defvar gnus-newsgroup-processable nil
1479   "List of articles in the current newsgroup that can be processed.")
1480
1481 (defvar gnus-newsgroup-downloadable nil
1482   "Sorted list of articles in the current newsgroup that can be processed.")
1483
1484 (defvar gnus-newsgroup-unfetched nil
1485   "Sorted list of articles in the current newsgroup whose headers have
1486 not been fetched into the agent.
1487
1488 This list will always be a subset of gnus-newsgroup-undownloaded.")
1489
1490 (defvar gnus-newsgroup-undownloaded nil
1491   "List of articles in the current newsgroup that haven't been downloaded.")
1492
1493 (defvar gnus-newsgroup-unsendable nil
1494   "List of articles in the current newsgroup that won't be sent.")
1495
1496 (defvar gnus-newsgroup-bookmarks nil
1497   "List of articles in the current newsgroup that have bookmarks.")
1498
1499 (defvar gnus-newsgroup-dormant nil
1500   "Sorted list of dormant articles in the current newsgroup.")
1501
1502 (defvar gnus-newsgroup-unseen nil
1503   "List of unseen articles in the current newsgroup.")
1504
1505 (defvar gnus-newsgroup-seen nil
1506   "Range of seen articles in the current newsgroup.")
1507
1508 (defvar gnus-newsgroup-articles nil
1509   "List of articles in the current newsgroup.")
1510
1511 (defvar gnus-newsgroup-scored nil
1512   "List of scored articles in the current newsgroup.")
1513
1514 (defvar gnus-newsgroup-headers nil
1515   "List of article headers in the current newsgroup.")
1516
1517 (defvar gnus-newsgroup-threads nil)
1518
1519 (defvar gnus-newsgroup-prepared nil
1520   "Whether the current group has been prepared properly.")
1521
1522 (defvar gnus-newsgroup-ancient nil
1523   "List of `gnus-fetch-old-headers' articles in the current newsgroup.")
1524
1525 (defvar gnus-newsgroup-sparse nil)
1526
1527 (defvar gnus-current-article nil)
1528 (defvar gnus-article-current nil)
1529 (defvar gnus-current-headers nil)
1530 (defvar gnus-have-all-headers nil)
1531 (defvar gnus-last-article nil)
1532 (defvar gnus-newsgroup-history nil)
1533 (defvar gnus-newsgroup-charset nil)
1534 (defvar gnus-newsgroup-ephemeral-charset nil)
1535 (defvar gnus-newsgroup-ephemeral-ignored-charsets nil)
1536
1537 (defvar gnus-article-before-search nil)
1538
1539 (defvar gnus-summary-local-variables
1540   '(gnus-newsgroup-name
1541     gnus-newsgroup-begin gnus-newsgroup-end
1542     gnus-newsgroup-last-rmail gnus-newsgroup-last-mail
1543     gnus-newsgroup-last-folder gnus-newsgroup-last-file
1544     gnus-newsgroup-last-directory
1545     gnus-newsgroup-auto-expire gnus-newsgroup-unreads
1546     gnus-newsgroup-unselected gnus-newsgroup-marked
1547     gnus-newsgroup-spam-marked
1548     gnus-newsgroup-reads gnus-newsgroup-saved
1549     gnus-newsgroup-replied gnus-newsgroup-forwarded
1550     gnus-newsgroup-recent
1551     gnus-newsgroup-expirable
1552     gnus-newsgroup-processable gnus-newsgroup-killed
1553     gnus-newsgroup-downloadable gnus-newsgroup-undownloaded
1554     gnus-newsgroup-unfetched
1555     gnus-newsgroup-unsendable gnus-newsgroup-unseen
1556     gnus-newsgroup-seen gnus-newsgroup-articles
1557     gnus-newsgroup-bookmarks gnus-newsgroup-dormant
1558     gnus-newsgroup-headers gnus-newsgroup-threads
1559     gnus-newsgroup-prepared gnus-summary-highlight-line-function
1560     gnus-current-article gnus-current-headers gnus-have-all-headers
1561     gnus-last-article gnus-article-internal-prepare-hook
1562     gnus-newsgroup-dependencies gnus-newsgroup-selected-overlay
1563     gnus-newsgroup-scored gnus-newsgroup-kill-headers
1564     gnus-thread-expunge-below
1565     gnus-score-alist gnus-current-score-file
1566     (gnus-summary-expunge-below . global)
1567     (gnus-summary-mark-below . global)
1568     (gnus-orphan-score . global)
1569     gnus-newsgroup-active gnus-scores-exclude-files
1570     gnus-newsgroup-history gnus-newsgroup-ancient
1571     gnus-newsgroup-sparse gnus-newsgroup-process-stack
1572     (gnus-newsgroup-adaptive . gnus-use-adaptive-scoring)
1573     gnus-newsgroup-adaptive-score-file (gnus-reffed-article-number . -1)
1574     (gnus-newsgroup-expunged-tally . 0)
1575     gnus-cache-removable-articles gnus-newsgroup-cached
1576     gnus-newsgroup-data gnus-newsgroup-data-reverse
1577     gnus-newsgroup-limit gnus-newsgroup-limits
1578     gnus-newsgroup-charset gnus-newsgroup-display
1579     gnus-summary-use-undownloaded-faces)
1580   "Variables that are buffer-local to the summary buffers.")
1581
1582 (defvar gnus-newsgroup-variables nil
1583   "A list of variables that have separate values in different newsgroups.
1584 A list of newsgroup (summary buffer) local variables, or cons of
1585 variables and their default expressions to be evalled (when the default
1586 values are not nil), that should be made global while the summary buffer
1587 is active.
1588
1589 Note: The default expressions will be evaluated (using function `eval')
1590 before assignment to the local variable rather than just assigned to it.
1591 If the default expression is the symbol `global', that symbol will not
1592 be evaluated but the global value of the local variable will be used
1593 instead.
1594
1595 These variables can be used to set variables in the group parameters
1596 while still allowing them to affect operations done in other buffers.
1597 For example:
1598
1599 \(setq gnus-newsgroup-variables
1600      '(message-use-followup-to
1601        (gnus-visible-headers .
1602          \"^From:\\\\|^Newsgroups:\\\\|^Subject:\\\\|^Date:\\\\|^To:\")))
1603 ")
1604
1605 (eval-when-compile
1606   ;; Bind features so that require will believe that gnus-sum has
1607   ;; already been loaded (avoids infinite recursion)
1608   (let ((features (cons 'gnus-sum features)))
1609     (require 'gnus-art)))
1610
1611 ;; MIME stuff.
1612
1613 (defvar gnus-decode-encoded-word-methods
1614   '(mail-decode-encoded-word-string)
1615   "List of methods used to decode encoded words.
1616
1617 This variable is a list of FUNCTION or (REGEXP . FUNCTION).  If item
1618 is FUNCTION, FUNCTION will be apply to all newsgroups.  If item is a
1619 \(REGEXP . FUNCTION), FUNCTION will be only apply to thes newsgroups
1620 whose names match REGEXP.
1621
1622 For example:
1623 \((\"chinese\" . gnus-decode-encoded-word-string-by-guess)
1624  mail-decode-encoded-word-string
1625  (\"chinese\" . rfc1843-decode-string))")
1626
1627 (defvar gnus-decode-encoded-word-methods-cache nil)
1628
1629 (defun gnus-multi-decode-encoded-word-string (string)
1630   "Apply the functions from `gnus-encoded-word-methods' that match."
1631   (unless (and gnus-decode-encoded-word-methods-cache
1632                (eq gnus-newsgroup-name
1633                    (car gnus-decode-encoded-word-methods-cache)))
1634     (setq gnus-decode-encoded-word-methods-cache (list gnus-newsgroup-name))
1635     (dolist (method gnus-decode-encoded-word-methods)
1636       (if (symbolp method)
1637           (nconc gnus-decode-encoded-word-methods-cache (list method))
1638         (if (and gnus-newsgroup-name
1639                  (string-match (car method) gnus-newsgroup-name))
1640             (nconc gnus-decode-encoded-word-methods-cache
1641                    (list (cdr method)))))))
1642   (dolist (method (cdr gnus-decode-encoded-word-methods-cache) string)
1643     (setq string (funcall method string))))
1644
1645 ;; Subject simplification.
1646
1647 (defun gnus-simplify-whitespace (str)
1648   "Remove excessive whitespace from STR."
1649   ;; Multiple spaces.
1650   (while (string-match "[ \t][ \t]+" str)
1651     (setq str (concat (substring str 0 (match-beginning 0))
1652                         " "
1653                         (substring str (match-end 0)))))
1654   ;; Leading spaces.
1655   (when (string-match "^[ \t]+" str)
1656     (setq str (substring str (match-end 0))))
1657   ;; Trailing spaces.
1658   (when (string-match "[ \t]+$" str)
1659     (setq str (substring str 0 (match-beginning 0))))
1660   str)
1661
1662 (defun gnus-simplify-all-whitespace (str)
1663   "Remove all whitespace from STR."
1664   (while (string-match "[ \t\n]+" str)
1665     (setq str (replace-match "" nil nil str)))
1666   str)
1667
1668 (defsubst gnus-simplify-subject-re (subject)
1669   "Remove \"Re:\" from subject lines."
1670   (if (string-match message-subject-re-regexp subject)
1671       (substring subject (match-end 0))
1672     subject))
1673
1674 (defun gnus-simplify-subject (subject &optional re-only)
1675   "Remove `Re:' and words in parentheses.
1676 If RE-ONLY is non-nil, strip leading `Re:'s only."
1677   (let ((case-fold-search t))           ;Ignore case.
1678     ;; Remove `Re:', `Re^N:', `Re(n)', and `Re[n]:'.
1679     (when (string-match "\\`\\(re\\([[(^][0-9]+[])]?\\)?:[ \t]*\\)+" subject)
1680       (setq subject (substring subject (match-end 0))))
1681     ;; Remove uninteresting prefixes.
1682     (when (and (not re-only)
1683                gnus-simplify-ignored-prefixes
1684                (string-match gnus-simplify-ignored-prefixes subject))
1685       (setq subject (substring subject (match-end 0))))
1686     ;; Remove words in parentheses from end.
1687     (unless re-only
1688       (while (string-match "[ \t\n]*([^()]*)[ \t\n]*\\'" subject)
1689         (setq subject (substring subject 0 (match-beginning 0)))))
1690     ;; Return subject string.
1691     subject))
1692
1693 ;; Remove any leading "re:"s, any trailing paren phrases, and simplify
1694 ;; all whitespace.
1695 (defsubst gnus-simplify-buffer-fuzzy-step (regexp &optional newtext)
1696   (goto-char (point-min))
1697   (while (re-search-forward regexp nil t)
1698     (replace-match (or newtext ""))))
1699
1700 (defun gnus-simplify-buffer-fuzzy ()
1701   "Simplify string in the buffer fuzzily.
1702 The string in the accessible portion of the current buffer is simplified.
1703 It is assumed to be a single-line subject.
1704 Whitespace is generally cleaned up, and miscellaneous leading/trailing
1705 matter is removed.  Additional things can be deleted by setting
1706 `gnus-simplify-subject-fuzzy-regexp'."
1707   (let ((case-fold-search t)
1708         (modified-tick))
1709     (gnus-simplify-buffer-fuzzy-step "\t" " ")
1710
1711     (while (not (eq modified-tick (buffer-modified-tick)))
1712       (setq modified-tick (buffer-modified-tick))
1713       (cond
1714        ((listp gnus-simplify-subject-fuzzy-regexp)
1715         (mapc 'gnus-simplify-buffer-fuzzy-step
1716               gnus-simplify-subject-fuzzy-regexp))
1717        (gnus-simplify-subject-fuzzy-regexp
1718         (gnus-simplify-buffer-fuzzy-step gnus-simplify-subject-fuzzy-regexp)))
1719       (gnus-simplify-buffer-fuzzy-step "^ *\\[[-+?*!][-+?*!]\\] *")
1720       (gnus-simplify-buffer-fuzzy-step
1721        "^ *\\(re\\|fw\\|fwd\\)[[{(^0-9]*[])}]?[:;] *")
1722       (gnus-simplify-buffer-fuzzy-step "^[[].*:\\( .*\\)[]]$" "\\1"))
1723
1724     (gnus-simplify-buffer-fuzzy-step " *[[{(][^()\n]*[]})] *$")
1725     (gnus-simplify-buffer-fuzzy-step "  +" " ")
1726     (gnus-simplify-buffer-fuzzy-step " $")
1727     (gnus-simplify-buffer-fuzzy-step "^ +")))
1728
1729 (defun gnus-simplify-subject-fuzzy (subject)
1730   "Simplify a subject string fuzzily.
1731 See `gnus-simplify-buffer-fuzzy' for details."
1732   (save-excursion
1733     (gnus-set-work-buffer)
1734     (let ((case-fold-search t))
1735       ;; Remove uninteresting prefixes.
1736       (when (and gnus-simplify-ignored-prefixes
1737                  (string-match gnus-simplify-ignored-prefixes subject))
1738         (setq subject (substring subject (match-end 0))))
1739       (insert subject)
1740       (inline (gnus-simplify-buffer-fuzzy))
1741       (buffer-string))))
1742
1743 (defsubst gnus-simplify-subject-fully (subject)
1744   "Simplify a subject string according to `gnus-summary-gather-subject-limit'."
1745   (cond
1746    (gnus-simplify-subject-functions
1747     (gnus-map-function gnus-simplify-subject-functions subject))
1748    ((null gnus-summary-gather-subject-limit)
1749     (gnus-simplify-subject-re subject))
1750    ((eq gnus-summary-gather-subject-limit 'fuzzy)
1751     (gnus-simplify-subject-fuzzy subject))
1752    ((numberp gnus-summary-gather-subject-limit)
1753     (truncate-string-to-width (gnus-simplify-subject-re subject)
1754                               gnus-summary-gather-subject-limit))
1755    (t
1756     subject)))
1757
1758 (defsubst gnus-subject-equal (s1 s2 &optional simple-first)
1759   "Check whether two subjects are equal.
1760 If optional argument SIMPLE-FIRST is t, first argument is already
1761 simplified."
1762   (cond
1763    ((null simple-first)
1764     (equal (gnus-simplify-subject-fully s1)
1765            (gnus-simplify-subject-fully s2)))
1766    (t
1767     (equal s1
1768            (gnus-simplify-subject-fully s2)))))
1769
1770 (defun gnus-summary-bubble-group ()
1771   "Increase the score of the current group.
1772 This is a handy function to add to `gnus-summary-exit-hook' to
1773 increase the score of each group you read."
1774   (gnus-group-add-score gnus-newsgroup-name))
1775
1776 \f
1777 ;;;
1778 ;;; Gnus summary mode
1779 ;;;
1780
1781 (put 'gnus-summary-mode 'mode-class 'special)
1782
1783 (defvar gnus-article-commands-menu)
1784
1785 ;; Non-orthogonal keys
1786
1787 (gnus-define-keys gnus-summary-mode-map
1788   " " gnus-summary-next-page
1789   "\177" gnus-summary-prev-page
1790   [delete] gnus-summary-prev-page
1791   [backspace] gnus-summary-prev-page
1792   "\r" gnus-summary-scroll-up
1793   "\M-\r" gnus-summary-scroll-down
1794   "n" gnus-summary-next-unread-article
1795   "p" gnus-summary-prev-unread-article
1796   "N" gnus-summary-next-article
1797   "P" gnus-summary-prev-article
1798   "\M-\C-n" gnus-summary-next-same-subject
1799   "\M-\C-p" gnus-summary-prev-same-subject
1800   "\M-n" gnus-summary-next-unread-subject
1801   "\M-p" gnus-summary-prev-unread-subject
1802   "." gnus-summary-first-unread-article
1803   "," gnus-summary-best-unread-article
1804   "\M-s" gnus-summary-search-article-forward
1805   "\M-r" gnus-summary-search-article-backward
1806   "\M-S" gnus-summary-repeat-search-article-forward
1807   "\M-R" gnus-summary-repeat-search-article-backward
1808   "<" gnus-summary-beginning-of-article
1809   ">" gnus-summary-end-of-article
1810   "j" gnus-summary-goto-article
1811   "^" gnus-summary-refer-parent-article
1812   "\M-^" gnus-summary-refer-article
1813   "u" gnus-summary-tick-article-forward
1814   "!" gnus-summary-tick-article-forward
1815   "U" gnus-summary-tick-article-backward
1816   "d" gnus-summary-mark-as-read-forward
1817   "D" gnus-summary-mark-as-read-backward
1818   "E" gnus-summary-mark-as-expirable
1819   "\M-u" gnus-summary-clear-mark-forward
1820   "\M-U" gnus-summary-clear-mark-backward
1821   "k" gnus-summary-kill-same-subject-and-select
1822   "\C-k" gnus-summary-kill-same-subject
1823   "\M-\C-k" gnus-summary-kill-thread
1824   "\M-\C-l" gnus-summary-lower-thread
1825   "e" gnus-summary-edit-article
1826   "#" gnus-summary-mark-as-processable
1827   "\M-#" gnus-summary-unmark-as-processable
1828   "\M-\C-t" gnus-summary-toggle-threads
1829   "\M-\C-s" gnus-summary-show-thread
1830   "\M-\C-h" gnus-summary-hide-thread
1831   "\M-\C-f" gnus-summary-next-thread
1832   "\M-\C-b" gnus-summary-prev-thread
1833   [(meta down)] gnus-summary-next-thread
1834   [(meta up)] gnus-summary-prev-thread
1835   "\M-\C-u" gnus-summary-up-thread
1836   "\M-\C-d" gnus-summary-down-thread
1837   "&" gnus-summary-execute-command
1838   "c" gnus-summary-catchup-and-exit
1839   "\C-w" gnus-summary-mark-region-as-read
1840   "\C-t" gnus-summary-toggle-truncation
1841   "?" gnus-summary-mark-as-dormant
1842   "\C-c\M-\C-s" gnus-summary-limit-include-expunged
1843   "\C-c\C-s\C-n" gnus-summary-sort-by-number
1844   "\C-c\C-s\C-m\C-n" gnus-summary-sort-by-most-recent-number
1845   "\C-c\C-s\C-l" gnus-summary-sort-by-lines
1846   "\C-c\C-s\C-c" gnus-summary-sort-by-chars
1847   "\C-c\C-s\C-a" gnus-summary-sort-by-author
1848   "\C-c\C-s\C-t" gnus-summary-sort-by-recipient
1849   "\C-c\C-s\C-s" gnus-summary-sort-by-subject
1850   "\C-c\C-s\C-d" gnus-summary-sort-by-date
1851   "\C-c\C-s\C-m\C-d" gnus-summary-sort-by-most-recent-date
1852   "\C-c\C-s\C-i" gnus-summary-sort-by-score
1853   "\C-c\C-s\C-o" gnus-summary-sort-by-original
1854   "\C-c\C-s\C-r" gnus-summary-sort-by-random
1855   "=" gnus-summary-expand-window
1856   "\C-x\C-s" gnus-summary-reselect-current-group
1857   "\M-g" gnus-summary-rescan-group
1858   "\C-c\C-r" gnus-summary-caesar-message
1859   "f" gnus-summary-followup
1860   "F" gnus-summary-followup-with-original
1861   "C" gnus-summary-cancel-article
1862   "r" gnus-summary-reply
1863   "R" gnus-summary-reply-with-original
1864   "\C-c\C-f" gnus-summary-mail-forward
1865   "o" gnus-summary-save-article
1866   "\C-o" gnus-summary-save-article-mail
1867   "|" gnus-summary-pipe-output
1868   "\M-k" gnus-summary-edit-local-kill
1869   "\M-K" gnus-summary-edit-global-kill
1870   ;; "V" gnus-version
1871   "\C-c\C-d" gnus-summary-describe-group
1872   "q" gnus-summary-exit
1873   "Q" gnus-summary-exit-no-update
1874   "\C-c\C-i" gnus-info-find-node
1875   gnus-mouse-2 gnus-mouse-pick-article
1876   [follow-link] mouse-face
1877   "m" gnus-summary-mail-other-window
1878   "a" gnus-summary-post-news
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
2180 (gnus-define-keys (gnus-summary-mime-map "K" gnus-summary-mode-map)
2181   "b" gnus-summary-display-buttonized
2182   "m" gnus-summary-repair-multipart
2183   "v" gnus-article-view-part
2184   "o" gnus-article-save-part
2185   "O" gnus-article-save-part-and-strip
2186   "r" gnus-article-replace-part
2187   "d" gnus-article-delete-part
2188   "t" gnus-article-view-part-as-type
2189   "j" gnus-article-jump-to-part
2190   "c" gnus-article-copy-part
2191   "C" gnus-article-view-part-as-charset
2192   "e" gnus-article-view-part-externally
2193   "H" gnus-article-browse-html-article
2194   "E" gnus-article-encrypt-body
2195   "i" gnus-article-inline-part
2196   "|" gnus-article-pipe-part)
2197
2198 (gnus-define-keys (gnus-uu-mark-map "P" gnus-summary-mark-map)
2199   "p" gnus-summary-mark-as-processable
2200   "u" gnus-summary-unmark-as-processable
2201   "U" gnus-summary-unmark-all-processable
2202   "v" gnus-uu-mark-over
2203   "s" gnus-uu-mark-series
2204   "r" gnus-uu-mark-region
2205   "g" gnus-uu-unmark-region
2206   "R" gnus-uu-mark-by-regexp
2207   "G" gnus-uu-unmark-by-regexp
2208   "t" gnus-uu-mark-thread
2209   "T" gnus-uu-unmark-thread
2210   "a" gnus-uu-mark-all
2211   "b" gnus-uu-mark-buffer
2212   "S" gnus-uu-mark-sparse
2213   "k" gnus-summary-kill-process-mark
2214   "y" gnus-summary-yank-process-mark
2215   "w" gnus-summary-save-process-mark
2216   "i" gnus-uu-invert-processable)
2217
2218 (gnus-define-keys (gnus-uu-extract-map "X" gnus-summary-mode-map)
2219   ;;"x" gnus-uu-extract-any
2220   "m" gnus-summary-save-parts
2221   "u" gnus-uu-decode-uu
2222   "U" gnus-uu-decode-uu-and-save
2223   "s" gnus-uu-decode-unshar
2224   "S" gnus-uu-decode-unshar-and-save
2225   "o" gnus-uu-decode-save
2226   "O" gnus-uu-decode-save
2227   "b" gnus-uu-decode-binhex
2228   "B" gnus-uu-decode-binhex
2229   "Y" gnus-uu-decode-yenc
2230   "p" gnus-uu-decode-postscript
2231   "P" gnus-uu-decode-postscript-and-save)
2232
2233 (gnus-define-keys
2234     (gnus-uu-extract-view-map "v" gnus-uu-extract-map)
2235   "u" gnus-uu-decode-uu-view
2236   "U" gnus-uu-decode-uu-and-save-view
2237   "s" gnus-uu-decode-unshar-view
2238   "S" gnus-uu-decode-unshar-and-save-view
2239   "o" gnus-uu-decode-save-view
2240   "O" gnus-uu-decode-save-view
2241   "b" gnus-uu-decode-binhex-view
2242   "B" gnus-uu-decode-binhex-view
2243   "p" gnus-uu-decode-postscript-view
2244   "P" gnus-uu-decode-postscript-and-save-view)
2245
2246 (defvar gnus-article-post-menu nil)
2247
2248 (defconst gnus-summary-menu-maxlen 20)
2249
2250 (defun gnus-summary-menu-split (menu)
2251   ;; If we have lots of elements, divide them into groups of 20
2252   ;; and make a pane (or submenu) for each one.
2253   (if (> (length menu) (/ (* gnus-summary-menu-maxlen 3) 2))
2254       (let ((menu menu) sublists next
2255             (i 1))
2256         (while menu
2257           ;; Pull off the next gnus-summary-menu-maxlen elements
2258           ;; and make them the next element of sublist.
2259           (setq next (nthcdr gnus-summary-menu-maxlen menu))
2260           (if next
2261               (setcdr (nthcdr (1- gnus-summary-menu-maxlen) menu)
2262                       nil))
2263           (setq sublists (cons (cons (format "%s ... %s" (aref (car menu) 0)
2264                                              (aref (car (last menu)) 0)) menu)
2265                                sublists))
2266           (setq i (1+ i))
2267           (setq menu next))
2268         (nreverse sublists))
2269     ;; Few elements--put them all in one pane.
2270     menu))
2271
2272 (defun gnus-summary-make-menu-bar ()
2273   (gnus-turn-off-edit-menu 'summary)
2274
2275   (unless (boundp 'gnus-summary-misc-menu)
2276
2277     (easy-menu-define
2278       gnus-summary-kill-menu gnus-summary-mode-map ""
2279       (cons
2280        "Score"
2281        (nconc
2282         (list
2283          ["Customize" gnus-score-customize t])
2284         (gnus-make-score-map 'increase)
2285         (gnus-make-score-map 'lower)
2286         '(("Mark"
2287            ["Kill below" gnus-summary-kill-below t]
2288            ["Mark above" gnus-summary-mark-above t]
2289            ["Tick above" gnus-summary-tick-above t]
2290            ["Clear above" gnus-summary-clear-above t])
2291           ["Current score" gnus-summary-current-score t]
2292           ["Set score" gnus-summary-set-score t]
2293           ["Switch current score file..." gnus-score-change-score-file t]
2294           ["Set mark below..." gnus-score-set-mark-below t]
2295           ["Set expunge below..." gnus-score-set-expunge-below t]
2296           ["Edit current score file" gnus-score-edit-current-scores t]
2297           ["Edit score file..." gnus-score-edit-file t]
2298           ["Trace score" gnus-score-find-trace t]
2299           ["Find words" gnus-score-find-favourite-words t]
2300           ["Rescore buffer" gnus-summary-rescore t]
2301           ["Increase score..." gnus-summary-increase-score t]
2302           ["Lower score..." gnus-summary-lower-score t]))))
2303
2304     ;; Define both the Article menu in the summary buffer and the
2305     ;; equivalent Commands menu in the article buffer here for
2306     ;; consistency.
2307     (let ((innards
2308            `(("Hide"
2309               ["All" gnus-article-hide t]
2310               ["Headers" gnus-article-hide-headers t]
2311               ["Signature" gnus-article-hide-signature t]
2312               ["Citation" gnus-article-hide-citation t]
2313               ["List identifiers" gnus-article-hide-list-identifiers t]
2314               ["Banner" gnus-article-strip-banner t]
2315               ["Boring headers" gnus-article-hide-boring-headers t])
2316              ("Highlight"
2317               ["All" gnus-article-highlight t]
2318               ["Headers" gnus-article-highlight-headers t]
2319               ["Signature" gnus-article-highlight-signature t]
2320               ["Citation" gnus-article-highlight-citation t])
2321              ("MIME"
2322               ["Words" gnus-article-decode-mime-words t]
2323               ["Charset" gnus-article-decode-charset t]
2324               ["QP" gnus-article-de-quoted-unreadable t]
2325               ["Base64" gnus-article-de-base64-unreadable t]
2326               ["View MIME buttons" gnus-summary-display-buttonized t]
2327               ["View all" gnus-mime-view-all-parts t]
2328               ["Verify and Decrypt" gnus-summary-force-verify-and-decrypt t]
2329               ["Encrypt body" gnus-article-encrypt-body
2330                :active (not (gnus-group-read-only-p))
2331                ,@(if (featurep 'xemacs) nil
2332                    '(:help "Encrypt the message body on disk"))]
2333               ["Extract all parts..." gnus-summary-save-parts t]
2334               ("Multipart"
2335                ["Repair multipart" gnus-summary-repair-multipart t]
2336                ["Pipe part..." gnus-article-pipe-part t]
2337                ["Inline part" gnus-article-inline-part t]
2338                ["View part as type..." gnus-article-view-part-as-type t]
2339                ["Encrypt body" gnus-article-encrypt-body
2340                 :active (not (gnus-group-read-only-p))
2341                ,@(if (featurep 'xemacs) nil
2342                    '(:help "Encrypt the message body on disk"))]
2343                ["View part externally" gnus-article-view-part-externally t]
2344                ["View HTML parts in browser" gnus-article-browse-html-article t]
2345                ["View part with charset..." gnus-article-view-part-as-charset t]
2346                ["Copy part" gnus-article-copy-part t]
2347                ["Save part..." gnus-article-save-part t]
2348                ["View part" gnus-article-view-part t]))
2349              ("Date"
2350               ["Local" gnus-article-date-local t]
2351               ["ISO8601" gnus-article-date-iso8601 t]
2352               ["UT" gnus-article-date-ut t]
2353               ["Original" gnus-article-date-original t]
2354               ["Lapsed" gnus-article-date-lapsed t]
2355               ["User-defined" gnus-article-date-user t])
2356              ("Display"
2357               ["Remove images" gnus-article-remove-images t]
2358               ["Toggle smiley" gnus-treat-smiley t]
2359               ["Show X-Face" gnus-article-display-x-face t]
2360               ["Show picons in From" gnus-treat-from-picon t]
2361               ["Show picons in mail headers" gnus-treat-mail-picon t]
2362               ["Show picons in news headers" gnus-treat-newsgroups-picon t]
2363               ("View as different encoding"
2364                ,@(gnus-summary-menu-split
2365                   (mapcar
2366                    (lambda (cs)
2367                      ;; Since easymenu under Emacs doesn't allow
2368                      ;; lambda forms for menu commands, we should
2369                      ;; provide intern'ed function symbols.
2370                      (let ((command (intern (format "\
2371 gnus-summary-show-article-from-menu-as-charset-%s" cs))))
2372                        (fset command
2373                              `(lambda ()
2374                                 (interactive)
2375                                 (let ((gnus-summary-show-article-charset-alist
2376                                        '((1 . ,cs))))
2377                                   (gnus-summary-show-article 1))))
2378                        `[,(symbol-name cs) ,command t]))
2379                    (sort (if (fboundp 'coding-system-list)
2380                              (coding-system-list)
2381                            (mapcar 'car mm-mime-mule-charset-alist))
2382                          'string<)))))
2383              ("Washing"
2384               ("Remove Blanks"
2385                ["Leading" gnus-article-strip-leading-blank-lines t]
2386                ["Multiple" gnus-article-strip-multiple-blank-lines t]
2387                ["Trailing" gnus-article-remove-trailing-blank-lines t]
2388                ["All of the above" gnus-article-strip-blank-lines t]
2389                ["All" gnus-article-strip-all-blank-lines t]
2390                ["Leading space" gnus-article-strip-leading-space t]
2391                ["Trailing space" gnus-article-strip-trailing-space t]
2392                ["Leading space in headers"
2393                 gnus-article-remove-leading-whitespace t])
2394               ["Overstrike" gnus-article-treat-overstrike t]
2395               ["Dumb quotes" gnus-article-treat-dumbquotes t]
2396               ["Emphasis" gnus-article-emphasize t]
2397               ["Word wrap" gnus-article-fill-cited-article t]
2398               ["Fill long lines" gnus-article-fill-long-lines t]
2399               ["Toggle truncate long lines" gnus-article-toggle-truncate-lines t]
2400               ["Capitalize sentences" gnus-article-capitalize-sentences t]
2401               ["Remove CR" gnus-article-remove-cr t]
2402               ["Quoted-Printable" gnus-article-de-quoted-unreadable t]
2403               ["Base64" gnus-article-de-base64-unreadable t]
2404               ["Rot 13" gnus-summary-caesar-message
2405                ,@(if (featurep 'xemacs) '(t)
2406                    '(:help "\"Caesar rotate\" article by 13"))]
2407               ["De-IDNA" gnus-summary-idna-message t]
2408               ["Morse decode" gnus-summary-morse-message t]
2409               ["Unix pipe..." gnus-summary-pipe-message t]
2410               ["Add buttons" gnus-article-add-buttons t]
2411               ["Add buttons to head" gnus-article-add-buttons-to-head t]
2412               ["Stop page breaking" gnus-summary-stop-page-breaking t]
2413               ["Verbose header" gnus-summary-verbose-headers t]
2414               ["Toggle header" gnus-summary-toggle-header t]
2415               ["Unfold headers" gnus-article-treat-unfold-headers t]
2416               ["Fold newsgroups" gnus-article-treat-fold-newsgroups t]
2417               ["Html" gnus-article-wash-html t]
2418               ["Unsplit URLs" gnus-article-unsplit-urls t]
2419               ["Verify X-PGP-Sig" gnus-article-verify-x-pgp-sig t]
2420               ["Decode HZ" gnus-article-decode-HZ t]
2421               ["ANSI sequences" gnus-article-treat-ansi-sequences t]
2422               ("(Outlook) Deuglify"
2423                ["Unwrap lines" gnus-article-outlook-unwrap-lines t]
2424                ["Repair attribution" gnus-article-outlook-repair-attribution t]
2425                ["Rearrange citation" gnus-article-outlook-rearrange-citation t]
2426                ["Full (Outlook) deuglify"
2427                 gnus-article-outlook-deuglify-article t])
2428               )
2429              ("Output"
2430               ["Save in default format..." gnus-summary-save-article
2431                ,@(if (featurep 'xemacs) '(t)
2432                    '(:help "Save article using default method"))]
2433               ["Save in file..." gnus-summary-save-article-file
2434                ,@(if (featurep 'xemacs) '(t)
2435                    '(:help "Save article in file"))]
2436               ["Save in Unix mail format..." gnus-summary-save-article-mail t]
2437               ["Save in MH folder..." gnus-summary-save-article-folder t]
2438               ["Save in VM folder..." gnus-summary-save-article-vm t]
2439               ["Save in RMAIL mbox..." gnus-summary-save-article-rmail t]
2440               ["Save body in file..." gnus-summary-save-article-body-file t]
2441               ["Pipe through a filter..." gnus-summary-pipe-output t]
2442               ["Print with Muttprint..." gnus-summary-muttprint t]
2443               ["Print" gnus-summary-print-article
2444                ,@(if (featurep 'xemacs) '(t)
2445                    '(:help "Generate and print a PostScript image"))])
2446              ("Copy, move,... (Backend)"
2447               ,@(if (featurep 'xemacs) nil
2448                   '(:help "Copying, moving, expiring articles..."))
2449               ["Respool article..." gnus-summary-respool-article t]
2450               ["Move article..." gnus-summary-move-article
2451                (gnus-check-backend-function
2452                 'request-move-article gnus-newsgroup-name)]
2453               ["Copy article..." gnus-summary-copy-article t]
2454               ["Crosspost article..." gnus-summary-crosspost-article
2455                (gnus-check-backend-function
2456                 'request-replace-article gnus-newsgroup-name)]
2457               ["Import file..." gnus-summary-import-article
2458                (gnus-check-backend-function
2459                 'request-accept-article gnus-newsgroup-name)]
2460               ["Create article..." gnus-summary-create-article
2461                (gnus-check-backend-function
2462                 'request-accept-article gnus-newsgroup-name)]
2463               ["Check if posted" gnus-summary-article-posted-p t]
2464               ["Edit article" gnus-summary-edit-article
2465                (not (gnus-group-read-only-p))]
2466               ["Delete article" gnus-summary-delete-article
2467                (gnus-check-backend-function
2468                 'request-expire-articles gnus-newsgroup-name)]
2469               ["Query respool" gnus-summary-respool-query t]
2470               ["Trace respool" gnus-summary-respool-trace t]
2471               ["Delete expirable articles" gnus-summary-expire-articles-now
2472                (gnus-check-backend-function
2473                 'request-expire-articles gnus-newsgroup-name)])
2474              ("Extract"
2475               ["Uudecode" gnus-uu-decode-uu
2476                ,@(if (featurep 'xemacs) '(t)
2477                    '(:help "Decode uuencoded article(s)"))]
2478               ["Uudecode and save" gnus-uu-decode-uu-and-save t]
2479               ["Unshar" gnus-uu-decode-unshar t]
2480               ["Unshar and save" gnus-uu-decode-unshar-and-save t]
2481               ["Save" gnus-uu-decode-save t]
2482               ["Binhex" gnus-uu-decode-binhex t]
2483               ["Postscript" gnus-uu-decode-postscript t]
2484               ["All MIME parts" gnus-summary-save-parts t])
2485              ("Cache"
2486               ["Enter article" gnus-cache-enter-article t]
2487               ["Remove article" gnus-cache-remove-article t])
2488              ["Translate" gnus-article-babel t]
2489              ["Select article buffer" gnus-summary-select-article-buffer t]
2490              ["Make article buffer sticky" gnus-sticky-article t]
2491              ["Enter digest buffer" gnus-summary-enter-digest-group t]
2492              ["Isearch article..." gnus-summary-isearch-article t]
2493              ["Beginning of the article" gnus-summary-beginning-of-article t]
2494              ["End of the article" gnus-summary-end-of-article t]
2495              ["Fetch parent of article" gnus-summary-refer-parent-article t]
2496              ["Fetch referenced articles" gnus-summary-refer-references t]
2497              ["Fetch current thread" gnus-summary-refer-thread t]
2498              ["Fetch article with id..." gnus-summary-refer-article t]
2499              ["Setup Mailing List Params" gnus-mailing-list-insinuate t]
2500              ["Redisplay" gnus-summary-show-article t]
2501              ["Raw article" gnus-summary-show-raw-article :keys "C-u g"])))
2502       (easy-menu-define
2503         gnus-summary-article-menu gnus-summary-mode-map ""
2504         (cons "Article" innards))
2505
2506       (if (not (keymapp gnus-summary-article-menu))
2507           (easy-menu-define
2508             gnus-article-commands-menu gnus-article-mode-map ""
2509             (cons "Commands" innards))
2510         ;; in Emacs, don't share menu.
2511         (setq gnus-article-commands-menu
2512               (copy-keymap gnus-summary-article-menu))
2513         (define-key gnus-article-mode-map [menu-bar commands]
2514           (cons "Commands" gnus-article-commands-menu))))
2515
2516     (easy-menu-define
2517       gnus-summary-thread-menu gnus-summary-mode-map ""
2518       '("Threads"
2519         ["Find all messages in thread" gnus-summary-refer-thread t]
2520         ["Toggle threading" gnus-summary-toggle-threads t]
2521         ["Hide threads" gnus-summary-hide-all-threads t]
2522         ["Show threads" gnus-summary-show-all-threads t]
2523         ["Hide thread" gnus-summary-hide-thread t]
2524         ["Show thread" gnus-summary-show-thread t]
2525         ["Go to next thread" gnus-summary-next-thread t]
2526         ["Go to previous thread" gnus-summary-prev-thread t]
2527         ["Go down thread" gnus-summary-down-thread t]
2528         ["Go up thread" gnus-summary-up-thread t]
2529         ["Top of thread" gnus-summary-top-thread t]
2530         ["Mark thread as read" gnus-summary-kill-thread t]
2531         ["Mark thread as expired" gnus-summary-expire-thread t]
2532         ["Lower thread score" gnus-summary-lower-thread t]
2533         ["Raise thread score" gnus-summary-raise-thread t]
2534         ["Rethread current" gnus-summary-rethread-current t]))
2535
2536     (easy-menu-define
2537       gnus-summary-post-menu gnus-summary-mode-map ""
2538       `("Post"
2539         ["Send a message (mail or news)" gnus-summary-post-news
2540          ,@(if (featurep 'xemacs) '(t)
2541              '(:help "Compose a new message (mail or news)"))]
2542         ["Followup" gnus-summary-followup
2543          ,@(if (featurep 'xemacs) '(t)
2544              '(:help "Post followup to this article"))]
2545         ["Followup and yank" gnus-summary-followup-with-original
2546          ,@(if (featurep 'xemacs) '(t)
2547              '(:help "Post followup to this article, quoting its contents"))]
2548         ["Supersede article" gnus-summary-supersede-article t]
2549         ["Cancel article" gnus-summary-cancel-article
2550          ,@(if (featurep 'xemacs) '(t)
2551              '(:help "Cancel an article you posted"))]
2552         ["Reply" gnus-summary-reply t]
2553         ["Reply and yank" gnus-summary-reply-with-original t]
2554         ["Wide reply" gnus-summary-wide-reply t]
2555         ["Wide reply and yank" gnus-summary-wide-reply-with-original
2556          ,@(if (featurep 'xemacs) '(t)
2557              '(:help "Mail a reply, quoting this article"))]
2558         ["Very wide reply" gnus-summary-very-wide-reply t]
2559         ["Very wide reply and yank" gnus-summary-very-wide-reply-with-original
2560          ,@(if (featurep 'xemacs) '(t)
2561              '(:help "Mail a very wide reply, quoting this article"))]
2562         ["Mail forward" gnus-summary-mail-forward t]
2563         ["Post forward" gnus-summary-post-forward t]
2564         ["Digest and mail" gnus-uu-digest-mail-forward t]
2565         ["Digest and post" gnus-uu-digest-post-forward t]
2566         ["Resend message" gnus-summary-resend-message t]
2567         ["Resend message edit" gnus-summary-resend-message-edit t]
2568         ["Send bounced mail" gnus-summary-resend-bounced-mail t]
2569         ["Send a mail" gnus-summary-mail-other-window t]
2570         ["Create a local message" gnus-summary-news-other-window t]
2571         ["Uuencode and post" gnus-uu-post-news
2572          ,@(if (featurep 'xemacs) '(t)
2573              '(:help "Post a uuencoded article"))]
2574         ["Followup via news" gnus-summary-followup-to-mail t]
2575         ["Followup via news and yank"
2576          gnus-summary-followup-to-mail-with-original t]
2577         ["Strip signature on reply"
2578          (lambda ()
2579            (interactive)
2580            (if (not (memq message-cite-function
2581                           '(message-cite-original-without-signature
2582                             message-cite-original)))
2583                ;; Stupid workaround for XEmacs not honoring :visible.
2584                (message "Can't toggle this value of `message-cite-function'")
2585              (setq message-cite-function
2586                    (if (eq message-cite-function
2587                            'message-cite-original-without-signature)
2588                        'message-cite-original
2589                      'message-cite-original-without-signature))))
2590          ;; XEmacs barfs on :visible.
2591          ,@(if (featurep 'xemacs) nil
2592              '(:visible (memq message-cite-function
2593                               '(message-cite-original-without-signature
2594                                 message-cite-original))))
2595          :style toggle
2596          :selected (eq message-cite-function
2597                        'message-cite-original-without-signature)
2598          ,@(if (featurep 'xemacs) nil
2599              '(:help "Strip signature from cited article when replying."))]
2600         ;;("Draft"
2601         ;;["Send" gnus-summary-send-draft t]
2602         ;;["Send bounced" gnus-resend-bounced-mail t])
2603         ))
2604
2605     (cond
2606      ((not (keymapp gnus-summary-post-menu))
2607       (setq gnus-article-post-menu gnus-summary-post-menu))
2608      ((not gnus-article-post-menu)
2609       ;; Don't share post menu.
2610       (setq gnus-article-post-menu
2611             (copy-keymap gnus-summary-post-menu))))
2612     (define-key gnus-article-mode-map [menu-bar post]
2613       (cons "Post" gnus-article-post-menu))
2614
2615     (easy-menu-define
2616       gnus-summary-misc-menu gnus-summary-mode-map ""
2617       `("Gnus"
2618         ("Mark Read"
2619          ["Mark as read" gnus-summary-mark-as-read-forward t]
2620          ["Mark same subject and select"
2621           gnus-summary-kill-same-subject-and-select t]
2622          ["Mark same subject" gnus-summary-kill-same-subject t]
2623          ["Catchup" gnus-summary-catchup
2624           ,@(if (featurep 'xemacs) '(t)
2625               '(:help "Mark unread articles in this group as read"))]
2626          ["Catchup all" gnus-summary-catchup-all t]
2627          ["Catchup to here" gnus-summary-catchup-to-here t]
2628          ["Catchup from here" gnus-summary-catchup-from-here t]
2629          ["Catchup region" gnus-summary-mark-region-as-read
2630           (gnus-mark-active-p)]
2631          ["Mark excluded" gnus-summary-limit-mark-excluded-as-read t])
2632         ("Mark Various"
2633          ["Tick" gnus-summary-tick-article-forward t]
2634          ["Mark as dormant" gnus-summary-mark-as-dormant t]
2635          ["Remove marks" gnus-summary-clear-mark-forward t]
2636          ["Set expirable mark" gnus-summary-mark-as-expirable t]
2637          ["Set bookmark" gnus-summary-set-bookmark t]
2638          ["Remove bookmark" gnus-summary-remove-bookmark t])
2639         ("Limit to"
2640          ["Marks..." gnus-summary-limit-to-marks t]
2641          ["Subject..." gnus-summary-limit-to-subject t]
2642          ["Author..." gnus-summary-limit-to-author t]
2643          ["Recipient..." gnus-summary-limit-to-recipient t]
2644          ["Address..." gnus-summary-limit-to-address t]
2645          ["Age..." gnus-summary-limit-to-age t]
2646          ["Extra..." gnus-summary-limit-to-extra t]
2647          ["Score..." gnus-summary-limit-to-score t]
2648          ["Display Predicate" gnus-summary-limit-to-display-predicate t]
2649          ["Unread" gnus-summary-limit-to-unread t]
2650          ["Unseen" gnus-summary-limit-to-unseen t]
2651          ["Singletons" gnus-summary-limit-to-singletons t]
2652          ["Replied" gnus-summary-limit-to-replied t]
2653          ["Non-dormant" gnus-summary-limit-exclude-dormant t]
2654          ["Next or process marked articles" gnus-summary-limit-to-articles t]
2655          ["Pop limit" gnus-summary-pop-limit t]
2656          ["Show dormant" gnus-summary-limit-include-dormant t]
2657          ["Hide childless dormant"
2658           gnus-summary-limit-exclude-childless-dormant t]
2659          ;;["Hide thread" gnus-summary-limit-exclude-thread t]
2660          ["Hide marked" gnus-summary-limit-exclude-marks t]
2661          ["Show expunged" gnus-summary-limit-include-expunged t])
2662         ("Process Mark"
2663          ["Set mark" gnus-summary-mark-as-processable t]
2664          ["Remove mark" gnus-summary-unmark-as-processable t]
2665          ["Remove all marks" gnus-summary-unmark-all-processable t]
2666          ["Invert marks" gnus-uu-invert-processable t]
2667          ["Mark above" gnus-uu-mark-over t]
2668          ["Mark series" gnus-uu-mark-series t]
2669          ["Mark region" gnus-uu-mark-region (gnus-mark-active-p)]
2670          ["Unmark region" gnus-uu-unmark-region (gnus-mark-active-p)]
2671          ["Mark by regexp..." gnus-uu-mark-by-regexp t]
2672          ["Unmark by regexp..." gnus-uu-unmark-by-regexp t]
2673          ["Mark all" gnus-uu-mark-all t]
2674          ["Mark buffer" gnus-uu-mark-buffer t]
2675          ["Mark sparse" gnus-uu-mark-sparse t]
2676          ["Mark thread" gnus-uu-mark-thread t]
2677          ["Unmark thread" gnus-uu-unmark-thread t]
2678          ("Process Mark Sets"
2679           ["Kill" gnus-summary-kill-process-mark t]
2680           ["Yank" gnus-summary-yank-process-mark
2681            gnus-newsgroup-process-stack]
2682           ["Save" gnus-summary-save-process-mark t]
2683           ["Run command on marked..." gnus-summary-universal-argument t]))
2684         ("Registry Marks")
2685         ("Scroll article"
2686          ["Page forward" gnus-summary-next-page
2687           ,@(if (featurep 'xemacs) '(t)
2688               '(:help "Show next page of article"))]
2689          ["Page backward" gnus-summary-prev-page
2690           ,@(if (featurep 'xemacs) '(t)
2691               '(:help "Show previous page of article"))]
2692          ["Line forward" gnus-summary-scroll-up t])
2693         ("Move"
2694          ["Next unread article" gnus-summary-next-unread-article t]
2695          ["Previous unread article" gnus-summary-prev-unread-article t]
2696          ["Next article" gnus-summary-next-article t]
2697          ["Previous article" gnus-summary-prev-article t]
2698          ["Next unread subject" gnus-summary-next-unread-subject t]
2699          ["Previous unread subject" gnus-summary-prev-unread-subject t]
2700          ["Next article same subject" gnus-summary-next-same-subject t]
2701          ["Previous article same subject" gnus-summary-prev-same-subject t]
2702          ["First unread article" gnus-summary-first-unread-article t]
2703          ["Best unread article" gnus-summary-best-unread-article t]
2704          ["Go to subject number..." gnus-summary-goto-subject t]
2705          ["Go to article number..." gnus-summary-goto-article t]
2706          ["Go to the last article" gnus-summary-goto-last-article t]
2707          ["Pop article off history" gnus-summary-pop-article t])
2708         ("Sort"
2709          ["Sort by number" gnus-summary-sort-by-number t]
2710          ["Sort by most recent number" gnus-summary-sort-by-most-recent-number t]
2711          ["Sort by author" gnus-summary-sort-by-author t]
2712          ["Sort by recipient" gnus-summary-sort-by-recipient t]
2713          ["Sort by subject" gnus-summary-sort-by-subject t]
2714          ["Sort by date" gnus-summary-sort-by-date t]
2715          ["Sort by most recent date" gnus-summary-sort-by-most-recent-date t]
2716          ["Sort by score" gnus-summary-sort-by-score t]
2717          ["Sort by lines" gnus-summary-sort-by-lines t]
2718          ["Sort by characters" gnus-summary-sort-by-chars t]
2719          ["Randomize" gnus-summary-sort-by-random t]
2720          ["Original sort" gnus-summary-sort-by-original t])
2721         ("Help"
2722          ["Fetch group FAQ" gnus-summary-fetch-faq t]
2723          ["Describe group" gnus-summary-describe-group t]
2724          ["Fetch charter" gnus-group-fetch-charter
2725           ,@(if (featurep 'xemacs) nil
2726               '(:help "Display the charter of the current group"))]
2727          ["Fetch control message" gnus-group-fetch-control
2728           ,@(if (featurep 'xemacs) nil
2729               '(:help "Display the archived control message for the current group"))]
2730          ["Read manual" gnus-info-find-node t])
2731         ("Modes"
2732          ["Pick and read" gnus-pick-mode t]
2733          ["Binary" gnus-binary-mode t])
2734         ("Regeneration"
2735          ["Regenerate" gnus-summary-prepare t]
2736          ["Insert cached articles" gnus-summary-insert-cached-articles t]
2737          ["Insert dormant articles" gnus-summary-insert-dormant-articles t]
2738          ["Insert ticked articles" gnus-summary-insert-ticked-articles t]
2739          ["Toggle threading" gnus-summary-toggle-threads t])
2740         ["See old articles" gnus-summary-insert-old-articles t]
2741         ["See new articles" gnus-summary-insert-new-articles t]
2742         ["Filter articles..." gnus-summary-execute-command t]
2743         ["Run command on articles..." gnus-summary-universal-argument t]
2744         ["Search articles forward..." gnus-summary-search-article-forward t]
2745         ["Search articles backward..." gnus-summary-search-article-backward t]
2746         ["Toggle line truncation" gnus-summary-toggle-truncation t]
2747         ["Expand window" gnus-summary-expand-window t]
2748         ["Expire expirable articles" gnus-summary-expire-articles
2749          (gnus-check-backend-function
2750           'request-expire-articles gnus-newsgroup-name)]
2751         ["Edit local kill file" gnus-summary-edit-local-kill t]
2752         ["Edit main kill file" gnus-summary-edit-global-kill t]
2753         ["Edit group parameters" gnus-summary-edit-parameters t]
2754         ["Customize group parameters" gnus-summary-customize-parameters t]
2755         ["Send a bug report" gnus-bug t]
2756         ("Exit"
2757          ["Catchup and exit" gnus-summary-catchup-and-exit
2758           ,@(if (featurep 'xemacs) '(t)
2759               '(:help "Mark unread articles in this group as read, then exit"))]
2760          ["Catchup all and exit" gnus-summary-catchup-all-and-exit t]
2761          ["Catchup and goto next" gnus-summary-catchup-and-goto-next-group t]
2762          ["Catchup and goto prev" gnus-summary-catchup-and-goto-prev-group t]
2763          ["Exit group" gnus-summary-exit
2764           ,@(if (featurep 'xemacs) '(t)
2765               '(:help "Exit current group, return to group selection mode"))]
2766          ["Exit group without updating" gnus-summary-exit-no-update t]
2767          ["Exit and goto next group" gnus-summary-next-group t]
2768          ["Exit and goto prev group" gnus-summary-prev-group t]
2769          ["Reselect group" gnus-summary-reselect-current-group t]
2770          ["Rescan group" gnus-summary-rescan-group t]
2771          ["Update dribble" gnus-summary-save-newsrc t])))
2772
2773     (gnus-run-hooks 'gnus-summary-menu-hook)))
2774
2775 (defvar gnus-summary-tool-bar-map nil)
2776
2777 ;; Note: The :set function in the `gnus-summary-tool-bar*' variables will only
2778 ;; affect _new_ message buffers.  We might add a function that walks thru all
2779 ;; summary-mode buffers and force the update.
2780 (defun gnus-summary-tool-bar-update (&optional symbol value)
2781   "Update summary mode toolbar.
2782 Setter function for custom variables."
2783   (setq-default gnus-summary-tool-bar-map nil)
2784   (when symbol
2785     ;; When used as ":set" function:
2786     (set-default symbol value))
2787   (when (gnus-buffer-live-p gnus-summary-buffer)
2788     (with-current-buffer gnus-summary-buffer
2789       (gnus-summary-make-tool-bar))))
2790
2791 (defcustom gnus-summary-tool-bar (if (eq gmm-tool-bar-style 'gnome)
2792                                      'gnus-summary-tool-bar-gnome
2793                                    'gnus-summary-tool-bar-retro)
2794   "Specifies the Gnus summary tool bar.
2795
2796 It can be either a list or a symbol refering to a list.  See
2797 `gmm-tool-bar-from-list' for the format of the list.  The
2798 default key map is `gnus-summary-mode-map'.
2799
2800 Pre-defined symbols include `gnus-summary-tool-bar-gnome' and
2801 `gnus-summary-tool-bar-retro'."
2802   :type '(choice (const :tag "GNOME style" gnus-summary-tool-bar-gnome)
2803                  (const :tag "Retro look"  gnus-summary-tool-bar-retro)
2804                  (repeat :tag "User defined list" gmm-tool-bar-item)
2805                  (symbol))
2806   :version "23.1" ;; No Gnus
2807   :initialize 'custom-initialize-default
2808   :set 'gnus-summary-tool-bar-update
2809   :group 'gnus-summary)
2810
2811 (defcustom gnus-summary-tool-bar-gnome
2812   '((gnus-summary-post-news "mail/compose" nil)
2813     (gnus-summary-insert-new-articles "mail/inbox" nil
2814                                       :visible (or (not gnus-agent)
2815                                                    gnus-plugged))
2816     (gnus-summary-reply-with-original "mail/reply")
2817     (gnus-summary-reply "mail/reply" nil :visible nil)
2818     (gnus-summary-followup-with-original "mail/reply-all")
2819     (gnus-summary-followup "mail/reply-all" nil :visible nil)
2820     (gnus-summary-mail-forward "mail/forward")
2821     (gnus-summary-save-article "mail/save")
2822     (gnus-summary-search-article-forward "search" nil :visible nil)
2823     (gnus-summary-print-article "print")
2824     (gnus-summary-tick-article-forward "flag-followup" nil :visible nil)
2825     ;; Some new commands that may need more suitable icons:
2826     (gnus-summary-save-newsrc "save" nil :visible nil)
2827     ;; (gnus-summary-show-article "stock_message-display" nil :visible nil)
2828     (gnus-summary-prev-article "left-arrow")
2829     (gnus-summary-next-article "right-arrow")
2830     (gnus-summary-next-page "next-page")
2831     ;; (gnus-summary-enter-digest-group "right_arrow" nil :visible nil)
2832     ;;
2833     ;; Maybe some sort-by-... could be added:
2834     ;; (gnus-summary-sort-by-author "sort-a-z" nil :visible nil)
2835     ;; (gnus-summary-sort-by-date "sort-1-9" nil :visible nil)
2836     (gnus-summary-mark-as-expirable
2837      "delete" nil
2838      :visible (gnus-check-backend-function 'request-expire-articles
2839                                            gnus-newsgroup-name))
2840     (gnus-summary-mark-as-spam
2841      "mail/spam" t
2842      :visible (and (fboundp 'spam-group-ham-contents-p)
2843                    (spam-group-ham-contents-p gnus-newsgroup-name))
2844      :help "Mark as spam")
2845     (gnus-summary-mark-as-read-forward
2846      "mail/not-spam" nil
2847      :visible (and (fboundp 'spam-group-spam-contents-p)
2848                    (spam-group-spam-contents-p gnus-newsgroup-name)))
2849     ;;
2850     (gnus-summary-exit "exit")
2851     (gmm-customize-mode "preferences" t :help "Edit mode preferences")
2852     (gnus-info-find-node "help"))
2853   "List of functions for the summary tool bar (GNOME style).
2854
2855 See `gmm-tool-bar-from-list' for the format of the list."
2856   :type '(repeat gmm-tool-bar-item)
2857   :version "23.1" ;; No Gnus
2858   :initialize 'custom-initialize-default
2859   :set 'gnus-summary-tool-bar-update
2860   :group 'gnus-summary)
2861
2862 (defcustom gnus-summary-tool-bar-retro
2863   '((gnus-summary-prev-unread-article "gnus/prev-ur")
2864     (gnus-summary-next-unread-article "gnus/next-ur")
2865     (gnus-summary-post-news "gnus/post")
2866     (gnus-summary-followup-with-original "gnus/fuwo")
2867     (gnus-summary-followup "gnus/followup")
2868     (gnus-summary-reply-with-original "gnus/reply-wo")
2869     (gnus-summary-reply "gnus/reply")
2870     (gnus-summary-caesar-message "gnus/rot13")
2871     (gnus-uu-decode-uu "gnus/uu-decode")
2872     (gnus-summary-save-article-file "gnus/save-aif")
2873     (gnus-summary-save-article "gnus/save-art")
2874     (gnus-uu-post-news "gnus/uu-post")
2875     (gnus-summary-catchup "gnus/catchup")
2876     (gnus-summary-catchup-and-exit "gnus/cu-exit")
2877     (gnus-summary-exit "gnus/exit-summ")
2878     ;; Some new command that may need more suitable icons:
2879     (gnus-summary-print-article "gnus/print" nil :visible nil)
2880     (gnus-summary-mark-as-expirable "gnus/close" nil :visible nil)
2881     (gnus-summary-save-newsrc "gnus/save" nil :visible nil)
2882     ;; (gnus-summary-enter-digest-group "gnus/right_arrow" nil :visible nil)
2883     (gnus-summary-search-article-forward "gnus/search" nil :visible nil)
2884     ;; (gnus-summary-insert-new-articles "gnus/paste" nil :visible nil)
2885     ;; (gnus-summary-toggle-threads "gnus/open" nil :visible nil)
2886     ;;
2887     (gnus-info-find-node "gnus/help" nil :visible nil))
2888   "List of functions for the summary tool bar (retro look).
2889
2890 See `gmm-tool-bar-from-list' for the format of the list."
2891   :type '(repeat gmm-tool-bar-item)
2892   :version "23.1" ;; No Gnus
2893   :initialize 'custom-initialize-default
2894   :set 'gnus-summary-tool-bar-update
2895   :group 'gnus-summary)
2896
2897 (defcustom gnus-summary-tool-bar-zap-list t
2898   "List of icon items from the global tool bar.
2899 These items are not displayed in the Gnus summary mode tool bar.
2900
2901 See `gmm-tool-bar-from-list' for the format of the list."
2902   :type 'gmm-tool-bar-zap-list
2903   :version "23.1" ;; No Gnus
2904   :initialize 'custom-initialize-default
2905   :set 'gnus-summary-tool-bar-update
2906   :group 'gnus-summary)
2907
2908 (defvar image-load-path)
2909 (defvar tool-bar-map)
2910
2911 (defun gnus-summary-make-tool-bar (&optional force)
2912   "Make a summary mode tool bar from `gnus-summary-tool-bar'.
2913 When FORCE, rebuild the tool bar."
2914   (when (and (not (featurep 'xemacs))
2915              (boundp 'tool-bar-mode)
2916              tool-bar-mode
2917              (or (not gnus-summary-tool-bar-map) force))
2918     (let* ((load-path
2919             (gmm-image-load-path-for-library "gnus"
2920                                              "mail/save.xpm"
2921                                              nil t))
2922            (image-load-path (cons (car load-path)
2923                                   (when (boundp 'image-load-path)
2924                                     image-load-path)))
2925            (map (gmm-tool-bar-from-list gnus-summary-tool-bar
2926                                         gnus-summary-tool-bar-zap-list
2927                                         'gnus-summary-mode-map)))
2928       (when map
2929         ;; Need to set `gnus-summary-tool-bar-map' because `gnus-article-mode'
2930         ;; uses it's value.
2931         (setq gnus-summary-tool-bar-map map))))
2932   (set (make-local-variable 'tool-bar-map) gnus-summary-tool-bar-map))
2933
2934 (defun gnus-score-set-default (var value)
2935   "A version of set that updates the GNU Emacs menu-bar."
2936   (set var value)
2937   ;; It is the message that forces the active status to be updated.
2938   (message ""))
2939
2940 (defun gnus-make-score-map (type)
2941   "Make a summary score map of type TYPE."
2942   (if t
2943       nil
2944     (let ((headers '(("author" "from" string)
2945                      ("subject" "subject" string)
2946                      ("article body" "body" string)
2947                      ("article head" "head" string)
2948                      ("xref" "xref" string)
2949                      ("extra header" "extra" string)
2950                      ("lines" "lines" number)
2951                      ("followups to author" "followup" string)))
2952           (types '((number ("less than" <)
2953                            ("greater than" >)
2954                            ("equal" =))
2955                    (string ("substring" s)
2956                            ("exact string" e)
2957                            ("fuzzy string" f)
2958                            ("regexp" r))))
2959           (perms '(("temporary" (current-time-string))
2960                    ("permanent" nil)
2961                    ("immediate" now)))
2962           header)
2963       (list
2964        (apply
2965         'nconc
2966         (list
2967          (if (eq type 'lower)
2968              "Lower score"
2969            "Increase score"))
2970         (let (outh)
2971           (while headers
2972             (setq header (car headers))
2973             (setq outh
2974                   (cons
2975                    (apply
2976                     'nconc
2977                     (list (car header))
2978                     (let ((ts (cdr (assoc (nth 2 header) types)))
2979                           outt)
2980                       (while ts
2981                         (setq outt
2982                               (cons
2983                                (apply
2984                                 'nconc
2985                                 (list (caar ts))
2986                                 (let ((ps perms)
2987                                       outp)
2988                                   (while ps
2989                                     (setq outp
2990                                           (cons
2991                                            (vector
2992                                             (caar ps)
2993                                             (list
2994                                              'gnus-summary-score-entry
2995                                              (nth 1 header)
2996                                              (if (or (string= (nth 1 header)
2997                                                               "head")
2998                                                      (string= (nth 1 header)
2999                                                               "body"))
3000                                                  ""
3001                                                (list 'gnus-summary-header
3002                                                      (nth 1 header)))
3003                                              (list 'quote (nth 1 (car ts)))
3004                                              (list 'gnus-score-delta-default
3005                                                    nil)
3006                                              (nth 1 (car ps))
3007                                              t)
3008                                             t)
3009                                            outp))
3010                                     (setq ps (cdr ps)))
3011                                   (list (nreverse outp))))
3012                                outt))
3013                         (setq ts (cdr ts)))
3014                       (list (nreverse outt))))
3015                    outh))
3016             (setq headers (cdr headers)))
3017           (list (nreverse outh))))))))
3018
3019
3020 (declare-function turn-on-gnus-mailing-list-mode "gnus-ml" ())
3021 (defvar bookmark-make-record-function)
3022 \f
3023
3024 (defun gnus-summary-mode (&optional group)
3025   "Major mode for reading articles.
3026
3027 All normal editing commands are switched off.
3028 \\<gnus-summary-mode-map>
3029 Each line in this buffer represents one article.  To read an
3030 article, you can, for instance, type `\\[gnus-summary-next-page]'.  To move forwards
3031 and backwards while displaying articles, type `\\[gnus-summary-next-unread-article]' and `\\[gnus-summary-prev-unread-article]',
3032 respectively.
3033
3034 You can also post articles and send mail from this buffer.  To
3035 follow up an article, type `\\[gnus-summary-followup]'.  To mail a reply to the author
3036 of an article, type `\\[gnus-summary-reply]'.
3037
3038 There are approx. one gazillion commands you can execute in this
3039 buffer; read the info pages for more information (`\\[gnus-info-find-node]').
3040
3041 The following commands are available:
3042
3043 \\{gnus-summary-mode-map}"
3044   (interactive)
3045   (kill-all-local-variables)
3046   (let ((gnus-summary-local-variables gnus-newsgroup-variables))
3047     (gnus-summary-make-local-variables))
3048   (gnus-summary-make-local-variables)
3049   (setq gnus-newsgroup-name group)
3050   (when (gnus-visual-p 'summary-menu 'menu)
3051     (gnus-summary-make-menu-bar)
3052     (gnus-summary-make-tool-bar))
3053   (gnus-make-thread-indent-array)
3054   (gnus-simplify-mode-line)
3055   (setq major-mode 'gnus-summary-mode)
3056   (setq mode-name "Summary")
3057   (use-local-map gnus-summary-mode-map)
3058   (buffer-disable-undo)
3059   (setq buffer-read-only t              ;Disable modification
3060         show-trailing-whitespace nil)
3061   (setq truncate-lines t)
3062   (add-to-invisibility-spec '(gnus-sum . t))
3063   (gnus-summary-set-display-table)
3064   (gnus-set-default-directory)
3065   (make-local-variable 'gnus-summary-line-format)
3066   (make-local-variable 'gnus-summary-line-format-spec)
3067   (make-local-variable 'gnus-summary-dummy-line-format)
3068   (make-local-variable 'gnus-summary-dummy-line-format-spec)
3069   (make-local-variable 'gnus-summary-mark-positions)
3070   (gnus-make-local-hook 'pre-command-hook)
3071   (add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
3072   (gnus-run-mode-hooks 'gnus-summary-mode-hook)
3073   (turn-on-gnus-mailing-list-mode)
3074   (mm-enable-multibyte)
3075   (set (make-local-variable 'bookmark-make-record-function)
3076        'gnus-summary-bookmark-make-record)
3077   (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
3078   (gnus-update-summary-mark-positions))
3079
3080 (defun gnus-summary-make-local-variables ()
3081   "Make all the local summary buffer variables."
3082   (let (global)
3083     (dolist (local gnus-summary-local-variables)
3084       (if (consp local)
3085           (progn
3086             (if (eq (cdr local) 'global)
3087                 ;; Copy the global value of the variable.
3088                 (setq global (symbol-value (car local)))
3089               ;; Use the value from the list.
3090               (setq global (eval (cdr local))))
3091             (set (make-local-variable (car local)) global))
3092         ;; Simple nil-valued local variable.
3093         (set (make-local-variable local) nil)))))
3094
3095 (defun gnus-summary-clear-local-variables ()
3096   (let ((locals gnus-summary-local-variables))
3097     (while locals
3098       (if (consp (car locals))
3099           (and (symbolp (caar locals))
3100                (set (caar locals) nil))
3101         (and (symbolp (car locals))
3102              (set (car locals) nil)))
3103       (setq locals (cdr locals)))))
3104
3105 ;; Summary data functions.
3106
3107 (defmacro gnus-data-number (data)
3108   `(car ,data))
3109
3110 (defmacro gnus-data-set-number (data number)
3111   `(setcar ,data ,number))
3112
3113 (defmacro gnus-data-mark (data)
3114   `(nth 1 ,data))
3115
3116 (defmacro gnus-data-set-mark (data mark)
3117   `(setcar (nthcdr 1 ,data) ,mark))
3118
3119 (defmacro gnus-data-pos (data)
3120   `(nth 2 ,data))
3121
3122 (defmacro gnus-data-set-pos (data pos)
3123   `(setcar (nthcdr 2 ,data) ,pos))
3124
3125 (defmacro gnus-data-header (data)
3126   `(nth 3 ,data))
3127
3128 (defmacro gnus-data-set-header (data header)
3129   `(setf (nth 3 ,data) ,header))
3130
3131 (defmacro gnus-data-level (data)
3132   `(nth 4 ,data))
3133
3134 (defmacro gnus-data-unread-p (data)
3135   `(= (nth 1 ,data) gnus-unread-mark))
3136
3137 (defmacro gnus-data-read-p (data)
3138   `(/= (nth 1 ,data) gnus-unread-mark))
3139
3140 (defmacro gnus-data-pseudo-p (data)
3141   `(consp (nth 3 ,data)))
3142
3143 (defmacro gnus-data-find (number)
3144   `(assq ,number gnus-newsgroup-data))
3145
3146 (defmacro gnus-data-find-list (number &optional data)
3147   `(let ((bdata ,(or data 'gnus-newsgroup-data)))
3148      (memq (assq ,number bdata)
3149            bdata)))
3150
3151 (defmacro gnus-data-make (number mark pos header level)
3152   `(list ,number ,mark ,pos ,header ,level))
3153
3154 (defun gnus-data-enter (after-article number mark pos header level offset)
3155   (let ((data (gnus-data-find-list after-article)))
3156     (unless data
3157       (error "No such article: %d" after-article))
3158     (setcdr data (cons (gnus-data-make number mark pos header level)
3159                        (cdr data)))
3160     (setq gnus-newsgroup-data-reverse nil)
3161     (gnus-data-update-list (cddr data) offset)))
3162
3163 (defun gnus-data-enter-list (after-article list &optional offset)
3164   (when list
3165     (let ((data (and after-article (gnus-data-find-list after-article)))
3166           (ilist list))
3167       (if (not (or data
3168                    after-article))
3169           (let ((odata gnus-newsgroup-data))
3170             (setq gnus-newsgroup-data (nconc list gnus-newsgroup-data))
3171             (when offset
3172               (gnus-data-update-list odata offset)))
3173         ;; Find the last element in the list to be spliced into the main
3174         ;; list.
3175         (setq list (last list))
3176         (if (not data)
3177             (progn
3178               (setcdr list gnus-newsgroup-data)
3179               (setq gnus-newsgroup-data ilist)
3180               (when offset
3181                 (gnus-data-update-list (cdr list) offset)))
3182           (setcdr list (cdr data))
3183           (setcdr data ilist)
3184           (when offset
3185             (gnus-data-update-list (cdr list) offset))))
3186       (setq gnus-newsgroup-data-reverse nil))))
3187
3188 (defun gnus-data-remove (article &optional offset)
3189   (let ((data gnus-newsgroup-data))
3190     (if (= (gnus-data-number (car data)) article)
3191         (progn
3192           (setq gnus-newsgroup-data (cdr gnus-newsgroup-data)
3193                 gnus-newsgroup-data-reverse nil)
3194           (when offset
3195             (gnus-data-update-list gnus-newsgroup-data offset)))
3196       (while (cdr data)
3197         (when (= (gnus-data-number (cadr data)) article)
3198           (setcdr data (cddr data))
3199           (when offset
3200             (gnus-data-update-list (cdr data) offset))
3201           (setq data nil
3202                 gnus-newsgroup-data-reverse nil))
3203         (setq data (cdr data))))))
3204
3205 (defmacro gnus-data-list (backward)
3206   `(if ,backward
3207        (or gnus-newsgroup-data-reverse
3208            (setq gnus-newsgroup-data-reverse
3209                  (reverse gnus-newsgroup-data)))
3210      gnus-newsgroup-data))
3211
3212 (defun gnus-data-update-list (data offset)
3213   "Add OFFSET to the POS of all data entries in DATA."
3214   (setq gnus-newsgroup-data-reverse nil)
3215   (while data
3216     (setcar (nthcdr 2 (car data)) (+ offset (nth 2 (car data))))
3217     (setq data (cdr data))))
3218
3219 (defun gnus-summary-article-pseudo-p (article)
3220   "Say whether this article is a pseudo article or not."
3221   (not (vectorp (gnus-data-header (gnus-data-find article)))))
3222
3223 (defmacro gnus-summary-article-sparse-p (article)
3224   "Say whether this article is a sparse article or not."
3225   `(memq ,article gnus-newsgroup-sparse))
3226
3227 (defmacro gnus-summary-article-ancient-p (article)
3228   "Say whether this article is a sparse article or not."
3229   `(memq ,article gnus-newsgroup-ancient))
3230
3231 (defun gnus-article-parent-p (number)
3232   "Say whether this article is a parent or not."
3233   (let ((data (gnus-data-find-list number)))
3234     (and (cdr data)              ; There has to be an article after...
3235          (< (gnus-data-level (car data)) ; And it has to have a higher level.
3236             (gnus-data-level (nth 1 data))))))
3237
3238 (defun gnus-article-children (number)
3239   "Return a list of all children to NUMBER."
3240   (let* ((data (gnus-data-find-list number))
3241          (level (gnus-data-level (car data)))
3242          children)
3243     (setq data (cdr data))
3244     (while (and data
3245                 (= (gnus-data-level (car data)) (1+ level)))
3246       (push (gnus-data-number (car data)) children)
3247       (setq data (cdr data)))
3248     children))
3249
3250 (defmacro gnus-summary-skip-intangible ()
3251   "If the current article is intangible, then jump to a different article."
3252   '(let ((to (get-text-property (point) 'gnus-intangible)))
3253      (and to (gnus-summary-goto-subject to))))
3254
3255 (defmacro gnus-summary-article-intangible-p ()
3256   "Say whether this article is intangible or not."
3257   '(get-text-property (point) 'gnus-intangible))
3258
3259 (defun gnus-article-read-p (article)
3260   "Say whether ARTICLE is read or not."
3261   (not (or (memq article gnus-newsgroup-marked)
3262            (memq article gnus-newsgroup-spam-marked)
3263            (memq article gnus-newsgroup-unreads)
3264            (memq article gnus-newsgroup-unselected)
3265            (memq article gnus-newsgroup-dormant))))
3266
3267 ;; Some summary mode macros.
3268
3269 (defmacro gnus-summary-article-number ()
3270   "The article number of the article on the current line.
3271 If there isn't an article number here, then we return the current
3272 article number."
3273   '(progn
3274      (gnus-summary-skip-intangible)
3275      (or (get-text-property (point) 'gnus-number)
3276          (gnus-summary-last-subject))))
3277
3278 (defmacro gnus-summary-article-header (&optional number)
3279   "Return the header of article NUMBER."
3280   `(gnus-data-header (gnus-data-find
3281                       ,(or number '(gnus-summary-article-number)))))
3282
3283 (defmacro gnus-summary-thread-level (&optional number)
3284   "Return the level of thread that starts with article NUMBER."
3285   `(if (and (eq gnus-summary-make-false-root 'dummy)
3286             (get-text-property (point) 'gnus-intangible))
3287        0
3288      (gnus-data-level (gnus-data-find
3289                        ,(or number '(gnus-summary-article-number))))))
3290
3291 (defmacro gnus-summary-article-mark (&optional number)
3292   "Return the mark of article NUMBER."
3293   `(gnus-data-mark (gnus-data-find
3294                     ,(or number '(gnus-summary-article-number)))))
3295
3296 (defmacro gnus-summary-article-pos (&optional number)
3297   "Return the position of the line of article NUMBER."
3298   `(gnus-data-pos (gnus-data-find
3299                    ,(or number '(gnus-summary-article-number)))))
3300
3301 (defalias 'gnus-summary-subject-string 'gnus-summary-article-subject)
3302 (defmacro gnus-summary-article-subject (&optional number)
3303   "Return current subject string or nil if nothing."
3304   `(let ((headers
3305           ,(if number
3306                `(gnus-data-header (assq ,number gnus-newsgroup-data))
3307              '(gnus-data-header (assq (gnus-summary-article-number)
3308                                       gnus-newsgroup-data)))))
3309      (and headers
3310           (vectorp headers)
3311           (mail-header-subject headers))))
3312
3313 (defmacro gnus-summary-article-score (&optional number)
3314   "Return current article score."
3315   `(or (cdr (assq ,(or number '(gnus-summary-article-number))
3316                   gnus-newsgroup-scored))
3317        gnus-summary-default-score 0))
3318
3319 (defun gnus-summary-article-children (&optional number)
3320   "Return a list of article numbers that are children of article NUMBER."
3321   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))))
3322          (level (gnus-data-level (car data)))
3323          l children)
3324     (while (and (setq data (cdr data))
3325                 (> (setq l (gnus-data-level (car data))) level))
3326       (and (= (1+ level) l)
3327            (push (gnus-data-number (car data))
3328                  children)))
3329     (nreverse children)))
3330
3331 (defun gnus-summary-article-parent (&optional number)
3332   "Return the article number of the parent of article NUMBER."
3333   (let* ((data (gnus-data-find-list (or number (gnus-summary-article-number))
3334                                     (gnus-data-list t)))
3335          (level (gnus-data-level (car data))))
3336     (if (zerop level)
3337         ()                              ; This is a root.
3338       ;; We search until we find an article with a level less than
3339       ;; this one.  That function has to be the parent.
3340       (while (and (setq data (cdr data))
3341                   (not (< (gnus-data-level (car data)) level))))
3342       (and data (gnus-data-number (car data))))))
3343
3344 (defun gnus-unread-mark-p (mark)
3345   "Say whether MARK is the unread mark."
3346   (= mark gnus-unread-mark))
3347
3348 (defun gnus-read-mark-p (mark)
3349   "Say whether MARK is one of the marks that mark as read.
3350 This is all marks except unread, ticked, dormant, and expirable."
3351   (not (or (= mark gnus-unread-mark)
3352            (= mark gnus-ticked-mark)
3353            (= mark gnus-spam-mark)
3354            (= mark gnus-dormant-mark)
3355            (= mark gnus-expirable-mark))))
3356
3357 (defmacro gnus-article-mark (number)
3358   "Return the MARK of article NUMBER.
3359 This macro should only be used when computing the mark the \"first\"
3360 time; i.e., when generating the summary lines.  After that,
3361 `gnus-summary-article-mark' should be used to examine the
3362 marks of articles."
3363   `(cond
3364     ((memq ,number gnus-newsgroup-unsendable) gnus-unsendable-mark)
3365     ((memq ,number gnus-newsgroup-downloadable) gnus-downloadable-mark)
3366     ((memq ,number gnus-newsgroup-unreads) gnus-unread-mark)
3367     ((memq ,number gnus-newsgroup-marked) gnus-ticked-mark)
3368     ((memq ,number gnus-newsgroup-spam-marked) gnus-spam-mark)
3369     ((memq ,number gnus-newsgroup-dormant) gnus-dormant-mark)
3370     ((memq ,number gnus-newsgroup-expirable) gnus-expirable-mark)
3371     (t (or (cdr (assq ,number gnus-newsgroup-reads))
3372            gnus-ancient-mark))))
3373
3374 ;; Saving hidden threads.
3375
3376 (defmacro gnus-save-hidden-threads (&rest forms)
3377   "Save hidden threads, eval FORMS, and restore the hidden threads."
3378   (let ((config (make-symbol "config")))
3379     `(let ((,config (gnus-hidden-threads-configuration)))
3380        (unwind-protect
3381            (save-excursion
3382              ,@forms)
3383          (gnus-restore-hidden-threads-configuration ,config)))))
3384 (put 'gnus-save-hidden-threads 'lisp-indent-function 0)
3385 (put 'gnus-save-hidden-threads 'edebug-form-spec '(body))
3386
3387 (defun gnus-data-compute-positions ()
3388   "Compute the positions of all articles."
3389   (setq gnus-newsgroup-data-reverse nil)
3390   (let ((data gnus-newsgroup-data))
3391     (save-excursion
3392       (gnus-save-hidden-threads
3393         (gnus-summary-show-all-threads)
3394         (goto-char (point-min))
3395         (while data
3396           (while (get-text-property (point) 'gnus-intangible)
3397             (forward-line 1))
3398           (gnus-data-set-pos (car data) (+ (point) 3))
3399           (setq data (cdr data))
3400           (forward-line 1))))))
3401
3402 (defun gnus-hidden-threads-configuration ()
3403   "Return the current hidden threads configuration."
3404   (save-excursion
3405     (let (config)
3406       (goto-char (point-min))
3407       (while (not (eobp))
3408         (when (eq (get-char-property (point-at-eol) 'invisible) 'gnus-sum)
3409           (push (save-excursion (forward-line 0) (point)) config))
3410         (forward-line 1))
3411       config)))
3412
3413 (defun gnus-restore-hidden-threads-configuration (config)
3414   "Restore hidden threads configuration from CONFIG."
3415   (save-excursion
3416     (let (point (inhibit-read-only t))
3417       (while (setq point (pop config))
3418         (goto-char point)
3419         (gnus-summary-hide-thread)))))
3420
3421 ;; Various summary mode internalish functions.
3422
3423 (defun gnus-mouse-pick-article (e)
3424   (interactive "e")
3425   (mouse-set-point e)
3426   (gnus-summary-next-page nil t))
3427
3428 (defun gnus-summary-set-display-table ()
3429   "Change the display table.
3430 Odd characters have a tendency to mess
3431 up nicely formatted displays - we make all possible glyphs
3432 display only a single character."
3433
3434   ;; We start from the standard display table, if any.
3435   (let ((table (or (copy-sequence standard-display-table)
3436                    (make-display-table)))
3437         (i 32))
3438     ;; Nix out all the control chars...
3439     (while (>= (setq i (1- i)) 0)
3440       (gnus-put-display-table i [??] table))
3441    ;; ... but not newline and cr, of course.  (cr is necessary for the
3442     ;; selective display).
3443     (gnus-put-display-table ?\n nil table)
3444     (gnus-put-display-table ?\r nil table)
3445     ;; We keep TAB as well.
3446     (gnus-put-display-table ?\t nil table)
3447     ;; We nix out any glyphs 127 through 255, or 127 through 159 in
3448     ;; Emacs 23 (unicode), that are not set already.
3449     (let ((i (if (ignore-errors (= (make-char 'latin-iso8859-1 160) 160))
3450                  160
3451                256)))
3452       (while (>= (setq i (1- i)) 127)
3453         ;; Only modify if the entry is nil.
3454         (unless (gnus-get-display-table i table)
3455           (gnus-put-display-table i [??] table))))
3456     (setq buffer-display-table table)))
3457
3458 (defun gnus-summary-set-article-display-arrow (pos)
3459   "Update the overlay arrow to point to line at position POS."
3460   (when gnus-summary-display-arrow
3461     (make-local-variable 'overlay-arrow-position)
3462     (make-local-variable 'overlay-arrow-string)
3463     (save-excursion
3464       (goto-char pos)
3465       (beginning-of-line)
3466       (unless overlay-arrow-position
3467         (setq overlay-arrow-position (make-marker)))
3468       (setq overlay-arrow-string "=>"
3469             overlay-arrow-position (set-marker overlay-arrow-position
3470                                                (point)
3471                                                (current-buffer))))))
3472
3473 (defun gnus-summary-setup-buffer (group)
3474   "Initialize summary buffer."
3475   (let ((buffer (gnus-summary-buffer-name group))
3476         (dead-name (concat "*Dead Summary "
3477                            (gnus-group-decoded-name group) "*")))
3478     ;; If a dead summary buffer exists, we kill it.
3479     (when (gnus-buffer-live-p dead-name)
3480       (gnus-kill-buffer dead-name))
3481     (if (get-buffer buffer)
3482         (progn
3483           (set-buffer buffer)
3484           (setq gnus-summary-buffer (current-buffer))
3485           (not gnus-newsgroup-prepared))
3486       ;; Fix by Sudish Joseph <joseph@cis.ohio-state.edu>
3487       (setq gnus-summary-buffer (set-buffer (gnus-get-buffer-create buffer)))
3488       (gnus-summary-mode group)
3489       (when gnus-carpal
3490         (gnus-carpal-setup-buffer 'summary))
3491       (when (gnus-group-quit-config group)
3492         (set (make-local-variable 'gnus-single-article-buffer) nil))
3493       (make-local-variable 'gnus-article-buffer)
3494       (make-local-variable 'gnus-article-current)
3495       (make-local-variable 'gnus-original-article-buffer)
3496       (setq gnus-newsgroup-name group)
3497       ;; Set any local variables in the group parameters.
3498       (gnus-summary-set-local-parameters gnus-newsgroup-name)
3499       t)))
3500
3501 (defun gnus-set-global-variables ()
3502   "Set the global equivalents of the buffer-local variables.
3503 They are set to the latest values they had.  These reflect the summary
3504 buffer that was in action when the last article was fetched."
3505   (when (eq major-mode 'gnus-summary-mode)
3506     (setq gnus-summary-buffer (current-buffer))
3507     (let ((name gnus-newsgroup-name)
3508           (marked gnus-newsgroup-marked)
3509           (spam gnus-newsgroup-spam-marked)
3510           (unread gnus-newsgroup-unreads)
3511           (headers gnus-current-headers)
3512           (data gnus-newsgroup-data)
3513           (summary gnus-summary-buffer)
3514           (article-buffer gnus-article-buffer)
3515           (original gnus-original-article-buffer)
3516           (gac gnus-article-current)
3517           (reffed gnus-reffed-article-number)
3518           (score-file gnus-current-score-file)
3519           (default-charset gnus-newsgroup-charset)
3520           vlist)
3521       (let ((locals gnus-newsgroup-variables))
3522         (while locals
3523           (if (consp (car locals))
3524               (push (eval (caar locals)) vlist)
3525             (push (eval (car locals)) vlist))
3526           (setq locals (cdr locals)))
3527         (setq vlist (nreverse vlist)))
3528       (with-current-buffer gnus-group-buffer
3529         (setq gnus-newsgroup-name name
3530               gnus-newsgroup-marked marked
3531               gnus-newsgroup-spam-marked spam
3532               gnus-newsgroup-unreads unread
3533               gnus-current-headers headers
3534               gnus-newsgroup-data data
3535               gnus-article-current gac
3536               gnus-summary-buffer summary
3537               gnus-article-buffer article-buffer
3538               gnus-original-article-buffer original
3539               gnus-reffed-article-number reffed
3540               gnus-current-score-file score-file
3541               gnus-newsgroup-charset default-charset)
3542         (let ((locals gnus-newsgroup-variables))
3543           (while locals
3544             (if (consp (car locals))
3545                 (set (caar locals) (pop vlist))
3546               (set (car locals) (pop vlist)))
3547             (setq locals (cdr locals))))
3548         ;; The article buffer also has local variables.
3549         (when (gnus-buffer-live-p gnus-article-buffer)
3550           (set-buffer gnus-article-buffer)
3551           (setq gnus-summary-buffer summary))))))
3552
3553 (defun gnus-summary-article-unread-p (article)
3554   "Say whether ARTICLE is unread or not."
3555   (memq article gnus-newsgroup-unreads))
3556
3557 (defun gnus-summary-first-article-p (&optional article)
3558   "Return whether ARTICLE is the first article in the buffer."
3559   (if (not (setq article (or article (gnus-summary-article-number))))
3560       nil
3561     (eq article (caar gnus-newsgroup-data))))
3562
3563 (defun gnus-summary-last-article-p (&optional article)
3564   "Return whether ARTICLE is the last article in the buffer."
3565   (if (not (setq article (or article (gnus-summary-article-number))))
3566       ;; All non-existent numbers are the last article.  :-)
3567       t
3568     (not (cdr (gnus-data-find-list article)))))
3569
3570 (defun gnus-make-thread-indent-array (&optional n)
3571   (when (or n
3572             (progn (setq n 200) nil)
3573             (null gnus-thread-indent-array)
3574             (/= gnus-thread-indent-level gnus-thread-indent-array-level))
3575     (setq gnus-thread-indent-array (make-vector (1+ n) "")
3576           gnus-thread-indent-array-level gnus-thread-indent-level)
3577     (while (>= n 0)
3578       (aset gnus-thread-indent-array n
3579             (make-string (* n gnus-thread-indent-level) ? ))
3580       (setq n (1- n)))))
3581
3582 (defun gnus-update-summary-mark-positions ()
3583   "Compute where the summary marks are to go."
3584   (save-excursion
3585     (when (gnus-buffer-exists-p gnus-summary-buffer)
3586       (set-buffer gnus-summary-buffer))
3587     (let ((spec gnus-summary-line-format-spec)
3588           pos)
3589       (save-excursion
3590         (gnus-set-work-buffer)
3591         (let ((gnus-tmp-unread ?Z)
3592               (gnus-replied-mark ?Z)
3593               (gnus-score-below-mark ?Z)
3594               (gnus-score-over-mark ?Z)
3595               (gnus-undownloaded-mark ?Z)
3596               (gnus-summary-line-format-spec spec)
3597               (gnus-newsgroup-downloadable '(0))
3598               (header [0 "" "" "05 Apr 2001 23:33:09 +0400" "" "" 0 0 "" nil])
3599               case-fold-search ignores)
3600           ;; Here, all marks are bound to Z.
3601           (gnus-summary-insert-line header
3602                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3603           (goto-char (point-min))
3604           ;; Memorize the positions of the same characters as dummy marks.
3605           (while (re-search-forward "[A-D]" nil t)
3606             (push (point) ignores))
3607           (erase-buffer)
3608           ;; We use A-D as dummy marks in order to know column positions
3609           ;; where marks should be inserted.
3610           (setq gnus-tmp-unread ?A
3611                 gnus-replied-mark ?B
3612                 gnus-score-below-mark ?C
3613                 gnus-score-over-mark ?C
3614                 gnus-undownloaded-mark ?D)
3615           (gnus-summary-insert-line header
3616                                     0 nil t gnus-tmp-unread t nil "" nil 1)
3617           ;; Ignore characters which aren't dummy marks.
3618           (dolist (p ignores)
3619             (delete-region (goto-char (1- p)) p)
3620             (insert ?Z))
3621           (goto-char (point-min))
3622           (setq pos (list (cons 'unread
3623                                 (and (search-forward "A" nil t)
3624                                      (- (point) (point-min) 1)))))
3625           (goto-char (point-min))
3626           (push (cons 'replied (and (search-forward "B" nil t)
3627                                     (- (point) (point-min) 1)))
3628                 pos)
3629           (goto-char (point-min))
3630           (push (cons 'score (and (search-forward "C" nil t)
3631                                   (- (point) (point-min) 1)))
3632                 pos)
3633           (goto-char (point-min))
3634           (push (cons 'download (and (search-forward "D" nil t)
3635                                      (- (point) (point-min) 1)))
3636                 pos)))
3637       (setq gnus-summary-mark-positions pos))))
3638
3639 (defun gnus-summary-insert-dummy-line (gnus-tmp-subject gnus-tmp-number)
3640   "Insert a dummy root in the summary buffer."
3641   (beginning-of-line)
3642   (gnus-add-text-properties
3643    (point) (progn (eval gnus-summary-dummy-line-format-spec) (point))
3644    (list 'gnus-number gnus-tmp-number 'gnus-intangible gnus-tmp-number)))
3645
3646 (defun gnus-summary-extract-address-component (from)
3647   (or (car (funcall gnus-extract-address-components from))
3648       from))
3649
3650 (defun gnus-summary-from-or-to-or-newsgroups (header gnus-tmp-from)
3651   (let ((mail-parse-charset gnus-newsgroup-charset)
3652         (ignored-from-addresses (gnus-ignored-from-addresses))
3653         ; Is it really necessary to do this next part for each summary line?
3654         ; Luckily, doesn't seem to slow things down much.
3655         (mail-parse-ignored-charsets
3656          (with-current-buffer gnus-summary-buffer
3657            gnus-newsgroup-ignored-charsets)))
3658     (or
3659      (and ignored-from-addresses
3660           (string-match ignored-from-addresses gnus-tmp-from)
3661           (let ((extra-headers (mail-header-extra header))
3662                 to
3663                 newsgroups)
3664             (cond
3665              ((setq to (cdr (assq 'To extra-headers)))
3666               (concat gnus-summary-to-prefix
3667                       (inline
3668                         (gnus-summary-extract-address-component
3669                          (funcall gnus-decode-encoded-address-function to)))))
3670              ((setq newsgroups
3671                     (or
3672                      (cdr (assq 'Newsgroups extra-headers))
3673                      (and
3674                       (memq 'Newsgroups gnus-extra-headers)
3675                       (eq (car (gnus-find-method-for-group
3676                                 gnus-newsgroup-name)) 'nntp)
3677                       (gnus-group-real-name gnus-newsgroup-name))))
3678               (concat gnus-summary-newsgroup-prefix newsgroups)))))
3679      (inline (gnus-summary-extract-address-component gnus-tmp-from)))))
3680
3681 (defun gnus-summary-insert-line (gnus-tmp-header
3682                                  gnus-tmp-level gnus-tmp-current
3683                                  undownloaded gnus-tmp-unread gnus-tmp-replied
3684                                  gnus-tmp-expirable gnus-tmp-subject-or-nil
3685                                  &optional gnus-tmp-dummy gnus-tmp-score
3686                                  gnus-tmp-process)
3687   (if (>= gnus-tmp-level (length gnus-thread-indent-array))
3688       (gnus-make-thread-indent-array (max (* 2 (length gnus-thread-indent-array))
3689                                           gnus-tmp-level)))
3690   (let* ((gnus-tmp-indentation (aref gnus-thread-indent-array gnus-tmp-level))
3691          (gnus-tmp-lines (mail-header-lines gnus-tmp-header))
3692          (gnus-tmp-score (or gnus-tmp-score gnus-summary-default-score 0))
3693          (gnus-tmp-score-char
3694           (if (or (null gnus-summary-default-score)
3695                   (<= (abs (- gnus-tmp-score gnus-summary-default-score))
3696                       gnus-summary-zcore-fuzz))
3697               ?                         ;Whitespace
3698             (if (< gnus-tmp-score gnus-summary-default-score)
3699                 gnus-score-below-mark gnus-score-over-mark)))
3700          (gnus-tmp-number (mail-header-number gnus-tmp-header))
3701          (gnus-tmp-replied
3702           (cond (gnus-tmp-process gnus-process-mark)
3703                 ((memq gnus-tmp-current gnus-newsgroup-cached)
3704                  gnus-cached-mark)
3705                 (gnus-tmp-replied gnus-replied-mark)
3706                 ((memq gnus-tmp-current gnus-newsgroup-forwarded)
3707                  gnus-forwarded-mark)
3708                 ((memq gnus-tmp-current gnus-newsgroup-saved)
3709                  gnus-saved-mark)
3710                 ((memq gnus-tmp-number gnus-newsgroup-recent)
3711                  gnus-recent-mark)
3712                 ((memq gnus-tmp-number gnus-newsgroup-unseen)
3713                  gnus-unseen-mark)
3714                 (t gnus-no-mark)))
3715          (gnus-tmp-downloaded
3716           (cond (undownloaded
3717                  gnus-undownloaded-mark)
3718                 (gnus-newsgroup-agentized
3719                  gnus-downloaded-mark)
3720                 (t
3721                  gnus-no-mark)))
3722          (gnus-tmp-from (mail-header-from gnus-tmp-header))
3723          (gnus-tmp-name
3724           (cond
3725            ((string-match "<[^>]+> *$" gnus-tmp-from)
3726             (let ((beg (match-beginning 0)))
3727               (or (and (string-match "^\".+\"" gnus-tmp-from)
3728                        (substring gnus-tmp-from 1 (1- (match-end 0))))
3729                   (substring gnus-tmp-from 0 beg))))
3730            ((string-match "(.+)" gnus-tmp-from)
3731             (substring gnus-tmp-from
3732                        (1+ (match-beginning 0)) (1- (match-end 0))))
3733            (t gnus-tmp-from)))
3734          (gnus-tmp-subject (mail-header-subject gnus-tmp-header))
3735          (gnus-tmp-opening-bracket (if gnus-tmp-dummy ?\< ?\[))
3736          (gnus-tmp-closing-bracket (if gnus-tmp-dummy ?\> ?\]))
3737          (inhibit-read-only t))
3738     (when (string= gnus-tmp-name "")
3739       (setq gnus-tmp-name gnus-tmp-from))
3740     (unless (numberp gnus-tmp-lines)
3741       (setq gnus-tmp-lines -1))
3742     (if (= gnus-tmp-lines -1)
3743         (setq gnus-tmp-lines "?")
3744       (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
3745     (condition-case ()
3746         (gnus-put-text-property
3747          (point)
3748          (progn (eval gnus-summary-line-format-spec) (point))
3749          'gnus-number gnus-tmp-number)
3750       (error (gnus-message 5 "Error updating the summary line")))
3751     (when (gnus-visual-p 'summary-highlight 'highlight)
3752       (forward-line -1)
3753       (gnus-run-hooks 'gnus-summary-update-hook)
3754       (forward-line 1))))
3755
3756 (defun gnus-summary-update-line (&optional dont-update)
3757   "Update summary line after change."
3758   (when (and gnus-summary-default-score
3759              (not gnus-summary-inhibit-highlight))
3760     (let* ((gnus-summary-inhibit-highlight t) ; Prevent recursion.
3761            (article (gnus-summary-article-number))
3762            (score (gnus-summary-article-score article)))
3763       (unless dont-update
3764         (if (and gnus-summary-mark-below
3765                  (< (gnus-summary-article-score)
3766                     gnus-summary-mark-below))
3767             ;; This article has a low score, so we mark it as read.
3768             (when (memq article gnus-newsgroup-unreads)
3769               (gnus-summary-mark-article-as-read gnus-low-score-mark))
3770           (when (eq (gnus-summary-article-mark) gnus-low-score-mark)
3771             ;; This article was previously marked as read on account
3772             ;; of a low score, but now it has risen, so we mark it as
3773             ;; unread.
3774             (gnus-summary-mark-article-as-unread gnus-unread-mark)))
3775         (gnus-summary-update-mark
3776          (if (or (null gnus-summary-default-score)
3777                  (<= (abs (- score gnus-summary-default-score))
3778                      gnus-summary-zcore-fuzz))
3779              ?                          ;Whitespace
3780            (if (< score gnus-summary-default-score)
3781                gnus-score-below-mark gnus-score-over-mark))
3782          'score))
3783       ;; Do visual highlighting.
3784       (when (gnus-visual-p 'summary-highlight 'highlight)
3785         (gnus-run-hooks 'gnus-summary-update-hook)))))
3786
3787 (defvar gnus-tmp-new-adopts nil)
3788
3789 (defun gnus-summary-number-of-articles-in-thread (thread &optional level char)
3790   "Return the number of articles in THREAD.
3791 This may be 0 in some cases -- if none of the articles in
3792 the thread are to be displayed."
3793   (let* ((number
3794          ;; Fix by Luc Van Eycken <Luc.VanEycken@esat.kuleuven.ac.be>.
3795           (cond
3796            ((not (listp thread))
3797             1)
3798            ((and (consp thread) (cdr thread))
3799             (apply
3800              '+ 1 (mapcar
3801                    'gnus-summary-number-of-articles-in-thread (cdr thread))))
3802            ((null thread)
3803             1)
3804            ((memq (mail-header-number (car thread)) gnus-newsgroup-limit)
3805             1)
3806            (t 0))))
3807     (when (and level (zerop level) gnus-tmp-new-adopts)
3808       (incf number
3809             (apply '+ (mapcar
3810                        'gnus-summary-number-of-articles-in-thread
3811                        gnus-tmp-new-adopts))))
3812     (if char
3813         (if (> number 1) gnus-not-empty-thread-mark
3814           gnus-empty-thread-mark)
3815       number)))
3816
3817 (defsubst gnus-summary-line-message-size (head)
3818   "Return pretty-printed version of message size.
3819 This function is intended to be used in
3820 `gnus-summary-line-format-alist'."
3821   (let ((c (or (mail-header-chars head) -1)))
3822     (cond ((< c 0) "n/a")               ; chars not available
3823           ((< c (* 1000 10)) (format "%1.1fk" (/ c 1024.0)))
3824           ((< c (* 1000 100)) (format "%dk" (/ c 1024.0)))
3825           ((< c (* 1000 10000)) (format "%1.1fM" (/ c (* 1024.0 1024))))
3826           (t (format "%dM" (/ c (* 1024.0 1024)))))))
3827
3828
3829 (defun gnus-summary-set-local-parameters (group)
3830   "Go through the local params of GROUP and set all variable specs in that list."
3831   (let ((vars '(quit-config)))          ; Ignore quit-config.
3832     (dolist (elem (gnus-group-find-parameter group))
3833       (and (consp elem)                 ; Has to be a cons.
3834            (consp (cdr elem))           ; The cdr has to be a list.
3835            (symbolp (car elem))         ; Has to be a symbol in there.
3836            (not (memq (car elem) vars))
3837            (ignore-errors
3838              (push (car elem) vars)
3839              ;; Variables like `gnus-show-threads' that are globally
3840              ;; bound, if used as group parameters, need to get to be
3841              ;; buffer-local, whereas just parameters like `gcc-self',
3842              ;; `timestamp', etc. should not be bound as variables.
3843              (if (boundp (car elem))
3844                  (set (make-local-variable (car elem)) (eval (nth 1 elem)))
3845                (eval (nth 1 elem))))))))
3846
3847 (defun gnus-summary-read-group (group &optional show-all no-article
3848                                       kill-buffer no-display backward
3849                                       select-articles)
3850   "Start reading news in newsgroup GROUP.
3851 If SHOW-ALL is non-nil, already read articles are also listed.
3852 If NO-ARTICLE is non-nil, no article is selected initially.
3853 If NO-DISPLAY, don't generate a summary buffer."
3854   (let (result)
3855     (while (and group
3856                 (null (setq result
3857                             (let ((gnus-auto-select-next nil))
3858                               (or (gnus-summary-read-group-1
3859                                    group show-all no-article
3860                                    kill-buffer no-display
3861                                    select-articles)
3862                                   (setq show-all nil
3863                                         select-articles nil)))))
3864                 (eq gnus-auto-select-next 'quietly))
3865       (set-buffer gnus-group-buffer)
3866       ;; The entry function called above goes to the next
3867       ;; group automatically, so we go two groups back
3868       ;; if we are searching for the previous group.
3869       (when backward
3870         (gnus-group-prev-unread-group 2))
3871       (if (not (equal group (gnus-group-group-name)))
3872           (setq group (gnus-group-group-name))
3873         (setq group nil)))
3874     result))
3875
3876 (defun gnus-summary-read-group-1 (group show-all no-article
3877                                         kill-buffer no-display
3878                                         &optional select-articles)
3879   ;; Killed foreign groups can't be entered.
3880   ;;  (when (and (not (gnus-group-native-p group))
3881   ;;         (not (gnus-gethash group gnus-newsrc-hashtb)))
3882   ;;    (error "Dead non-native groups can't be entered"))
3883   (gnus-message 5 "Retrieving newsgroup: %s..."
3884                 (gnus-group-decoded-name group))
3885   (let* ((new-group (gnus-summary-setup-buffer group))
3886          (quit-config (gnus-group-quit-config group))
3887          (did-select (and new-group (gnus-select-newsgroup
3888                                      group show-all select-articles))))
3889     (cond
3890      ;; This summary buffer exists already, so we just select it.
3891      ((not new-group)
3892       (gnus-set-global-variables)
3893       (when kill-buffer
3894         (gnus-kill-or-deaden-summary kill-buffer))
3895       (gnus-configure-windows 'summary 'force)
3896       (gnus-set-mode-line 'summary)
3897       (gnus-summary-position-point)
3898       (message "")
3899       t)
3900      ;; We couldn't select this group.
3901      ((null did-select)
3902       (when (and (eq major-mode 'gnus-summary-mode)
3903                  (not (equal (current-buffer) kill-buffer)))
3904         (kill-buffer (current-buffer))
3905         (if (not quit-config)
3906             (progn
3907               ;; Update the info -- marks might need to be removed,
3908               ;; for instance.
3909               (gnus-summary-update-info)
3910               (set-buffer gnus-group-buffer)
3911               (gnus-group-jump-to-group group)
3912               (gnus-group-next-unread-group 1))
3913           (gnus-handle-ephemeral-exit quit-config)))
3914       (let ((grpinfo (gnus-get-info group)))
3915         (if (null (gnus-info-read grpinfo))
3916             (gnus-message 3 "Group %s contains no messages"
3917                           (gnus-group-decoded-name group))
3918           (gnus-message 3 "Can't select group")))
3919       nil)
3920      ;; The user did a `C-g' while prompting for number of articles,
3921      ;; so we exit this group.
3922      ((eq did-select 'quit)
3923       (and (eq major-mode 'gnus-summary-mode)
3924            (not (equal (current-buffer) kill-buffer))
3925            (kill-buffer (current-buffer)))
3926       (when kill-buffer
3927         (gnus-kill-or-deaden-summary kill-buffer))
3928       (if (not quit-config)
3929           (progn
3930             (set-buffer gnus-group-buffer)
3931             (gnus-group-jump-to-group group)
3932             (gnus-configure-windows 'group 'force))
3933         (gnus-handle-ephemeral-exit quit-config))
3934       ;; Finally signal the quit.
3935       (signal 'quit nil))
3936      ;; The group was successfully selected.
3937      (t
3938       (gnus-set-global-variables)
3939       ;; Save the active value in effect when the group was entered.
3940       (setq gnus-newsgroup-active
3941             (gnus-copy-sequence
3942              (gnus-active gnus-newsgroup-name)))
3943       ;; You can change the summary buffer in some way with this hook.
3944       (gnus-run-hooks 'gnus-select-group-hook)
3945       (when (memq 'summary (gnus-update-format-specifications
3946                             nil 'summary 'summary-mode 'summary-dummy))
3947         ;; The format specification for the summary line was updated,
3948         ;; so we need to update the mark positions as well.
3949         (gnus-update-summary-mark-positions))
3950       ;; Do score processing.
3951       (when gnus-use-scoring
3952         (gnus-possibly-score-headers))
3953       ;; Check whether to fill in the gaps in the threads.
3954       (when gnus-build-sparse-threads
3955         (gnus-build-sparse-threads))
3956       ;; Find the initial limit.
3957       (if show-all
3958           (let ((gnus-newsgroup-dormant nil))
3959             (gnus-summary-initial-limit show-all))
3960         (gnus-summary-initial-limit show-all))
3961       ;; Generate the summary buffer.
3962       (unless no-display
3963         (gnus-summary-prepare))
3964       (when gnus-use-trees
3965         (gnus-tree-open group)
3966         (setq gnus-summary-highlight-line-function
3967               'gnus-tree-highlight-article))
3968       ;; If the summary buffer is empty, but there are some low-scored
3969       ;; articles or some excluded dormants, we include these in the
3970       ;; buffer.
3971       (when (and (zerop (buffer-size))
3972                  (not no-display))
3973         (cond (gnus-newsgroup-dormant
3974                (gnus-summary-limit-include-dormant))
3975               ((and gnus-newsgroup-scored show-all)
3976                (gnus-summary-limit-include-expunged t))))
3977       ;; Function `gnus-apply-kill-file' must be called in this hook.
3978       (gnus-run-hooks 'gnus-apply-kill-hook)
3979       (if (and (zerop (buffer-size))
3980                (not no-display))
3981           (progn
3982             ;; This newsgroup is empty.
3983             (gnus-summary-catchup-and-exit nil t)
3984             (gnus-message 6 "No unread news")
3985             (when kill-buffer
3986               (gnus-kill-or-deaden-summary kill-buffer))
3987             ;; Return nil from this function.
3988             nil)
3989         ;; Hide conversation thread subtrees.  We cannot do this in
3990         ;; gnus-summary-prepare-hook since kill processing may not
3991         ;; work with hidden articles.
3992         (gnus-summary-maybe-hide-threads)
3993         (when kill-buffer
3994           (gnus-kill-or-deaden-summary kill-buffer))
3995         (gnus-summary-auto-select-subject)
3996         ;; Show first unread article if requested.
3997         (if (and (not no-article)
3998                  (not no-display)
3999                  gnus-newsgroup-unreads
4000                  gnus-auto-select-first)
4001             (progn
4002               (gnus-configure-windows 'summary)
4003               (let ((art (gnus-summary-article-number)))
4004                 (unless (and (not gnus-plugged)
4005                              (or (memq art gnus-newsgroup-undownloaded)
4006                                  (memq art gnus-newsgroup-downloadable)))
4007                   (gnus-summary-goto-article art))))
4008           ;; Don't select any articles.
4009           (gnus-summary-position-point)
4010           (gnus-configure-windows 'summary 'force)
4011           (gnus-set-mode-line 'summary))
4012         (when (and gnus-auto-center-group
4013                    (get-buffer-window gnus-group-buffer t))
4014           ;; Gotta use windows, because recenter does weird stuff if
4015           ;; the current buffer ain't the displayed window.
4016           (let ((owin (selected-window)))
4017             (select-window (get-buffer-window gnus-group-buffer t))
4018             (when (gnus-group-goto-group group)
4019               (recenter))
4020             (select-window owin)))
4021         ;; Mark this buffer as "prepared".
4022         (setq gnus-newsgroup-prepared t)
4023         (gnus-run-hooks 'gnus-summary-prepared-hook)
4024         (unless (gnus-ephemeral-group-p group)
4025           (gnus-group-update-group group))
4026         t)))))
4027
4028 (defun gnus-summary-auto-select-subject ()
4029   "Select the subject line on initial group entry."
4030   (goto-char (point-min))
4031   (cond
4032    ((eq gnus-auto-select-subject 'best)
4033     (gnus-summary-best-unread-subject))
4034    ((eq gnus-auto-select-subject 'unread)
4035     (gnus-summary-first-unread-subject))
4036    ((eq gnus-auto-select-subject 'unseen)
4037     (gnus-summary-first-unseen-subject))
4038    ((eq gnus-auto-select-subject 'unseen-or-unread)
4039     (gnus-summary-first-unseen-or-unread-subject))
4040    ((eq gnus-auto-select-subject 'first)
4041     ;; Do nothing.
4042     )
4043    ((functionp gnus-auto-select-subject)
4044     (funcall gnus-auto-select-subject))))
4045
4046 (defun gnus-summary-prepare ()
4047   "Generate the summary buffer."
4048   (interactive)
4049   (let ((inhibit-read-only t))
4050     (erase-buffer)
4051     (setq gnus-newsgroup-data nil
4052           gnus-newsgroup-data-reverse nil)
4053     (gnus-run-hooks 'gnus-summary-generate-hook)
4054     ;; Generate the buffer, either with threads or without.
4055     (when gnus-newsgroup-headers
4056       (gnus-summary-prepare-threads
4057        (if gnus-show-threads
4058            (gnus-sort-gathered-threads
4059             (funcall gnus-summary-thread-gathering-function
4060                      (gnus-sort-threads
4061                       (gnus-cut-threads (gnus-make-threads)))))
4062          ;; Unthreaded display.
4063          (gnus-sort-articles gnus-newsgroup-headers))))
4064     (setq gnus-newsgroup-data (nreverse gnus-newsgroup-data))
4065     ;; Call hooks for modifying summary buffer.
4066     (goto-char (point-min))
4067     (gnus-run-hooks 'gnus-summary-prepare-hook)))
4068
4069 (defsubst gnus-general-simplify-subject (subject)
4070   "Simplify subject by the same rules as `gnus-gather-threads-by-subject'."
4071   (setq subject
4072         (cond
4073          ;; Truncate the subject.
4074          (gnus-simplify-subject-functions
4075           (gnus-map-function gnus-simplify-subject-functions subject))
4076          ((numberp gnus-summary-gather-subject-limit)
4077           (setq subject (gnus-simplify-subject-re subject))
4078           (if (> (length subject) gnus-summary-gather-subject-limit)
4079               (substring subject 0 gnus-summary-gather-subject-limit)
4080             subject))
4081          ;; Fuzzily simplify it.
4082          ((eq 'fuzzy gnus-summary-gather-subject-limit)
4083           (gnus-simplify-subject-fuzzy subject))
4084          ;; Just remove the leading "Re:".
4085          (t
4086           (gnus-simplify-subject-re subject))))
4087
4088   (if (and gnus-summary-gather-exclude-subject
4089            (string-match gnus-summary-gather-exclude-subject subject))
4090       nil                         ; This article shouldn't be gathered
4091     subject))
4092
4093 (defun gnus-summary-simplify-subject-query ()
4094   "Query where the respool algorithm would put this article."
4095   (interactive)
4096   (gnus-summary-select-article)
4097   (message "%s" (gnus-general-simplify-subject (gnus-summary-article-subject))))
4098
4099 (defun gnus-gather-threads-by-subject (threads)
4100   "Gather threads by looking at Subject headers."
4101   (if (not gnus-summary-make-false-root)
4102       threads
4103     (let ((hashtb (gnus-make-hashtable 1024))
4104           (prev threads)
4105           (result threads)
4106           subject hthread whole-subject)
4107       (while threads
4108         (setq subject (gnus-general-simplify-subject
4109                        (setq whole-subject (mail-header-subject
4110                                             (caar threads)))))
4111         (when subject
4112           (if (setq hthread (gnus-gethash subject hashtb))
4113               (progn
4114                 ;; We enter a dummy root into the thread, if we
4115                 ;; haven't done that already.
4116                 (unless (stringp (caar hthread))
4117                   (setcar hthread (list whole-subject (car hthread))))
4118                 ;; We add this new gathered thread to this gathered
4119                 ;; thread.
4120                 (setcdr (car hthread)
4121                         (nconc (cdar hthread) (list (car threads))))
4122                 ;; Remove it from the list of threads.
4123                 (setcdr prev (cdr threads))
4124                 (setq threads prev))
4125             ;; Enter this thread into the hash table.
4126             (gnus-sethash subject
4127                           (if gnus-summary-make-false-root-always
4128                               (progn
4129                                 ;; If you want a dummy root above all
4130                                 ;; threads...
4131                                 (setcar threads (list whole-subject
4132                                                       (car threads)))
4133                                 threads)
4134                             threads)
4135                           hashtb)))
4136         (setq prev threads)
4137         (setq threads (cdr threads)))
4138       result)))
4139
4140 (defun gnus-gather-threads-by-references (threads)
4141   "Gather threads by looking at References headers."
4142   (let ((idhashtb (gnus-make-hashtable 1024))
4143         (thhashtb (gnus-make-hashtable 1024))
4144         (prev threads)
4145         (result threads)
4146         ids references id gthread gid entered ref)
4147     (while threads
4148       (when (setq references (mail-header-references (caar threads)))
4149         (setq id (mail-header-id (caar threads))
4150               ids (inline (gnus-split-references references))
4151               entered nil)
4152         (while (setq ref (pop ids))
4153           (setq ids (delete ref ids))
4154           (if (not (setq gid (gnus-gethash ref idhashtb)))
4155               (progn
4156                 (gnus-sethash ref id idhashtb)
4157                 (gnus-sethash id threads thhashtb))
4158             (setq gthread (gnus-gethash gid thhashtb))
4159             (unless entered
4160               ;; We enter a dummy root into the thread, if we
4161               ;; haven't done that already.
4162               (unless (stringp (caar gthread))
4163                 (setcar gthread (list (mail-header-subject (caar gthread))
4164                                       (car gthread))))
4165               ;; We add this new gathered thread to this gathered
4166               ;; thread.
4167               (setcdr (car gthread)
4168                       (nconc (cdar gthread) (list (car threads)))))
4169             ;; Add it into the thread hash table.
4170             (gnus-sethash id gthread thhashtb)
4171             (setq entered t)
4172             ;; Remove it from the list of threads.
4173             (setcdr prev (cdr threads))
4174             (setq threads prev))))
4175       (setq prev threads)
4176       (setq threads (cdr threads)))
4177     result))
4178
4179 (defun gnus-sort-gathered-threads (threads)
4180   "Sort subtreads inside each gathered thread by `gnus-sort-gathered-threads-function'."
4181   (let ((result threads))
4182     (while threads
4183       (when (stringp (caar threads))
4184         (setcdr (car threads)
4185                 (sort (cdar threads) gnus-sort-gathered-threads-function)))
4186       (setq threads (cdr threads)))
4187     result))
4188
4189 (defun gnus-thread-loop-p (root thread)
4190   "Say whether ROOT is in THREAD."
4191   (let ((stack (list thread))
4192         (infloop 0)
4193         th)
4194     (while (setq thread (pop stack))
4195       (setq th (cdr thread))
4196       (while (and th
4197                   (not (eq (caar th) root)))
4198         (pop th))
4199       (if th
4200           ;; We have found a loop.
4201           (let (ref-dep)
4202             (setcdr thread (delq (car th) (cdr thread)))
4203             (if (boundp (setq ref-dep (intern "none"
4204                                               gnus-newsgroup-dependencies)))
4205                 (setcdr (symbol-value ref-dep)
4206                         (nconc (cdr (symbol-value ref-dep))
4207                                (list (car th))))
4208               (set ref-dep (list nil (car th))))
4209             (setq infloop 1
4210                   stack nil))
4211         ;; Push all the subthreads onto the stack.
4212         (push (cdr thread) stack)))
4213     infloop))
4214
4215 (defun gnus-make-threads ()
4216   "Go through the dependency hashtb and find the roots.  Return all threads."
4217   (let (threads)
4218     (while (catch 'infloop
4219              (mapatoms
4220               (lambda (refs)
4221                 ;; Deal with self-referencing References loops.
4222                 (when (and (car (symbol-value refs))
4223                            (not (zerop
4224                                  (apply
4225                                   '+
4226                                   (mapcar
4227                                    (lambda (thread)
4228                                      (gnus-thread-loop-p
4229                                       (car (symbol-value refs)) thread))
4230                                    (cdr (symbol-value refs)))))))
4231                   (setq threads nil)
4232                   (throw 'infloop t))
4233                 (unless (car (symbol-value refs))
4234                   ;; These threads do not refer back to any other
4235                   ;; articles, so they're roots.
4236                   (setq threads (append (cdr (symbol-value refs)) threads))))
4237               gnus-newsgroup-dependencies)))
4238     threads))
4239
4240 ;; Build the thread tree.
4241 (defsubst gnus-dependencies-add-header (header dependencies force-new)
4242   "Enter HEADER into the DEPENDENCIES table if it is not already there.
4243
4244 If FORCE-NEW is not nil, enter HEADER into the DEPENDENCIES table even
4245 if it was already present.
4246
4247 If `gnus-summary-ignore-duplicates' is nil then duplicate Message-IDs
4248 will not be entered in the DEPENDENCIES table.  Otherwise duplicate
4249 Message-IDs will be renamed to a unique Message-ID before being
4250 entered.
4251
4252 Returns HEADER if it was entered in the DEPENDENCIES.  Returns nil otherwise."
4253   (let* ((id (mail-header-id header))
4254          (id-dep (and id (intern id dependencies)))
4255          parent-id ref ref-dep ref-header replaced)
4256     ;; Enter this `header' in the `dependencies' table.
4257     (cond
4258      ((not id-dep)
4259       (setq header nil))
4260      ;; The first two cases do the normal part: enter a new `header'
4261      ;; in the `dependencies' table.
4262      ((not (boundp id-dep))
4263       (set id-dep (list header)))
4264      ((null (car (symbol-value id-dep)))
4265       (setcar (symbol-value id-dep) header))
4266
4267      ;; From here the `header' was already present in the
4268      ;; `dependencies' table.
4269      (force-new
4270       ;; Overrides an existing entry;
4271       ;; just set the header part of the entry.
4272       (setcar (symbol-value id-dep) header)
4273       (setq replaced t))
4274
4275      ;; Renames the existing `header' to a unique Message-ID.
4276      ((not gnus-summary-ignore-duplicates)
4277       ;; An article with this Message-ID has already been seen.
4278       ;; We rename the Message-ID.
4279       (set (setq id-dep (intern (setq id (nnmail-message-id)) dependencies))
4280            (list header))
4281       (mail-header-set-id header id))
4282
4283      ;; The last case ignores an existing entry, except it adds any
4284      ;; additional Xrefs (in case the two articles came from different
4285      ;; servers.
4286      ;; Also sets `header' to `nil' meaning that the `dependencies'
4287      ;; table was *not* modified.
4288      (t
4289       (mail-header-set-xref
4290        (car (symbol-value id-dep))
4291        (concat (or (mail-header-xref (car (symbol-value id-dep)))
4292                    "")
4293                (or (mail-header-xref header) "")))
4294       (setq header nil)))
4295
4296     (when (and header (not replaced))
4297       ;; First check that we are not creating a References loop.
4298       (setq parent-id (gnus-parent-id (mail-header-references header)))
4299       (setq ref parent-id)
4300       (while (and ref
4301                   (setq ref-dep (intern-soft ref dependencies))
4302                   (boundp ref-dep)
4303                   (setq ref-header (car (symbol-value ref-dep))))
4304         (if (string= id ref)
4305             ;; Yuk!  This is a reference loop.  Make the article be a
4306             ;; root article.
4307             (progn
4308               (mail-header-set-references (car (symbol-value id-dep)) "none")
4309               (setq ref nil)
4310               (setq parent-id nil))
4311           (setq ref (gnus-parent-id (mail-header-references ref-header)))))
4312       (setq ref-dep (intern (or parent-id "none") dependencies))
4313       (if (boundp ref-dep)
4314           (setcdr (symbol-value ref-dep)
4315                   (nconc (cdr (symbol-value ref-dep))
4316                          (list (symbol-value id-dep))))
4317         (set ref-dep (list nil (symbol-value id-dep)))))
4318     header))
4319
4320 (defun gnus-extract-message-id-from-in-reply-to (string)
4321   (if (string-match "<[^>]+>" string)
4322       (substring string (match-beginning 0) (match-end 0))
4323     nil))
4324
4325 (defun gnus-build-sparse-threads ()
4326   (let ((headers gnus-newsgroup-headers)
4327         (mail-parse-charset gnus-newsgroup-charset)
4328         (gnus-summary-ignore-duplicates t)
4329         header references generation relations
4330         subject child end new-child date)
4331     ;; First we create an alist of generations/relations, where
4332     ;; generations is how much we trust the relation, and the relation
4333     ;; is parent/child.
4334     (gnus-message 7 "Making sparse threads...")
4335     (save-excursion
4336       (nnheader-set-temp-buffer " *gnus sparse threads*")
4337       (while (setq header (pop headers))
4338         (when (and (setq references (mail-header-references header))
4339                    (not (string= references "")))
4340           (insert references)
4341           (setq child (mail-header-id header)
4342                 subject (mail-header-subject header)
4343                 date (mail-header-date header)
4344                 generation 0)
4345           (while (search-backward ">" nil t)
4346             (setq end (1+ (point)))
4347             (when (search-backward "<" nil t)
4348               (setq new-child (buffer-substring (point) end))
4349               (push (list (incf generation)
4350                           child (setq child new-child)
4351                           subject date)
4352                     relations)))
4353           (when child
4354             (push (list (1+ generation) child nil subject) relations))
4355           (erase-buffer)))
4356       (kill-buffer (current-buffer)))
4357     ;; Sort over trustworthiness.
4358     (dolist (relation (sort relations 'car-less-than-car))
4359       (when (gnus-dependencies-add-header
4360              (make-full-mail-header
4361               gnus-reffed-article-number
4362               (nth 3 relation) "" (or (nth 4 relation) "")
4363               (nth 1 relation)
4364               (or (nth 2 relation) "") 0 0 "")
4365              gnus-newsgroup-dependencies nil)
4366         (push gnus-reffed-article-number gnus-newsgroup-limit)
4367         (push gnus-reffed-article-number gnus-newsgroup-sparse)
4368         (push (cons gnus-reffed-article-number gnus-sparse-mark)
4369               gnus-newsgroup-reads)
4370         (decf gnus-reffed-article-number)))
4371     (gnus-message 7 "Making sparse threads...done")))
4372
4373 (defun gnus-build-old-threads ()
4374   ;; Look at all the articles that refer back to old articles, and
4375   ;; fetch the headers for the articles that aren't there.  This will
4376   ;; build complete threads - if the roots haven't been expired by the
4377   ;; server, that is.
4378   (let ((mail-parse-charset gnus-newsgroup-charset)
4379         id heads)
4380     (mapatoms
4381      (lambda (refs)
4382        (when (not (car (symbol-value refs)))
4383          (setq heads (cdr (symbol-value refs)))
4384          (while heads
4385            (if (memq (mail-header-number (caar heads))
4386                      gnus-newsgroup-dormant)
4387                (setq heads (cdr heads))
4388              (setq id (symbol-name refs))
4389              (while (and (setq id (gnus-build-get-header id))
4390                          (not (car (gnus-id-to-thread id)))))
4391              (setq heads nil)))))
4392      gnus-newsgroup-dependencies)))
4393
4394 (defsubst gnus-remove-odd-characters (string)
4395   "Translate STRING into something that doesn't contain weird characters."
4396   (mm-subst-char-in-string
4397    ?\r ?\-
4398    (mm-subst-char-in-string ?\n ?\- string t) t))
4399
4400 ;; This function has to be called with point after the article number
4401 ;; on the beginning of the line.
4402 (defsubst gnus-nov-parse-line (number dependencies &optional force-new)
4403   (let ((eol (point-at-eol))
4404         (buffer (current-buffer))
4405         header references in-reply-to)
4406
4407     ;; overview: [num subject from date id refs chars lines misc]
4408     (unwind-protect
4409         (let (x)
4410           (narrow-to-region (point) eol)
4411           (unless (eobp)
4412             (forward-char))
4413
4414           (setq header
4415                 (make-full-mail-header
4416                  number                 ; number
4417                  (condition-case ()     ; subject
4418                      (gnus-remove-odd-characters
4419                       (funcall gnus-decode-encoded-word-function
4420                                (setq x (nnheader-nov-field))))
4421                    (error x))
4422                  (condition-case ()     ; from
4423                      (gnus-remove-odd-characters
4424                       (funcall gnus-decode-encoded-address-function
4425                                (setq x (nnheader-nov-field))))
4426                    (error x))
4427                  (nnheader-nov-field)   ; date
4428                  (nnheader-nov-read-message-id number)  ; id
4429                  (setq references (nnheader-nov-field)) ; refs
4430                  (nnheader-nov-read-integer) ; chars
4431                  (nnheader-nov-read-integer) ; lines
4432                  (unless (eobp)
4433                    (if (looking-at "Xref: ")
4434                        (goto-char (match-end 0)))
4435                    (nnheader-nov-field)) ; Xref
4436                  (nnheader-nov-parse-extra)))) ; extra
4437
4438       (widen))
4439
4440     (when (and (string= references "")
4441                (setq in-reply-to (mail-header-extra header))
4442                (setq in-reply-to (cdr (assq 'In-Reply-To in-reply-to))))
4443       (mail-header-set-references
4444        header (gnus-extract-message-id-from-in-reply-to in-reply-to)))
4445
4446     (when gnus-alter-header-function
4447       (funcall gnus-alter-header-function header))
4448     (gnus-dependencies-add-header header dependencies force-new)))
4449
4450 (defun gnus-build-get-header (id)
4451   "Look through the buffer of NOV lines and find the header to ID.
4452 Enter this line into the dependencies hash table, and return
4453 the id of the parent article (if any)."
4454   (let ((deps gnus-newsgroup-dependencies)
4455         found header)
4456     (prog1
4457         (with-current-buffer nntp-server-buffer
4458           (let ((case-fold-search nil))
4459             (goto-char (point-min))
4460             (while (and (not found)
4461                         (search-forward id nil t))
4462               (beginning-of-line)
4463               (setq found (looking-at
4464                            (format "^[^\t]*\t[^\t]*\t[^\t]*\t[^\t]*\t%s"
4465                                    (regexp-quote id))))
4466               (or found (beginning-of-line 2)))
4467             (when found
4468               (beginning-of-line)
4469               (and
4470                (setq header (gnus-nov-parse-line
4471                              (read (current-buffer)) deps))
4472                (gnus-parent-id (mail-header-references header))))))
4473       (when header
4474         (let ((number (mail-header-number header)))
4475           (push number gnus-newsgroup-limit)
4476           (push header gnus-newsgroup-headers)
4477           (if (memq number gnus-newsgroup-unselected)
4478               (progn
4479                 (setq gnus-newsgroup-unreads
4480                       (gnus-add-to-sorted-list gnus-newsgroup-unreads
4481                                                number))
4482                 (setq gnus-newsgroup-unselected
4483                       (delq number gnus-newsgroup-unselected)))
4484             (push number gnus-newsgroup-ancient)))))))
4485
4486 (defun gnus-build-all-threads ()
4487   "Read all the headers."
4488   (let ((gnus-summary-ignore-duplicates t)
4489         (mail-parse-charset gnus-newsgroup-charset)
4490         (dependencies gnus-newsgroup-dependencies)
4491         header article)
4492     (with-current-buffer nntp-server-buffer
4493       (let ((case-fold-search nil))
4494         (goto-char (point-min))
4495         (while (not (eobp))
4496           (ignore-errors
4497             (setq article (read (current-buffer))
4498                   header (gnus-nov-parse-line article dependencies)))
4499           (when header
4500             (with-current-buffer gnus-summary-buffer
4501               (push header gnus-newsgroup-headers)
4502               (if (memq (setq article (mail-header-number header))
4503                         gnus-newsgroup-unselected)
4504                   (progn
4505                     (setq gnus-newsgroup-unreads
4506                           (gnus-add-to-sorted-list
4507                            gnus-newsgroup-unreads article))
4508                     (setq gnus-newsgroup-unselected
4509                           (delq article gnus-newsgroup-unselected)))
4510                 (push article gnus-newsgroup-ancient)))
4511             (forward-line 1)))))))
4512
4513 (defun gnus-summary-update-article-line (article header)
4514   "Update the line for ARTICLE using HEADER."
4515   (let* ((id (mail-header-id header))
4516          (thread (gnus-id-to-thread id)))
4517     (unless thread
4518       (error "Article in no thread"))
4519     ;; Update the thread.
4520     (setcar thread header)
4521     (gnus-summary-goto-subject article)
4522     (let* ((datal (gnus-data-find-list article))
4523            (data (car datal))
4524            (inhibit-read-only t)
4525            (level (gnus-summary-thread-level)))
4526       (gnus-delete-line)
4527       (let ((inserted (- (point)
4528                          (progn
4529                            (gnus-summary-insert-line
4530                             header level nil
4531                             (memq article gnus-newsgroup-undownloaded)
4532                             (gnus-article-mark article)
4533                             (memq article gnus-newsgroup-replied)
4534                             (memq article gnus-newsgroup-expirable)
4535                             ;; Only insert the Subject string when it's different
4536                             ;; from the previous Subject string.
4537                             (if (and
4538                                  gnus-show-threads
4539                                  (gnus-subject-equal
4540                                   (condition-case ()
4541                                       (mail-header-subject
4542                                        (gnus-data-header
4543                                         (cadr
4544                                          (gnus-data-find-list
4545                                           article
4546                                           (gnus-data-list t)))))
4547                                     ;; Error on the side of excessive subjects.
4548                                     (error ""))
4549                                   (mail-header-subject header)))
4550                                 ""
4551                               (mail-header-subject header))
4552                             nil (cdr (assq article gnus-newsgroup-scored))
4553                             (memq article gnus-newsgroup-processable))
4554                            (point)))))
4555         (when (cdr datal)
4556           (gnus-data-update-list
4557            (cdr datal)
4558            (- (gnus-data-pos data) (gnus-data-pos (cadr datal)) inserted)))))))
4559
4560 (defun gnus-summary-update-article (article &optional iheader)
4561   "Update ARTICLE in the summary buffer."
4562   (set-buffer gnus-summary-buffer)
4563   (let* ((header (gnus-summary-article-header article))
4564          (id (mail-header-id header))
4565          (data (gnus-data-find article))
4566          (thread (gnus-id-to-thread id))
4567          (references (mail-header-references header))
4568          (parent
4569           (gnus-id-to-thread
4570            (or (gnus-parent-id
4571                 (when (and references
4572                            (not (equal "" references)))
4573                   references))
4574                "none")))
4575          (inhibit-read-only t)
4576          (old (car thread)))
4577     (when thread
4578       (unless iheader
4579         (setcar thread nil)
4580         (when parent
4581           (delq thread parent)))
4582       (if (gnus-summary-insert-subject id header)
4583           ;; Set the (possibly) new article number in the data structure.
4584           (gnus-data-set-number data (gnus-id-to-article id))
4585         (setcar thread old)
4586         nil))))
4587
4588 (defun gnus-rebuild-thread (id &optional line)
4589   "Rebuild the thread containing ID.
4590 If LINE, insert the rebuilt thread starting on line LINE."
4591   (let ((inhibit-read-only t)
4592         old-pos current thread data)
4593     (if (not gnus-show-threads)
4594         (setq thread (list (car (gnus-id-to-thread id))))
4595       ;; Get the thread this article is part of.
4596       (setq thread (gnus-remove-thread id)))
4597     (setq old-pos (point-at-bol))
4598     (setq current (save-excursion
4599                     (and (re-search-backward "[\r\n]" nil t)
4600                          (gnus-summary-article-number))))
4601     ;; If this is a gathered thread, we have to go some re-gathering.
4602     (when (stringp (car thread))
4603       (let ((subject (car thread))
4604             roots thr)
4605         (setq thread (cdr thread))
4606         (while thread
4607           (unless (memq (setq thr (gnus-id-to-thread
4608                                    (gnus-root-id
4609                                     (mail-header-id (caar thread)))))
4610                         roots)
4611             (push thr roots))
4612           (setq thread (cdr thread)))
4613         ;; We now have all (unique) roots.
4614         (if (= (length roots) 1)
4615             ;; All the loose roots are now one solid root.
4616             (setq thread (car roots))
4617           (setq thread (cons subject (gnus-sort-threads roots))))))
4618     (let (threads)
4619       ;; We then insert this thread into the summary buffer.
4620       (when line
4621         (goto-char (point-min))
4622         (forward-line (1- line)))
4623       (let (gnus-newsgroup-data gnus-newsgroup-threads)
4624         (if gnus-show-threads
4625             (gnus-summary-prepare-threads (gnus-cut-threads (list thread)))
4626           (gnus-summary-prepare-unthreaded thread))
4627         (setq data (nreverse gnus-newsgroup-data))
4628         (setq threads gnus-newsgroup-threads))
4629       ;; We splice the new data into the data structure.
4630       ;;!!! This is kinda bogus.  We assume that in LINE is non-nil,
4631       ;;!!! then we want to insert at the beginning of the buffer.
4632       ;;!!! That happens to be true with Gnus now, but that may
4633       ;;!!! change in the future.  Perhaps.
4634       (gnus-data-enter-list
4635        (if line nil current) data (- (point) old-pos))
4636       (setq gnus-newsgroup-threads
4637             (nconc threads gnus-newsgroup-threads))
4638       (gnus-data-compute-positions))))
4639
4640 (defun gnus-number-to-header (number)
4641   "Return the header for article NUMBER."
4642   (let ((headers gnus-newsgroup-headers))
4643     (while (and headers
4644                 (not (= number (mail-header-number (car headers)))))
4645       (pop headers))
4646     (when headers
4647       (car headers))))
4648
4649 (defun gnus-parent-headers (in-headers &optional generation)
4650   "Return the headers of the GENERATIONeth parent of HEADERS."
4651   (unless generation
4652     (setq generation 1))
4653   (let ((parent t)
4654         (headers in-headers)
4655         references)
4656     (while (and parent
4657                 (not (zerop generation))
4658                 (setq references (mail-header-references headers)))
4659       (setq headers (if (and references
4660                              (setq parent (gnus-parent-id references)))
4661                         (car (gnus-id-to-thread parent))
4662                       nil))
4663       (decf generation))
4664     (and (not (eq headers in-headers))
4665          headers)))
4666
4667 (defun gnus-id-to-thread (id)
4668   "Return the (sub-)thread where ID appears."
4669   (gnus-gethash id gnus-newsgroup-dependencies))
4670
4671 (defun gnus-id-to-article (id)
4672   "Return the article number of ID."
4673   (let ((thread (gnus-id-to-thread id)))
4674     (when (and thread
4675                (car thread))
4676       (mail-header-number (car thread)))))
4677
4678 (defun gnus-id-to-header (id)
4679   "Return the article headers of ID."
4680   (car (gnus-id-to-thread id)))
4681
4682 (defun gnus-article-displayed-root-p (article)
4683   "Say whether ARTICLE is a root(ish) article."
4684   (let ((level (gnus-summary-thread-level article))
4685         (refs (mail-header-references  (gnus-summary-article-header article)))
4686         particle)
4687     (cond
4688      ((null level) nil)
4689      ((zerop level) t)
4690      ((null refs) t)
4691      ((null (gnus-parent-id refs)) t)
4692      ((and (= 1 level)
4693            (null (setq particle (gnus-id-to-article
4694                                  (gnus-parent-id refs))))
4695            (null (gnus-summary-thread-level particle)))))))
4696
4697 (defun gnus-root-id (id)
4698   "Return the id of the root of the thread where ID appears."
4699   (let (last-id prev)
4700     (while (and id (setq prev (car (gnus-id-to-thread id))))
4701       (setq last-id id
4702             id (gnus-parent-id (mail-header-references prev))))
4703     last-id))
4704
4705 (defun gnus-articles-in-thread (thread)
4706   "Return the list of articles in THREAD."
4707   (cons (mail-header-number (car thread))
4708         (apply 'nconc (mapcar 'gnus-articles-in-thread (cdr thread)))))
4709
4710 (defun gnus-remove-thread (id &optional dont-remove)
4711   "Remove the thread that has ID in it."
4712   (let (headers thread last-id)
4713     ;; First go up in this thread until we find the root.
4714     (setq last-id (gnus-root-id id)
4715           headers (message-flatten-list (gnus-id-to-thread last-id)))
4716     ;; We have now found the real root of this thread.  It might have
4717     ;; been gathered into some loose thread, so we have to search
4718     ;; through the threads to find the thread we wanted.
4719     (let ((threads gnus-newsgroup-threads)
4720           sub)
4721       (while threads
4722         (setq sub (car threads))
4723         (if (stringp (car sub))
4724             ;; This is a gathered thread, so we look at the roots
4725             ;; below it to find whether this article is in this
4726             ;; gathered root.
4727             (progn
4728               (setq sub (cdr sub))
4729               (while sub
4730                 (when (member (caar sub) headers)
4731                   (setq thread (car threads)
4732                         threads nil
4733                         sub nil))
4734                 (setq sub (cdr sub))))
4735           ;; It's an ordinary thread, so we check it.
4736           (when (eq (car sub) (car headers))
4737             (setq thread sub
4738                   threads nil)))
4739         (setq threads (cdr threads)))
4740       ;; If this article is in no thread, then it's a root.
4741       (if thread
4742           (unless dont-remove
4743             (setq gnus-newsgroup-threads (delq thread gnus-newsgroup-threads)))
4744         (setq thread (gnus-id-to-thread last-id)))
4745       (when thread
4746         (prog1
4747             thread                      ; We return this thread.
4748           (unless dont-remove
4749             (if (stringp (car thread))
4750                 (progn
4751                   ;; If we use dummy roots, then we have to remove the
4752                   ;; dummy root as well.
4753                   (when (eq gnus-summary-make-false-root 'dummy)
4754                     ;; We go to the dummy root by going to
4755                     ;; the first sub-"thread", and then one line up.
4756                     (gnus-summary-goto-article
4757                      (mail-header-number (caadr thread)))
4758                     (forward-line -1)
4759                     (gnus-delete-line)
4760                     (gnus-data-compute-positions))
4761                   (setq thread (cdr thread))
4762                   (while thread
4763                     (gnus-remove-thread-1 (car thread))
4764                     (setq thread (cdr thread))))
4765               (gnus-remove-thread-1 thread))))))))
4766
4767 (defun gnus-remove-thread-1 (thread)
4768   "Remove the thread THREAD recursively."
4769   (let ((number (mail-header-number (pop thread)))
4770         d)
4771     (setq thread (reverse thread))
4772     (while thread
4773       (gnus-remove-thread-1 (pop thread)))
4774     (when (setq d (gnus-data-find number))
4775       (goto-char (gnus-data-pos d))
4776       (gnus-summary-show-thread)
4777       (gnus-data-remove
4778        number
4779        (- (point-at-bol)
4780           (prog1
4781               (1+ (point-at-eol))
4782             (gnus-delete-line)))))))
4783
4784 (defun gnus-sort-threads-recursive (threads func)
4785   (sort (mapcar (lambda (thread)
4786                   (cons (car thread)
4787                         (and (cdr thread)
4788                              (gnus-sort-threads-recursive (cdr thread) func))))
4789                 threads) func))
4790
4791 (defun gnus-sort-threads-loop (threads func)
4792   (let* ((superthread (cons nil threads))
4793          (stack (list (cons superthread threads)))
4794          remaining-threads thread)
4795     (while stack
4796       (setq remaining-threads (cdr (car stack)))
4797       (if remaining-threads
4798           (progn (setq thread (car remaining-threads))
4799                  (setcdr (car stack) (cdr remaining-threads))
4800                  (if (cdr thread)
4801                      (push (cons thread (cdr thread)) stack)))
4802         (setq thread (caar stack))
4803         (setcdr thread (sort (cdr thread) func))
4804         (pop stack)))
4805     (cdr superthread)))
4806
4807 (defun gnus-sort-threads (threads)
4808   "Sort THREADS."
4809   (if (not gnus-thread-sort-functions)
4810       threads
4811     (gnus-message 8 "Sorting threads...")
4812     (prog1
4813         (condition-case nil
4814             (let ((max-lisp-eval-depth (max max-lisp-eval-depth 5000)))
4815               (gnus-sort-threads-recursive
4816                threads (gnus-make-sort-function gnus-thread-sort-functions)))
4817           ;; Even after binding max-lisp-eval-depth, the recursive
4818           ;; sorter might fail for very long threads.  In that case,
4819           ;; try using a (less well-tested) non-recursive sorter.
4820           (error (gnus-message 9 "Sorting threads with loop...")
4821                  (gnus-sort-threads-loop
4822                   threads (gnus-make-sort-function
4823                            gnus-thread-sort-functions))))
4824       (gnus-message 8 "Sorting threads...done"))))
4825
4826 (defun gnus-sort-articles (articles)
4827   "Sort ARTICLES."
4828   (when gnus-article-sort-functions
4829     (gnus-message 7 "Sorting articles...")
4830     (prog1
4831         (setq gnus-newsgroup-headers
4832               (sort articles (gnus-make-sort-function
4833                               gnus-article-sort-functions)))
4834       (gnus-message 7 "Sorting articles...done"))))
4835
4836 ;; Written by Hallvard B Furuseth <h.b.furuseth@usit.uio.no>.
4837 (defmacro gnus-thread-header (thread)
4838   "Return header of first article in THREAD.
4839 Note that THREAD must never, ever be anything else than a variable -
4840 using some other form will lead to serious barfage."
4841   (or (symbolp thread) (signal 'wrong-type-argument '(symbolp thread)))
4842   ;; (8% speedup to gnus-summary-prepare, just for fun :-)
4843   (list 'byte-code "\10\211:\203\17\0\211@;\203\16\0A@@\207"
4844         (vector thread) 2))
4845
4846 (defsubst gnus-article-sort-by-number (h1 h2)
4847   "Sort articles by article number."
4848   (< (mail-header-number h1)
4849      (mail-header-number h2)))
4850
4851 (defun gnus-thread-sort-by-number (h1 h2)
4852   "Sort threads by root article number."
4853   (gnus-article-sort-by-number
4854    (gnus-thread-header h1) (gnus-thread-header h2)))
4855
4856 (defsubst gnus-article-sort-by-random (h1 h2)
4857   "Sort articles randomly."
4858   (zerop (random 2)))
4859
4860 (defun gnus-thread-sort-by-random (h1 h2)
4861   "Sort threads randomly."
4862   (gnus-article-sort-by-random
4863    (gnus-thread-header h1) (gnus-thread-header h2)))
4864
4865 (defsubst gnus-article-sort-by-lines (h1 h2)
4866   "Sort articles by article Lines header."
4867   (< (mail-header-lines h1)
4868      (mail-header-lines h2)))
4869
4870 (defun gnus-thread-sort-by-lines (h1 h2)
4871   "Sort threads by root article Lines header."
4872   (gnus-article-sort-by-lines
4873    (gnus-thread-header h1) (gnus-thread-header h2)))
4874
4875 (defsubst gnus-article-sort-by-chars (h1 h2)
4876   "Sort articles by octet length."
4877   (< (mail-header-chars h1)
4878      (mail-header-chars h2)))
4879
4880 (defun gnus-thread-sort-by-chars (h1 h2)
4881   "Sort threads by root article octet length."
4882   (gnus-article-sort-by-chars
4883    (gnus-thread-header h1) (gnus-thread-header h2)))
4884
4885 (defsubst gnus-article-sort-by-author (h1 h2)
4886   "Sort articles by root author."
4887   (gnus-string<
4888    (let ((extract (funcall
4889                    gnus-extract-address-components
4890                    (mail-header-from h1))))
4891      (or (car extract) (cadr extract) ""))
4892    (let ((extract (funcall
4893                    gnus-extract-address-components
4894                    (mail-header-from h2))))
4895      (or (car extract) (cadr extract) ""))))
4896
4897 (defun gnus-thread-sort-by-author (h1 h2)
4898   "Sort threads by root author."
4899   (gnus-article-sort-by-author
4900    (gnus-thread-header h1)  (gnus-thread-header h2)))
4901
4902 (defsubst gnus-article-sort-by-recipient (h1 h2)
4903   "Sort articles by recipient."
4904   (gnus-string<
4905    (let ((extract (funcall
4906                    gnus-extract-address-components
4907                    (or (cdr (assq 'To (mail-header-extra h1))) ""))))
4908      (or (car extract) (cadr extract)))
4909    (let ((extract (funcall
4910                    gnus-extract-address-components
4911                    (or (cdr (assq 'To (mail-header-extra h2))) ""))))
4912      (or (car extract) (cadr extract)))))
4913
4914 (defun gnus-thread-sort-by-recipient (h1 h2)
4915   "Sort threads by root recipient."
4916   (gnus-article-sort-by-recipient
4917    (gnus-thread-header h1) (gnus-thread-header h2)))
4918
4919 (defsubst gnus-article-sort-by-subject (h1 h2)
4920   "Sort articles by root subject."
4921   (gnus-string<
4922    (downcase (gnus-simplify-subject-re (mail-header-subject h1)))
4923    (downcase (gnus-simplify-subject-re (mail-header-subject h2)))))
4924
4925 (defun gnus-thread-sort-by-subject (h1 h2)
4926   "Sort threads by root subject."
4927   (gnus-article-sort-by-subject
4928    (gnus-thread-header h1) (gnus-thread-header h2)))
4929
4930 (defsubst gnus-article-sort-by-date (h1 h2)
4931   "Sort articles by root article date."
4932   (time-less-p
4933    (gnus-date-get-time (mail-header-date h1))
4934    (gnus-date-get-time (mail-header-date h2))))
4935
4936 (defun gnus-thread-sort-by-date (h1 h2)
4937   "Sort threads by root article date."
4938   (gnus-article-sort-by-date
4939    (gnus-thread-header h1) (gnus-thread-header h2)))
4940
4941 (defsubst gnus-article-sort-by-score (h1 h2)
4942   "Sort articles by root article score.
4943 Unscored articles will be counted as having a score of zero."
4944   (> (or (cdr (assq (mail-header-number h1)
4945                     gnus-newsgroup-scored))
4946          gnus-summary-default-score 0)
4947      (or (cdr (assq (mail-header-number h2)
4948                     gnus-newsgroup-scored))
4949          gnus-summary-default-score 0)))
4950
4951 (defun gnus-thread-sort-by-score (h1 h2)
4952   "Sort threads by root article score."
4953   (gnus-article-sort-by-score
4954    (gnus-thread-header h1) (gnus-thread-header h2)))
4955
4956 (defun gnus-thread-sort-by-total-score (h1 h2)
4957   "Sort threads by the sum of all scores in the thread.
4958 Unscored articles will be counted as having a score of zero."
4959   (> (gnus-thread-total-score h1) (gnus-thread-total-score h2)))
4960
4961 (defun gnus-thread-total-score (thread)
4962   ;; This function find the total score of THREAD.
4963   (cond
4964    ((null thread)
4965     0)
4966    ((consp thread)
4967     (if (stringp (car thread))
4968         (apply gnus-thread-score-function 0
4969                (mapcar 'gnus-thread-total-score-1 (cdr thread)))
4970       (gnus-thread-total-score-1 thread)))
4971    (t
4972     (gnus-thread-total-score-1 (list thread)))))
4973
4974 (defun gnus-thread-sort-by-most-recent-number (h1 h2)
4975   "Sort threads such that the thread with the most recently arrived article comes first."
4976   (> (gnus-thread-highest-number h1) (gnus-thread-highest-number h2)))
4977
4978 (defun gnus-thread-highest-number (thread)
4979   "Return the highest article number in THREAD."
4980   (apply 'max (mapcar (lambda (header)
4981                         (mail-header-number header))
4982                       (message-flatten-list thread))))
4983
4984 (defun gnus-thread-sort-by-most-recent-date (h1 h2)
4985   "Sort threads such that the thread with the most recently dated article comes first."
4986   (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2)))
4987
4988 ; Since this is called not only to sort the top-level threads, but
4989 ; also in recursive sorts to order the articles within a thread, each
4990 ; article will be processed many times.  Thus it speeds things up
4991 ; quite a bit to use gnus-date-get-time, which caches the time value.
4992 (defun gnus-thread-latest-date (thread)
4993   "Return the highest article date in THREAD."
4994   (apply 'max
4995          (mapcar (lambda (header) (gnus-float-time
4996                                    (gnus-date-get-time
4997                                     (mail-header-date header))))
4998                  (message-flatten-list thread))))
4999
5000 (defun gnus-thread-total-score-1 (root)
5001   ;; This function find the total score of the thread below ROOT.
5002   (setq root (car root))
5003   (apply gnus-thread-score-function
5004          (or (append
5005               (mapcar 'gnus-thread-total-score
5006                       (cdr (gnus-id-to-thread (mail-header-id root))))
5007               (when (> (mail-header-number root) 0)
5008                 (list (or (cdr (assq (mail-header-number root)
5009                                      gnus-newsgroup-scored))
5010                           gnus-summary-default-score 0))))
5011              (list gnus-summary-default-score)
5012              '(0))))
5013
5014 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
5015 (defvar gnus-tmp-prev-subject nil)
5016 (defvar gnus-tmp-false-parent nil)
5017 (defvar gnus-tmp-root-expunged nil)
5018 (defvar gnus-tmp-dummy-line nil)
5019
5020 (defun gnus-extra-header (type &optional header)
5021   "Return the extra header of TYPE."
5022   (or (cdr (assq type (mail-header-extra (or header gnus-tmp-header))))
5023       ""))
5024
5025 (defvar gnus-tmp-thread-tree-header-string "")
5026
5027 (defcustom gnus-sum-thread-tree-root "> "
5028   "With %B spec, used for the root of a thread.
5029 If nil, use subject instead."
5030   :version "22.1"
5031   :type '(radio (const :format "%v  " nil) string)
5032   :group 'gnus-thread)
5033
5034 (defcustom gnus-sum-thread-tree-false-root "> "
5035   "With %B spec, used for a false root of a thread.
5036 If nil, use subject instead."
5037   :version "22.1"
5038   :type '(radio (const :format "%v  " nil) string)
5039   :group 'gnus-thread)
5040
5041 (defcustom gnus-sum-thread-tree-single-indent ""
5042   "With %B spec, used for a thread with just one message.
5043 If nil, use subject instead."
5044   :version "22.1"
5045   :type '(radio (const :format "%v  " nil) string)
5046   :group 'gnus-thread)
5047
5048 (defcustom gnus-sum-thread-tree-vertical "| "
5049   "With %B spec, used for drawing a vertical line."
5050   :version "22.1"
5051   :type 'string
5052   :group 'gnus-thread)
5053
5054 (defcustom gnus-sum-thread-tree-indent "  "
5055   "With %B spec, used for indenting."
5056   :version "22.1"
5057   :type 'string
5058   :group 'gnus-thread)
5059
5060 (defcustom gnus-sum-thread-tree-leaf-with-other "+-> "
5061   "With %B spec, used for a leaf with brothers."
5062   :version "22.1"
5063   :type 'string
5064   :group 'gnus-thread)
5065
5066 (defcustom gnus-sum-thread-tree-single-leaf "\\-> "
5067   "With %B spec, used for a leaf without brothers."
5068   :version "22.1"
5069   :type 'string
5070   :group 'gnus-thread)
5071
5072 (defcustom gnus-summary-display-while-building nil
5073   "If non-nil, show and update the summary buffer as it's being built.
5074 If the value is t, update the buffer after every line is inserted.  If
5075 the value is an integer (N), update the display every N lines."
5076   :version "22.1"
5077   :group 'gnus-thread
5078   :type '(choice (const :tag "off" nil)
5079                  number
5080                  (const :tag "frequently" t)))
5081
5082 (defun gnus-summary-prepare-threads (threads)
5083   "Prepare summary buffer from THREADS and indentation LEVEL.
5084 THREADS is either a list of `(PARENT [(CHILD1 [(GRANDCHILD ...]...) ...])'
5085 or a straight list of headers."
5086   (gnus-message 7 "Generating summary...")
5087
5088   (setq gnus-newsgroup-threads threads)
5089   (beginning-of-line)
5090
5091   (let ((gnus-tmp-level 0)
5092         (default-score (or gnus-summary-default-score 0))
5093         (gnus-visual-p (gnus-visual-p 'summary-highlight 'highlight))
5094         (building-line-count gnus-summary-display-while-building)
5095         (building-count (integerp gnus-summary-display-while-building))
5096         thread number subject stack state gnus-tmp-gathered beg-match
5097         new-roots gnus-tmp-new-adopts thread-end simp-subject
5098         gnus-tmp-header gnus-tmp-unread gnus-tmp-downloaded
5099         gnus-tmp-replied gnus-tmp-subject-or-nil
5100         gnus-tmp-dummy gnus-tmp-indentation gnus-tmp-lines gnus-tmp-score
5101         gnus-tmp-score-char gnus-tmp-from gnus-tmp-name
5102         gnus-tmp-number gnus-tmp-opening-bracket gnus-tmp-closing-bracket
5103         tree-stack)
5104
5105     (setq gnus-tmp-prev-subject nil
5106           gnus-tmp-thread-tree-header-string "")
5107
5108     (if (vectorp (car threads))
5109         ;; If this is a straight (sic) list of headers, then a
5110         ;; threaded summary display isn't required, so we just create
5111         ;; an unthreaded one.
5112         (gnus-summary-prepare-unthreaded threads)
5113
5114       ;; Do the threaded display.
5115
5116       (if gnus-summary-display-while-building
5117           (switch-to-buffer (buffer-name)))
5118       (while (or threads stack gnus-tmp-new-adopts new-roots)
5119
5120         (if (and (= gnus-tmp-level 0)
5121                  (or (not stack)
5122                      (= (caar stack) 0))
5123                  (not gnus-tmp-false-parent)
5124                  (or gnus-tmp-new-adopts new-roots))
5125             (if gnus-tmp-new-adopts
5126                 (setq gnus-tmp-level (if gnus-tmp-root-expunged 0 1)
5127                       thread (list (car gnus-tmp-new-adopts))
5128                       gnus-tmp-header (caar thread)
5129                       gnus-tmp-new-adopts (cdr gnus-tmp-new-adopts))
5130               (when new-roots
5131                 (setq thread (list (car new-roots))
5132                       gnus-tmp-header (caar thread)
5133                       new-roots (cdr new-roots))))
5134
5135           (if threads
5136               ;; If there are some threads, we do them before the
5137               ;; threads on the stack.
5138               (setq thread threads
5139                     gnus-tmp-header (caar thread))
5140             ;; There were no current threads, so we pop something off
5141             ;; the stack.
5142             (setq state (car stack)
5143                   gnus-tmp-level (car state)
5144                   tree-stack (cadr state)
5145                   thread (caddr state)
5146                   stack (cdr stack)
5147                   gnus-tmp-header (caar thread))))
5148
5149         (setq gnus-tmp-false-parent nil)
5150         (setq gnus-tmp-root-expunged nil)
5151         (setq thread-end nil)
5152
5153         (if (stringp gnus-tmp-header)
5154             ;; The header is a dummy root.
5155             (cond
5156              ((eq gnus-summary-make-false-root 'adopt)
5157               ;; We let the first article adopt the rest.
5158               (setq gnus-tmp-new-adopts (nconc gnus-tmp-new-adopts
5159                                                (cddar thread)))
5160               (setq gnus-tmp-gathered
5161                     (nconc (mapcar
5162                             (lambda (h) (mail-header-number (car h)))
5163                             (cddar thread))
5164                            gnus-tmp-gathered))
5165               (setq thread (cons (list (caar thread)
5166                                        (cadar thread))
5167                                  (cdr thread)))
5168               (setq gnus-tmp-level -1
5169                     gnus-tmp-false-parent t))
5170              ((eq gnus-summary-make-false-root 'empty)
5171               ;; We print adopted articles with empty subject fields.
5172               (setq gnus-tmp-gathered
5173                     (nconc (mapcar
5174                             (lambda (h) (mail-header-number (car h)))
5175                             (cddar thread))
5176                            gnus-tmp-gathered))
5177               (setq gnus-tmp-level -1))
5178              ((eq gnus-summary-make-false-root 'dummy)
5179               ;; We remember that we probably want to output a dummy
5180               ;; root.
5181               (setq gnus-tmp-dummy-line gnus-tmp-header)
5182               (setq gnus-tmp-prev-subject gnus-tmp-header))
5183              (t
5184               ;; We do not make a root for the gathered
5185               ;; sub-threads at all.
5186               (setq gnus-tmp-level -1)))
5187
5188           (setq number (mail-header-number gnus-tmp-header)
5189                 subject (mail-header-subject gnus-tmp-header)
5190                 simp-subject (gnus-simplify-subject-fully subject))
5191
5192           (cond
5193            ;; If the thread has changed subject, we might want to make
5194            ;; this subthread into a root.
5195            ((and (null gnus-thread-ignore-subject)
5196                  (not (zerop gnus-tmp-level))
5197                  gnus-tmp-prev-subject
5198                  (not (string= gnus-tmp-prev-subject simp-subject)))
5199             (setq new-roots (nconc new-roots (list (car thread)))
5200                   thread-end t
5201                   gnus-tmp-header nil))
5202            ;; If the article lies outside the current limit,
5203            ;; then we do not display it.
5204            ((not (memq number gnus-newsgroup-limit))
5205             (setq gnus-tmp-gathered
5206                   (nconc (mapcar
5207                           (lambda (h) (mail-header-number (car h)))
5208                           (cdar thread))
5209                          gnus-tmp-gathered))
5210             (setq gnus-tmp-new-adopts (if (cdar thread)
5211                                           (append gnus-tmp-new-adopts
5212                                                   (cdar thread))
5213                                         gnus-tmp-new-adopts)
5214                   thread-end t
5215                   gnus-tmp-header nil)
5216             (when (zerop gnus-tmp-level)
5217               (setq gnus-tmp-root-expunged t)))
5218            ;; Perhaps this article is to be marked as read?
5219            ((and gnus-summary-mark-below
5220                  (< (or (cdr (assq number gnus-newsgroup-scored))
5221                         default-score)
5222                     gnus-summary-mark-below)
5223                  ;; Don't touch sparse articles.
5224                  (not (gnus-summary-article-sparse-p number))
5225                  (not (gnus-summary-article-ancient-p number)))
5226             (setq gnus-newsgroup-unreads
5227                   (delq number gnus-newsgroup-unreads))
5228             (if gnus-newsgroup-auto-expire
5229                 (setq gnus-newsgroup-expirable
5230                       (gnus-add-to-sorted-list
5231                        gnus-newsgroup-expirable number))
5232               (push (cons number gnus-low-score-mark)
5233                     gnus-newsgroup-reads))))
5234
5235           (when gnus-tmp-header
5236             ;; We may have an old dummy line to output before this
5237             ;; article.
5238             (when (and gnus-tmp-dummy-line
5239                        (gnus-subject-equal
5240                         gnus-tmp-dummy-line
5241                         (mail-header-subject gnus-tmp-header)))
5242               (gnus-summary-insert-dummy-line
5243                gnus-tmp-dummy-line (mail-header-number gnus-tmp-header))
5244               (setq gnus-tmp-dummy-line nil))
5245
5246             ;; Compute the mark.
5247             (setq gnus-tmp-unread (gnus-article-mark number))
5248
5249             (push (gnus-data-make number gnus-tmp-unread (1+ (point))
5250                                   gnus-tmp-header gnus-tmp-level)
5251                   gnus-newsgroup-data)
5252
5253             ;; Actually insert the line.
5254             (setq
5255              gnus-tmp-subject-or-nil
5256              (cond
5257               ((and gnus-thread-ignore-subject
5258                     gnus-tmp-prev-subject
5259                     (not (string= gnus-tmp-prev-subject simp-subject)))
5260                subject)
5261               ((zerop gnus-tmp-level)
5262                (if (and (eq gnus-summary-make-false-root 'empty)
5263                         (memq number gnus-tmp-gathered)
5264                         gnus-tmp-prev-subject
5265                         (string= gnus-tmp-prev-subject simp-subject))
5266                    gnus-summary-same-subject
5267                  subject))
5268               (t gnus-summary-same-subject)))
5269             (if (and (eq gnus-summary-make-false-root 'adopt)
5270                      (= gnus-tmp-level 1)
5271                      (memq number gnus-tmp-gathered))
5272                 (setq gnus-tmp-opening-bracket ?\<
5273                       gnus-tmp-closing-bracket ?\>)
5274               (setq gnus-tmp-opening-bracket ?\[
5275                     gnus-tmp-closing-bracket ?\]))
5276             (if (>= gnus-tmp-level (length gnus-thread-indent-array))
5277                 (gnus-make-thread-indent-array
5278                  (max (* 2 (length gnus-thread-indent-array))
5279                       gnus-tmp-level)))
5280             (setq
5281              gnus-tmp-indentation
5282              (aref gnus-thread-indent-array gnus-tmp-level)
5283              gnus-tmp-lines (mail-header-lines gnus-tmp-header)
5284              gnus-tmp-score (or (cdr (assq number gnus-newsgroup-scored))
5285                                 gnus-summary-default-score 0)
5286              gnus-tmp-score-char
5287              (if (or (null gnus-summary-default-score)
5288                      (<= (abs (- gnus-tmp-score gnus-summary-default-score))
5289                          gnus-summary-zcore-fuzz))
5290                  ?                      ;Whitespace
5291                (if (< gnus-tmp-score gnus-summary-default-score)
5292                    gnus-score-below-mark gnus-score-over-mark))
5293              gnus-tmp-replied
5294              (cond ((memq number gnus-newsgroup-processable)
5295                     gnus-process-mark)
5296                    ((memq number gnus-newsgroup-cached)
5297                     gnus-cached-mark)
5298                    ((memq number gnus-newsgroup-replied)
5299                     gnus-replied-mark)
5300                    ((memq number gnus-newsgroup-forwarded)
5301                     gnus-forwarded-mark)
5302                    ((memq number gnus-newsgroup-saved)
5303                     gnus-saved-mark)
5304                    ((memq number gnus-newsgroup-recent)
5305                     gnus-recent-mark)
5306                    ((memq number gnus-newsgroup-unseen)
5307                     gnus-unseen-mark)
5308                    (t gnus-no-mark))
5309              gnus-tmp-downloaded
5310              (cond ((memq number gnus-newsgroup-undownloaded)
5311                     gnus-undownloaded-mark)
5312                    (gnus-newsgroup-agentized
5313                     gnus-downloaded-mark)
5314                    (t
5315                     gnus-no-mark))
5316              gnus-tmp-from (mail-header-from gnus-tmp-header)
5317              gnus-tmp-name
5318              (cond
5319               ((string-match "<[^>]+> *$" gnus-tmp-from)
5320                (setq beg-match (match-beginning 0))
5321                (or (and (string-match "^\".+\"" gnus-tmp-from)
5322                         (substring gnus-tmp-from 1 (1- (match-end 0))))
5323                    (substring gnus-tmp-from 0 beg-match)))
5324               ((string-match "(.+)" gnus-tmp-from)
5325                (substring gnus-tmp-from
5326                           (1+ (match-beginning 0)) (1- (match-end 0))))
5327               (t gnus-tmp-from))
5328
5329              ;; Do the %B string
5330              gnus-tmp-thread-tree-header-string
5331              (cond
5332               ((not gnus-show-threads) "")
5333               ((zerop gnus-tmp-level)
5334                (cond ((cdar thread)
5335                       (or gnus-sum-thread-tree-root subject))
5336                      (gnus-tmp-new-adopts
5337                       (or gnus-sum-thread-tree-false-root subject))
5338                      (t
5339                       (or gnus-sum-thread-tree-single-indent subject))))
5340               (t
5341                (concat (apply 'concat
5342                               (mapcar (lambda (item)
5343                                         (if (= item 1)
5344                                             gnus-sum-thread-tree-vertical
5345                                           gnus-sum-thread-tree-indent))
5346                                       (cdr (reverse tree-stack))))
5347                        (if (nth 1 thread)
5348                            gnus-sum-thread-tree-leaf-with-other
5349                          gnus-sum-thread-tree-single-leaf)))))
5350             (when (string= gnus-tmp-name "")
5351               (setq gnus-tmp-name gnus-tmp-from))
5352             (unless (numberp gnus-tmp-lines)
5353               (setq gnus-tmp-lines -1))
5354             (if (= gnus-tmp-lines -1)
5355                 (setq gnus-tmp-lines "?")
5356               (setq gnus-tmp-lines (number-to-string gnus-tmp-lines)))
5357               (gnus-put-text-property
5358                (point)
5359                (progn (eval gnus-summary-line-format-spec) (point))
5360                'gnus-number number)
5361               (when gnus-visual-p
5362                 (forward-line -1)
5363                 (gnus-run-hooks 'gnus-summary-update-hook)
5364                 (forward-line 1))
5365
5366               (setq gnus-tmp-prev-subject simp-subject)))
5367
5368         (when (nth 1 thread)
5369           (push (list (max 0 gnus-tmp-level)
5370                       (copy-sequence tree-stack)
5371                       (nthcdr 1 thread))
5372                 stack))
5373         (push (if (nth 1 thread) 1 0) tree-stack)
5374         (incf gnus-tmp-level)
5375         (setq threads (if thread-end nil (cdar thread)))
5376         (if gnus-summary-display-while-building
5377             (if building-count
5378                 (progn
5379                   ;; use a set frequency
5380                   (setq building-line-count (1- building-line-count))
5381                   (when (= building-line-count 0)
5382                     (sit-for 0)
5383                     (setq building-line-count
5384                           gnus-summary-display-while-building)))
5385               ;; always
5386               (sit-for 0)))
5387         (unless threads
5388           (setq gnus-tmp-level 0)))))
5389   (gnus-message 7 "Generating summary...done"))
5390
5391 (defun gnus-summary-prepare-unthreaded (headers)
5392   "Generate an unthreaded summary buffer based on HEADERS."
5393   (let (header number mark)
5394
5395     (beginning-of-line)
5396
5397     (while headers
5398       ;; We may have to root out some bad articles...
5399       (when (memq (setq number (mail-header-number
5400                                 (setq header (pop headers))))
5401                   gnus-newsgroup-limit)
5402         ;; Mark article as read when it has a low score.
5403         (when (and gnus-summary-mark-below
5404                    (< (or (cdr (assq number gnus-newsgroup-scored))
5405                           gnus-summary-default-score 0)
5406                       gnus-summary-mark-below)
5407                    (not (gnus-summary-article-ancient-p number)))
5408           (setq gnus-newsgroup-unreads
5409                 (delq number gnus-newsgroup-unreads))
5410           (if gnus-newsgroup-auto-expire
5411               (push number gnus-newsgroup-expirable)
5412             (push (cons number gnus-low-score-mark)
5413                   gnus-newsgroup-reads)))
5414
5415         (setq mark (gnus-article-mark number))
5416         (push (gnus-data-make number mark (1+ (point)) header 0)
5417               gnus-newsgroup-data)
5418         (gnus-summary-insert-line
5419          header 0 number
5420          (memq number gnus-newsgroup-undownloaded)
5421          mark (memq number gnus-newsgroup-replied)
5422          (memq number gnus-newsgroup-expirable)
5423          (mail-header-subject header) nil
5424          (cdr (assq number gnus-newsgroup-scored))
5425          (memq number gnus-newsgroup-processable))))))
5426
5427 (defun gnus-summary-remove-list-identifiers ()
5428   "Remove list identifiers in `gnus-list-identifiers' from articles in the current group."
5429   (let ((regexp (if (consp gnus-list-identifiers)
5430                     (mapconcat 'identity gnus-list-identifiers " *\\|")
5431                   gnus-list-identifiers))
5432         changed subject)
5433     (when regexp
5434       (setq regexp (concat "^\\(?:R[Ee]: +\\)*\\(" regexp " *\\)"))
5435       (dolist (header gnus-newsgroup-headers)
5436         (setq subject (mail-header-subject header)
5437               changed nil)
5438         (while (string-match regexp subject)
5439           (setq subject
5440                 (concat (substring subject 0 (match-beginning 1))
5441                         (substring subject (match-end 0)))
5442                 changed t))
5443         (when changed
5444           (when (string-match "^\\(\\(?:R[Ee]: +\\)+\\)R[Ee]: +" subject)
5445             (setq subject
5446                   (concat (substring subject 0 (match-beginning 1))
5447                           (substring subject (match-end 1)))))
5448           (mail-header-set-subject header subject))))))
5449
5450 (defun gnus-fetch-headers (articles)
5451   "Fetch headers of ARTICLES."
5452   (let ((name (gnus-group-decoded-name gnus-newsgroup-name)))
5453     (gnus-message 5 "Fetching headers for %s..." name)
5454     (prog1
5455         (if (eq 'nov
5456                 (setq gnus-headers-retrieved-by
5457                       (gnus-retrieve-headers
5458                        articles gnus-newsgroup-name
5459                        ;; We might want to fetch old headers, but
5460                        ;; not if there is only 1 article.
5461                        (and (or (and
5462                                  (not (eq gnus-fetch-old-headers 'some))
5463                                  (not (numberp gnus-fetch-old-headers)))
5464                                 (> (length articles) 1))
5465                             gnus-fetch-old-headers))))
5466             (gnus-get-newsgroup-headers-xover
5467              articles nil nil gnus-newsgroup-name t)
5468           (gnus-get-newsgroup-headers))
5469       (gnus-message 5 "Fetching headers for %s...done" name))))
5470
5471 (defun gnus-select-newsgroup (group &optional read-all select-articles)
5472   "Select newsgroup GROUP.
5473 If READ-ALL is non-nil, all articles in the group are selected.
5474 If SELECT-ARTICLES, only select those articles from GROUP."
5475   (let* ((entry (gnus-group-entry group))
5476          ;;!!! Dirty hack; should be removed.
5477          (gnus-summary-ignore-duplicates
5478           (if (eq (car (gnus-find-method-for-group group)) 'nnvirtual)
5479               t
5480             gnus-summary-ignore-duplicates))
5481          (info (nth 2 entry))
5482          charset articles fetched-articles cached)
5483
5484     (unless (gnus-check-server
5485              (set (make-local-variable 'gnus-current-select-method)
5486                   (gnus-find-method-for-group group)))
5487       (error "Couldn't open server"))
5488     (setq charset (gnus-group-name-charset gnus-current-select-method group))
5489
5490     (or (and entry (not (eq (car entry) t))) ; Either it's active...
5491         (gnus-activate-group group)     ; Or we can activate it...
5492         (progn                          ; Or we bug out.
5493           (when (equal major-mode 'gnus-summary-mode)
5494             (gnus-kill-buffer (current-buffer)))
5495           (error
5496            "Couldn't activate group %s: %s"
5497            (mm-decode-coding-string group charset)
5498            (mm-decode-coding-string (gnus-status-message group) charset))))
5499
5500     (unless (gnus-request-group group t)
5501         (when (equal major-mode 'gnus-summary-mode)
5502           (gnus-kill-buffer (current-buffer)))
5503         (error "Couldn't request group %s: %s"
5504                (mm-decode-coding-string group charset)
5505                (mm-decode-coding-string (gnus-status-message group) charset)))
5506
5507     (when gnus-agent
5508       (gnus-agent-possibly-alter-active group (gnus-active group) info)
5509
5510       (setq gnus-summary-use-undownloaded-faces
5511             (gnus-agent-find-parameter
5512              group
5513              'agent-enable-undownloaded-faces)))
5514
5515     (setq gnus-newsgroup-name group
5516           gnus-newsgroup-unselected nil
5517           gnus-newsgroup-unreads (gnus-list-of-unread-articles group))
5518
5519     (let ((display (gnus-group-find-parameter group 'display)))
5520       (setq gnus-newsgroup-display
5521             (cond
5522              ((not (zerop (or (car-safe read-all) 0)))
5523               ;; The user entered the group with C-u SPC/RET, let's show
5524               ;; all articles.
5525               'gnus-not-ignore)
5526              ((eq display 'all)
5527               'gnus-not-ignore)
5528              ((arrayp display)
5529               (gnus-summary-display-make-predicate (mapcar 'identity display)))
5530              ((numberp display)
5531               ;; The following is probably the "correct" solution, but
5532               ;; it makes Gnus fetch all headers and then limit the
5533               ;; articles (which is slow), so instead we hack the
5534               ;; select-articles parameter instead. -- Simon Josefsson
5535               ;; <jas@kth.se>
5536               ;;
5537               ;; (gnus-byte-compile
5538               ;;  `(lambda () (> number ,(- (cdr (gnus-active group))
5539               ;;                         display)))))
5540               (setq select-articles
5541                     (gnus-uncompress-range
5542                      (cons (let ((tmp (- (cdr (gnus-active group)) display)))
5543                              (if (> tmp 0)
5544                                  tmp
5545                                1))
5546                            (cdr (gnus-active group)))))
5547               nil)
5548              (t
5549               nil))))
5550
5551     (gnus-summary-setup-default-charset)
5552
5553     ;; Kludge to avoid having cached articles nixed out in virtual groups.
5554     (when (gnus-virtual-group-p group)
5555       (setq cached gnus-newsgroup-cached))
5556
5557     (setq gnus-newsgroup-unreads
5558           (gnus-sorted-ndifference
5559            (gnus-sorted-ndifference gnus-newsgroup-unreads
5560                                     gnus-newsgroup-marked)
5561            gnus-newsgroup-dormant))
5562
5563     (setq gnus-newsgroup-processable nil)
5564
5565     (gnus-update-read-articles group gnus-newsgroup-unreads)
5566
5567     ;; Adjust and set lists of article marks.
5568     (when info
5569       (gnus-adjust-marked-articles info))
5570     (if (setq articles select-articles)
5571         (setq gnus-newsgroup-unselected
5572               (gnus-sorted-difference gnus-newsgroup-unreads articles))
5573       (setq articles (gnus-articles-to-read group read-all)))
5574
5575     (cond
5576      ((null articles)
5577       ;;(gnus-message 3 "Couldn't select newsgroup -- no articles to display")
5578       'quit)
5579      ((eq articles 0) nil)
5580      (t
5581       ;; Init the dependencies hash table.
5582       (setq gnus-newsgroup-dependencies
5583             (gnus-make-hashtable (length articles)))
5584       (gnus-set-global-variables)
5585       ;; Retrieve the headers and read them in.
5586
5587       (setq gnus-newsgroup-headers (gnus-fetch-headers articles))
5588
5589       ;; Kludge to avoid having cached articles nixed out in virtual groups.
5590       (when cached
5591         (setq gnus-newsgroup-cached cached))
5592
5593       ;; Suppress duplicates?
5594       (when gnus-suppress-duplicates
5595         (gnus-dup-suppress-articles))
5596
5597       ;; Set the initial limit.
5598       (setq gnus-newsgroup-limit (copy-sequence articles))
5599       ;; Remove canceled articles from the list of unread articles.
5600       (setq fetched-articles
5601             (mapcar (lambda (headers) (mail-header-number headers))
5602                     gnus-newsgroup-headers))
5603       (setq gnus-newsgroup-articles fetched-articles)
5604       (setq gnus-newsgroup-unreads
5605             (gnus-sorted-nintersection
5606              gnus-newsgroup-unreads fetched-articles))
5607       (gnus-compute-unseen-list)
5608
5609       ;; Removed marked articles that do not exist.
5610       (gnus-update-missing-marks
5611        (gnus-sorted-difference articles fetched-articles))
5612       ;; We might want to build some more threads first.
5613       (when (and gnus-fetch-old-headers
5614                  (eq gnus-headers-retrieved-by 'nov))
5615         (if (eq gnus-fetch-old-headers 'invisible)
5616             (gnus-build-all-threads)
5617           (gnus-build-old-threads)))
5618       ;; Let the Gnus agent mark articles as read.
5619       (when gnus-agent
5620         (gnus-agent-get-undownloaded-list))
5621       ;; Remove list identifiers from subject
5622       (when gnus-list-identifiers
5623         (gnus-summary-remove-list-identifiers))
5624       ;; Check whether auto-expire is to be done in this group.
5625       (setq gnus-newsgroup-auto-expire
5626             (gnus-group-auto-expirable-p group))
5627       ;; Set up the article buffer now, if necessary.
5628       (unless (and gnus-single-article-buffer
5629                    (equal gnus-article-buffer "*Article*"))
5630         (gnus-article-setup-buffer))
5631       ;; First and last article in this newsgroup.
5632       (when gnus-newsgroup-headers
5633         (setq gnus-newsgroup-begin
5634               (mail-header-number (car gnus-newsgroup-headers))
5635               gnus-newsgroup-end
5636               (mail-header-number
5637                (gnus-last-element gnus-newsgroup-headers))))
5638       ;; GROUP is successfully selected.
5639       (or gnus-newsgroup-headers t)))))
5640
5641 (defun gnus-compute-unseen-list ()
5642   ;; The `seen' marks are treated specially.
5643   (if (not gnus-newsgroup-seen)
5644       (setq gnus-newsgroup-unseen gnus-newsgroup-articles)
5645     (setq gnus-newsgroup-unseen
5646           (gnus-inverse-list-range-intersection
5647            gnus-newsgroup-articles gnus-newsgroup-seen))))
5648
5649 (declare-function gnus-get-predicate "gnus-agent" (predicate))
5650
5651 (defun gnus-summary-display-make-predicate (display)
5652   (require 'gnus-agent)
5653   (when (= (length display) 1)
5654     (setq display (car display)))
5655   (unless gnus-summary-display-cache
5656     (dolist (elem (append '((unread . unread)
5657                             (read . read)
5658                             (unseen . unseen))
5659                           gnus-article-mark-lists))
5660       (push (cons (cdr elem)
5661                   (gnus-byte-compile
5662                    `(lambda () (gnus-article-marked-p ',(cdr elem)))))
5663             gnus-summary-display-cache)))
5664   (let ((gnus-category-predicate-alist gnus-summary-display-cache)
5665         (gnus-category-predicate-cache gnus-summary-display-cache))
5666     (gnus-get-predicate display)))
5667
5668 ;; Uses the dynamically bound `number' variable.
5669 (defvar number)
5670 (defun gnus-article-marked-p (type &optional article)
5671   (let ((article (or article number)))
5672     (cond
5673      ((eq type 'tick)
5674       (memq article gnus-newsgroup-marked))
5675      ((eq type 'spam)
5676       (memq article gnus-newsgroup-spam-marked))
5677      ((eq type 'unsend)
5678       (memq article gnus-newsgroup-unsendable))
5679      ((eq type 'undownload)
5680       (memq article gnus-newsgroup-undownloaded))
5681      ((eq type 'download)
5682       (memq article gnus-newsgroup-downloadable))
5683      ((eq type 'unread)
5684       (memq article gnus-newsgroup-unreads))
5685      ((eq type 'read)
5686       (memq article gnus-newsgroup-reads))
5687      ((eq type 'dormant)
5688       (memq article gnus-newsgroup-dormant) )
5689      ((eq type 'expire)
5690       (memq article gnus-newsgroup-expirable))
5691      ((eq type 'reply)
5692       (memq article gnus-newsgroup-replied))
5693      ((eq type 'killed)
5694       (memq article gnus-newsgroup-killed))
5695      ((eq type 'bookmark)
5696       (assq article gnus-newsgroup-bookmarks))
5697      ((eq type 'score)
5698       (assq article gnus-newsgroup-scored))
5699      ((eq type 'save)
5700       (memq article gnus-newsgroup-saved))
5701      ((eq type 'cache)
5702       (memq article gnus-newsgroup-cached))
5703      ((eq type 'forward)
5704       (memq article gnus-newsgroup-forwarded))
5705      ((eq type 'seen)
5706       (not (memq article gnus-newsgroup-unseen)))
5707      ((eq type 'recent)
5708       (memq article gnus-newsgroup-recent))
5709      (t t))))
5710
5711 (defun gnus-articles-to-read (group &optional read-all)
5712   "Find out what articles the user wants to read."
5713   (let* ((articles
5714           ;; Select all articles if `read-all' is non-nil, or if there
5715           ;; are no unread articles.
5716           (if (or read-all
5717                   (and (zerop (length gnus-newsgroup-marked))
5718                        (zerop (length gnus-newsgroup-unreads)))
5719                   ;; Fetch all if the predicate is non-nil.
5720                   gnus-newsgroup-display)
5721               ;; We want to select the headers for all the articles in
5722               ;; the group, so we select either all the active
5723               ;; articles in the group, or (if that's nil), the
5724               ;; articles in the cache.
5725               (or
5726                (if gnus-newsgroup-maximum-articles
5727                    (let ((active (gnus-active group)))
5728                      (gnus-uncompress-range
5729                       (cons (max (car active)
5730                                  (- (cdr active)
5731                                     gnus-newsgroup-maximum-articles
5732                                     -1))
5733                             (cdr active))))
5734                  (gnus-uncompress-range (gnus-active group)))
5735                (gnus-cache-articles-in-group group))
5736             ;; Select only the "normal" subset of articles.
5737             (gnus-sorted-nunion
5738              (gnus-sorted-union gnus-newsgroup-dormant gnus-newsgroup-marked)
5739              gnus-newsgroup-unreads)))
5740          (scored-list (gnus-killed-articles gnus-newsgroup-killed articles))
5741          (scored (length scored-list))
5742          (number (length articles))
5743          (marked (+ (length gnus-newsgroup-marked)
5744                     (length gnus-newsgroup-dormant)))
5745          (select
5746           (cond
5747            ((numberp read-all)
5748             read-all)
5749            ((numberp gnus-newsgroup-display)
5750             gnus-newsgroup-display)
5751            (t
5752             (condition-case ()
5753                 (cond
5754                  ((and (or (<= scored marked) (= scored number))
5755                        (numberp gnus-large-newsgroup)
5756                        (> number gnus-large-newsgroup))
5757                   (let* ((cursor-in-echo-area nil)
5758                          (initial (gnus-parameter-large-newsgroup-initial
5759                                    gnus-newsgroup-name))
5760                          (input
5761                           (read-string
5762                            (format
5763                             "How many articles from %s (%s %d): "
5764                             (gnus-group-decoded-name gnus-newsgroup-name)
5765                             (if initial "max" "default")
5766                             number)
5767                            (if initial
5768                                (cons (number-to-string initial)
5769                                      0)))))
5770                     (if (string-match "^[ \t]*$" input) number input)))
5771                  ((and (> scored marked) (< scored number)
5772                        (> (- scored number) 20))
5773                   (let ((input
5774                          (read-string
5775                           (format "%s %s (%d scored, %d total): "
5776                                   "How many articles from"
5777                                   (gnus-group-decoded-name group)
5778                                   scored number))))
5779                     (if (string-match "^[ \t]*$" input)
5780                         number input)))
5781                  (t number))
5782               (quit
5783                (message "Quit getting the articles to read")
5784                nil))))))
5785     (setq select (if (stringp select) (string-to-number select) select))
5786     (if (or (null select) (zerop select))
5787         select
5788       (if (and (not (zerop scored)) (<= (abs select) scored))
5789           (progn
5790             (setq articles (sort scored-list '<))
5791             (setq number (length articles)))
5792         (setq articles (copy-sequence articles)))
5793
5794       (when (< (abs select) number)
5795         (if (< select 0)
5796             ;; Select the N oldest articles.
5797             (setcdr (nthcdr (1- (abs select)) articles) nil)
5798           ;; Select the N most recent articles.
5799           (setq articles (nthcdr (- number select) articles))))
5800       (setq gnus-newsgroup-unselected
5801             (gnus-sorted-difference gnus-newsgroup-unreads articles))
5802       (when gnus-alter-articles-to-read-function
5803         (setq articles
5804               (sort
5805                (funcall gnus-alter-articles-to-read-function
5806                         gnus-newsgroup-name articles)
5807                '<)))
5808       articles)))
5809
5810 (defun gnus-killed-articles (killed articles)
5811   (let (out)
5812     (while articles
5813       (when (inline (gnus-member-of-range (car articles) killed))
5814         (push (car articles) out))
5815       (setq articles (cdr articles)))
5816     out))
5817
5818 (defun gnus-uncompress-marks (marks)
5819   "Uncompress the mark ranges in MARKS."
5820   (let ((uncompressed '(score bookmark))
5821         out)
5822     (while marks
5823       (if (memq (caar marks) uncompressed)
5824           (push (car marks) out)
5825         (push (cons (caar marks) (gnus-uncompress-range (cdar marks))) out))
5826       (setq marks (cdr marks)))
5827     out))
5828
5829 (defun gnus-article-mark-to-type (mark)
5830   "Return the type of MARK."
5831   (or (cadr (assq mark gnus-article-special-mark-lists))
5832       'list))
5833
5834 (defun gnus-article-unpropagatable-p (mark)
5835   "Return whether MARK should be propagated to back end."
5836   (memq mark gnus-article-unpropagated-mark-lists))
5837
5838 (defun gnus-adjust-marked-articles (info)
5839   "Set all article lists and remove all marks that are no longer valid."
5840   (let* ((marked-lists (gnus-info-marks info))
5841          (active (gnus-active (gnus-info-group info)))
5842          (min (car active))
5843          (max (cdr active))
5844          (types gnus-article-mark-lists)
5845          marks var articles article mark mark-type
5846          bgn end)
5847
5848     (dolist (marks marked-lists)
5849       (setq mark (car marks)
5850             mark-type (gnus-article-mark-to-type mark)
5851             var (intern (format "gnus-newsgroup-%s" (car (rassq mark types)))))
5852
5853       ;; We set the variable according to the type of the marks list,
5854       ;; and then adjust the marks to a subset of the active articles.
5855       (cond
5856        ;; Adjust "simple" lists - compressed yet unsorted
5857        ((eq mark-type 'list)
5858         ;; Simultaneously uncompress and clip to active range
5859         ;; See gnus-uncompress-range for a description of possible marks
5860         (let (l lh)
5861           (if (not (cadr marks))
5862               (set var nil)
5863             (setq articles (if (numberp (cddr marks))
5864                                (list (cdr marks))
5865                              (cdr marks))
5866                   lh (cons nil nil)
5867                   l lh)
5868
5869             (while (setq article (pop articles))
5870               (cond ((consp article)
5871                      (setq bgn (max (car article) min)
5872                            end (min (cdr article) max))
5873                      (while (<= bgn end)
5874                        (setq l (setcdr l (cons bgn nil))
5875                              bgn (1+ bgn))))
5876                     ((and (<= min article)
5877                           (>= max article))
5878                      (setq l (setcdr l (cons article nil))))))
5879             (set var (cdr lh)))))
5880        ;; Adjust assocs.
5881        ((eq mark-type 'tuple)
5882         (set var (setq articles (cdr marks)))
5883         (when (not (listp (cdr (symbol-value var))))
5884           (set var (list (symbol-value var))))
5885         (when (not (listp (cdr articles)))
5886           (setq articles (list articles)))
5887         (while articles
5888           (when (or (not (consp (setq article (pop articles))))
5889                     (< (car article) min)
5890                     (> (car article) max))
5891             (set var (delq article (symbol-value var))))))
5892        ;; Adjust ranges (sloppily).
5893        ((eq mark-type 'range)
5894         (cond
5895          ((eq mark 'seen)
5896           ;; Fix the record for `seen' if it looks like (seen NUM1 . NUM2).
5897           ;; It should be (seen (NUM1 . NUM2)).
5898           (when (numberp (cddr marks))
5899             (setcdr marks (list (cdr marks))))
5900           (setq articles (cdr marks))
5901           (while (and articles
5902                       (or (and (consp (car articles))
5903                                (> min (cdar articles)))
5904                           (and (numberp (car articles))
5905                                (> min (car articles)))))
5906             (pop articles))
5907           (set var articles))))))))
5908
5909 (defun gnus-update-missing-marks (missing)
5910   "Go through the list of MISSING articles and remove them from the mark lists."
5911   (when missing
5912     (let (var m)
5913       ;; Go through all types.
5914       (dolist (elem gnus-article-mark-lists)
5915         (when (eq (gnus-article-mark-to-type (cdr elem)) 'list)
5916           (setq var (intern (format "gnus-newsgroup-%s" (car elem))))
5917           (when (symbol-value var)
5918             ;; This list has articles.  So we delete all missing
5919             ;; articles from it.
5920             (setq m missing)
5921             (while m
5922               (set var (delq (pop m) (symbol-value var))))))))))
5923
5924 (defun gnus-update-marks ()
5925   "Enter the various lists of marked articles into the newsgroup info list."
5926   (let ((types gnus-article-mark-lists)
5927         (info (gnus-get-info gnus-newsgroup-name))
5928         type list newmarked symbol delta-marks)
5929     (when info
5930       ;; Add all marks lists to the list of marks lists.
5931       (while (setq type (pop types))
5932         (setq list (symbol-value
5933                     (setq symbol
5934                           (intern (format "gnus-newsgroup-%s" (car type))))))
5935
5936         (when list
5937           ;; Get rid of the entries of the articles that have the
5938           ;; default score.
5939           (when (and (eq (cdr type) 'score)
5940                      gnus-save-score
5941                      list)
5942             (let* ((arts list)
5943                    (prev (cons nil list))
5944                    (all prev))
5945               (while arts
5946                 (if (or (not (consp (car arts)))
5947                         (= (cdar arts) gnus-summary-default-score))
5948                     (setcdr prev (cdr arts))
5949                   (setq prev arts))
5950                 (setq arts (cdr arts)))
5951               (setq list (cdr all)))))
5952
5953         (when (eq (cdr type) 'seen)
5954           (setq list (gnus-range-add list gnus-newsgroup-unseen)))
5955
5956         (when (eq (gnus-article-mark-to-type (cdr type)) 'list)
5957           (setq list (gnus-compress-sequence (set symbol (sort list '<)) t)))
5958
5959         (when (and (gnus-check-backend-function
5960                     'request-set-mark gnus-newsgroup-name)
5961                    (not (gnus-article-unpropagatable-p (cdr type))))
5962           (let* ((old (cdr (assq (cdr type) (gnus-info-marks info))))
5963                  (del (gnus-remove-from-range (gnus-copy-sequence old) list))
5964                  (add (gnus-remove-from-range
5965                        (gnus-copy-sequence list) old)))
5966             (when add
5967               (push (list add 'add (list (cdr type))) delta-marks))
5968             (when del
5969               (push (list del 'del (list (cdr type))) delta-marks))))
5970
5971         (when list
5972           (push (cons (cdr type) list) newmarked)))
5973
5974       (when delta-marks
5975         (unless (gnus-check-group gnus-newsgroup-name)
5976           (error "Can't open server for %s" gnus-newsgroup-name))
5977         (gnus-request-set-mark gnus-newsgroup-name delta-marks))
5978
5979       ;; Enter these new marks into the info of the group.
5980       (if (nthcdr 3 info)
5981           (setcar (nthcdr 3 info) newmarked)
5982         ;; Add the marks lists to the end of the info.
5983         (when newmarked
5984           (setcdr (nthcdr 2 info) (list newmarked))))
5985
5986       ;; Cut off the end of the info if there's nothing else there.
5987       (let ((i 5))
5988         (while (and (> i 2)
5989                     (not (nth i info)))
5990           (when (nthcdr (decf i) info)
5991             (setcdr (nthcdr i info) nil)))))))
5992
5993 (defun gnus-set-mode-line (where)
5994   "Set the mode line of the article or summary buffers.
5995 If WHERE is `summary', the summary mode line format will be used."
5996   ;; Is this mode line one we keep updated?
5997   (when (and (memq where gnus-updated-mode-lines)
5998              (symbol-value
5999               (intern (format "gnus-%s-mode-line-format-spec" where))))
6000     (let (mode-string)
6001       ;; We evaluate this in the summary buffer since these
6002       ;; variables are buffer-local to that buffer.
6003       (with-current-buffer gnus-summary-buffer
6004         ;; We bind all these variables that are used in the `eval' form
6005         ;; below.
6006         (let* ((mformat (symbol-value
6007                          (intern
6008                           (format "gnus-%s-mode-line-format-spec" where))))
6009                (gnus-tmp-group-name (gnus-mode-string-quote
6010                                      (gnus-group-decoded-name
6011                                       gnus-newsgroup-name)))
6012                (gnus-tmp-article-number (or gnus-current-article 0))
6013                (gnus-tmp-unread gnus-newsgroup-unreads)
6014                (gnus-tmp-unread-and-unticked (length gnus-newsgroup-unreads))
6015                (gnus-tmp-unselected (length gnus-newsgroup-unselected))
6016                (gnus-tmp-unread-and-unselected
6017                 (cond ((and (zerop gnus-tmp-unread-and-unticked)
6018                             (zerop gnus-tmp-unselected))
6019                        "")
6020                       ((zerop gnus-tmp-unselected)
6021                        (format "{%d more}" gnus-tmp-unread-and-unticked))
6022                       (t (format "{%d(+%d) more}"
6023                                  gnus-tmp-unread-and-unticked
6024                                  gnus-tmp-unselected))))
6025                (gnus-tmp-subject
6026                 (if (and gnus-current-headers
6027                          (vectorp gnus-current-headers))
6028                     (gnus-mode-string-quote
6029                      (mail-header-subject gnus-current-headers))
6030                   ""))
6031                bufname-length max-len
6032                gnus-tmp-header) ;; passed as argument to any user-format-funcs
6033           (setq mode-string (eval mformat))
6034           (setq bufname-length (if (string-match "%b" mode-string)
6035                                    (- (length
6036                                        (buffer-name
6037                                         (if (eq where 'summary)
6038                                             nil
6039                                           (get-buffer gnus-article-buffer))))
6040                                       2)
6041                                  0))
6042           (setq max-len (max 4 (if gnus-mode-non-string-length
6043                                    (- (window-width)
6044                                       gnus-mode-non-string-length
6045                                       bufname-length)
6046                                  (length mode-string))))
6047           ;; We might have to chop a bit of the string off...
6048           (when (> (length mode-string) max-len)
6049             (setq mode-string
6050                   (concat (truncate-string-to-width mode-string (- max-len 3))
6051                           "...")))
6052           ;; Pad the mode string a bit.
6053           (setq mode-string (format (format "%%-%ds" max-len) mode-string))))
6054       ;; Update the mode line.
6055       (setq mode-line-buffer-identification
6056             (gnus-mode-line-buffer-identification (list mode-string)))
6057       (set-buffer-modified-p t))))
6058
6059 (defun gnus-create-xref-hashtb (from-newsgroup headers unreads)
6060   "Go through the HEADERS list and add all Xrefs to a hash table.
6061 The resulting hash table is returned, or nil if no Xrefs were found."
6062   (let* ((virtual (gnus-virtual-group-p from-newsgroup))
6063          (prefix (if virtual "" (gnus-group-real-prefix from-newsgroup)))
6064          (xref-hashtb (gnus-make-hashtable))
6065          start group entry number xrefs header)
6066     (while headers
6067       (setq header (pop headers))
6068       (when (and (setq xrefs (mail-header-xref header))
6069                  (not (memq (setq number (mail-header-number header))
6070                             unreads)))
6071         (setq start 0)
6072         (while (string-match "\\([^ ]+\\)[:/]\\([0-9]+\\)" xrefs start)
6073           (setq start (match-end 0))
6074           (setq group (if prefix
6075                           (concat prefix (substring xrefs (match-beginning 1)
6076                                                     (match-end 1)))
6077                         (substring xrefs (match-beginning 1) (match-end 1))))
6078           (setq number
6079                 (string-to-number (substring xrefs (match-beginning 2)
6080                                           (match-end 2))))
6081           (if (setq entry (gnus-gethash group xref-hashtb))
6082               (setcdr entry (cons number (cdr entry)))
6083             (gnus-sethash group (cons number nil) xref-hashtb)))))
6084     (and start xref-hashtb)))
6085
6086 (defun gnus-mark-xrefs-as-read (from-newsgroup headers unreads)
6087   "Look through all the headers and mark the Xrefs as read."
6088   (let ((virtual (gnus-virtual-group-p from-newsgroup))
6089         name info xref-hashtb idlist method nth4)
6090     (with-current-buffer gnus-group-buffer
6091       (when (setq xref-hashtb
6092                   (gnus-create-xref-hashtb from-newsgroup headers unreads))
6093         (mapatoms
6094          (lambda (group)
6095            (unless (string= from-newsgroup (setq name (symbol-name group)))
6096              (setq idlist (symbol-value group))
6097              ;; Dead groups are not updated.
6098              (and (prog1
6099                       (setq info (gnus-get-info name))
6100                     (when (stringp (setq nth4 (gnus-info-method info)))
6101                       (setq nth4 (gnus-server-to-method nth4))))
6102                   ;; Only do the xrefs if the group has the same
6103                   ;; select method as the group we have just read.
6104                   (or (gnus-methods-equal-p
6105                        nth4 (gnus-find-method-for-group from-newsgroup))
6106                       virtual
6107                       (equal nth4 (setq method (gnus-find-method-for-group
6108                                                 from-newsgroup)))
6109                       (and (equal (car nth4) (car method))
6110                            (equal (nth 1 nth4) (nth 1 method))))
6111                   gnus-use-cross-reference
6112                   (or (not (eq gnus-use-cross-reference t))
6113                       virtual
6114                       ;; Only do cross-references on subscribed
6115                       ;; groups, if that is what is wanted.
6116                       (<= (gnus-info-level info) gnus-level-subscribed))
6117                   (gnus-group-make-articles-read name idlist))))
6118          xref-hashtb)))))
6119
6120 (defun gnus-compute-read-articles (group articles)
6121   (let* ((entry (gnus-group-entry group))
6122          (info (nth 2 entry))
6123          (active (gnus-active group))
6124          ninfo)
6125     (when entry
6126       ;; First peel off all invalid article numbers.
6127       (when active
6128         (let ((ids articles)
6129               id first)
6130           (while (setq id (pop ids))
6131             (when (and first (> id (cdr active)))
6132               ;; We'll end up in this situation in one particular
6133               ;; obscure situation.  If you re-scan a group and get
6134               ;; a new article that is cross-posted to a different
6135               ;; group that has not been re-scanned, you might get
6136               ;; crossposted article that has a higher number than
6137               ;; Gnus believes possible.  So we re-activate this
6138               ;; group as well.  This might mean doing the
6139               ;; crossposting thingy will *increase* the number
6140               ;; of articles in some groups.  Tsk, tsk.
6141               (setq active (or (gnus-activate-group group) active)))
6142             (when (or (> id (cdr active))
6143                       (< id (car active)))
6144               (setq articles (delq id articles))))))
6145       ;; If the read list is nil, we init it.
6146       (if (and active
6147                (null (gnus-info-read info))
6148                (> (car active) 1))
6149           (setq ninfo (cons 1 (1- (car active))))
6150         (setq ninfo (gnus-info-read info)))
6151       ;; Then we add the read articles to the range.
6152       (gnus-add-to-range
6153        ninfo (setq articles (sort articles '<))))))
6154
6155 (defun gnus-group-make-articles-read (group articles)
6156   "Update the info of GROUP to say that ARTICLES are read."
6157   (let* ((num 0)
6158          (entry (gnus-group-entry group))
6159          (info (nth 2 entry))
6160          (active (gnus-active group))
6161          range)
6162     (when entry
6163       (setq range (gnus-compute-read-articles group articles))
6164       (with-current-buffer gnus-group-buffer
6165         (gnus-undo-register
6166           `(progn
6167              (gnus-info-set-marks ',info ',(gnus-info-marks info) t)
6168              (gnus-info-set-read ',info ',(gnus-info-read info))
6169              (gnus-get-unread-articles-in-group ',info (gnus-active ,group))
6170              (gnus-request-set-mark ,group (list (list ',range 'del '(read))))
6171              (gnus-group-update-group ,group t))))
6172       ;; Add the read articles to the range.
6173       (gnus-info-set-read info range)
6174       (gnus-request-set-mark group (list (list range 'add '(read))))
6175       ;; Then we have to re-compute how many unread
6176       ;; articles there are in this group.
6177       (when active
6178         (cond
6179          ((not range)
6180           (setq num (- (1+ (cdr active)) (car active))))
6181          ((not (listp (cdr range)))
6182           (setq num (- (cdr active) (- (1+ (cdr range))
6183                                        (car range)))))
6184          (t
6185           (while range
6186             (if (numberp (car range))
6187                 (setq num (1+ num))
6188               (setq num (+ num (- (1+ (cdar range)) (caar range)))))
6189             (setq range (cdr range)))
6190           (setq num (- (cdr active) num))))
6191         ;; Update the number of unread articles.
6192         (setcar entry num)
6193         ;; Update the group buffer.
6194         (unless (gnus-ephemeral-group-p group)
6195           (gnus-group-update-group group t))))))
6196
6197 (defvar gnus-newsgroup-none-id 0)
6198
6199 (defun gnus-get-newsgroup-headers (&optional dependencies force-new)
6200   (let ((cur nntp-server-buffer)
6201         (dependencies
6202          (or dependencies
6203              (with-current-buffer gnus-summary-buffer
6204                gnus-newsgroup-dependencies)))
6205         headers id end ref number
6206         (mail-parse-charset gnus-newsgroup-charset)
6207         (mail-parse-ignored-charsets
6208          (save-current-buffer (condition-case nil
6209                                   (set-buffer gnus-summary-buffer)
6210                                 (error))
6211                               gnus-newsgroup-ignored-charsets)))
6212     (with-current-buffer nntp-server-buffer
6213       ;; Translate all TAB characters into SPACE characters.
6214       (subst-char-in-region (point-min) (point-max) ?\t ?  t)
6215       (subst-char-in-region (point-min) (point-max) ?\r ?  t)
6216       (ietf-drums-unfold-fws)
6217       (gnus-run-hooks 'gnus-parse-headers-hook)
6218       (let ((case-fold-search t)
6219             in-reply-to header p lines chars)
6220         (goto-char (point-min))
6221         ;; Search to the beginning of the next header.  Error messages
6222         ;; do not begin with 2 or 3.
6223         (while (re-search-forward "^[23][0-9]+ " nil t)
6224           (setq id nil
6225                 ref nil)
6226           ;; This implementation of this function, with nine
6227           ;; search-forwards instead of the one re-search-forward and
6228           ;; a case (which basically was the old function) is actually
6229           ;; about twice as fast, even though it looks messier.  You
6230           ;; can't have everything, I guess.  Speed and elegance
6231           ;; doesn't always go hand in hand.
6232           (setq
6233            header
6234            (vector
6235             ;; Number.
6236             (prog1
6237                 (setq number (read cur))
6238               (end-of-line)
6239               (setq p (point))
6240               (narrow-to-region (point)
6241                                 (or (and (search-forward "\n.\n" nil t)
6242                                          (- (point) 2))
6243                                     (point))))
6244             ;; Subject.
6245             (progn
6246               (goto-char p)
6247               (if (search-forward "\nsubject:" nil t)
6248                   (funcall gnus-decode-encoded-word-function
6249                            (nnheader-header-value))
6250                 "(none)"))
6251             ;; From.
6252             (progn
6253               (goto-char p)
6254               (if (search-forward "\nfrom:" nil t)
6255                   (funcall gnus-decode-encoded-address-function
6256                            (nnheader-header-value))
6257                 "(nobody)"))
6258             ;; Date.
6259             (progn
6260               (goto-char p)
6261               (if (search-forward "\ndate:" nil t)
6262                   (nnheader-header-value) ""))
6263             ;; Message-ID.
6264             (progn
6265               (goto-char p)
6266               (setq id (if (re-search-forward
6267                             "^message-id: *\\(<[^\n\t> ]+>\\)" nil t)
6268                            ;; We do it this way to make sure the Message-ID
6269                            ;; is (somewhat) syntactically valid.
6270                            (buffer-substring (match-beginning 1)
6271                                              (match-end 1))
6272                          ;; If there was no message-id, we just fake one
6273                          ;; to make subsequent routines simpler.
6274                          (nnheader-generate-fake-message-id number))))
6275             ;; References.
6276             (progn
6277               (goto-char p)
6278               (if (search-forward "\nreferences:" nil t)
6279                   (progn
6280                     (setq end (point))
6281                     (prog1
6282                         (nnheader-header-value)
6283                       (setq ref
6284                             (buffer-substring
6285                              (progn
6286                                (end-of-line)
6287                                (search-backward ">" end t)
6288                                (1+ (point)))
6289                              (progn
6290                                (search-backward "<" end t)
6291                                (point))))))
6292                 ;; Get the references from the in-reply-to header if there
6293                 ;; were no references and the in-reply-to header looks
6294                 ;; promising.
6295                 (if (and (search-forward "\nin-reply-to:" nil t)
6296                          (setq in-reply-to (nnheader-header-value))
6297                          (string-match "<[^>]+>" in-reply-to))
6298                     (let (ref2)
6299                       (setq ref (substring in-reply-to (match-beginning 0)
6300                                            (match-end 0)))
6301                       (while (string-match "<[^>]+>" in-reply-to (match-end 0))
6302                         (setq ref2 (substring in-reply-to (match-beginning 0)
6303                                               (match-end 0)))
6304                         (when (> (length ref2) (length ref))
6305                           (setq ref ref2)))
6306                       ref)
6307                   (setq ref nil))))
6308             ;; Chars.
6309             (progn
6310               (goto-char p)
6311               (if