Mercurial > emacs
annotate lisp/gnus/gnus-dup.el @ 45528:bc8cc9c5d979
*** empty log message ***
author | Colin Walters <walters@gnu.org> |
---|---|
date | Sun, 26 May 2002 20:42:31 +0000 |
parents | 9968f55ad26e |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
17493 | 1 ;;; gnus-dup.el --- suppression of duplicate articles in Gnus |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
3 ;; Free Software Foundation, Inc. |
17493 | 4 |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
17493 | 6 ;; Keywords: news |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; This package tries to mark articles as read the second time the | |
28 ;; user reads a copy. This is useful if the server doesn't support | |
29 ;; Xref properly, or if the user reads the same group from several | |
30 ;; servers. | |
31 | |
32 ;;; Code: | |
33 | |
19493
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
34 (eval-when-compile (require 'cl)) |
8d840c4548c0
Require cl at compile time.
Richard M. Stallman <rms@gnu.org>
parents:
17493
diff
changeset
|
35 |
17493 | 36 (require 'gnus) |
37 (require 'gnus-art) | |
38 | |
39 (defgroup gnus-duplicate nil | |
40 "Suppression of duplicate articles." | |
41 :group 'gnus) | |
42 | |
43 (defcustom gnus-save-duplicate-list nil | |
44 "*If non-nil, save the duplicate list when shutting down Gnus. | |
45 If nil, duplicate suppression will only work on duplicates | |
46 seen in the same session." | |
47 :group 'gnus-duplicate | |
48 :type 'boolean) | |
49 | |
50 (defcustom gnus-duplicate-list-length 10000 | |
51 "*The number of Message-IDs to keep in the duplicate suppression list." | |
52 :group 'gnus-duplicate | |
53 :type 'integer) | |
54 | |
55 (defcustom gnus-duplicate-file (nnheader-concat gnus-directory "suppression") | |
56 "*The name of the file to store the duplicate suppression list." | |
57 :group 'gnus-duplicate | |
58 :type 'file) | |
59 | |
60 ;;; Internal variables | |
61 | |
62 (defvar gnus-dup-list nil) | |
63 (defvar gnus-dup-hashtb nil) | |
64 | |
65 (defvar gnus-dup-list-dirty nil) | |
66 | |
67 ;;; | |
68 ;;; Starting and stopping | |
69 ;;; | |
70 | |
71 (gnus-add-shutdown 'gnus-dup-close 'gnus) | |
72 | |
73 (defun gnus-dup-close () | |
74 "Possibly save the duplicate suppression list and shut down the subsystem." | |
75 (gnus-dup-save) | |
76 (setq gnus-dup-list nil | |
77 gnus-dup-hashtb nil | |
78 gnus-dup-list-dirty nil)) | |
79 | |
80 (defun gnus-dup-open () | |
81 "Possibly read the duplicate suppression list and start the subsystem." | |
82 (if gnus-save-duplicate-list | |
83 (gnus-dup-read) | |
84 (setq gnus-dup-list nil)) | |
85 (setq gnus-dup-hashtb (gnus-make-hashtable gnus-duplicate-list-length)) | |
86 ;; Enter all Message-IDs into the hash table. | |
87 (let ((list gnus-dup-list) | |
88 (obarray gnus-dup-hashtb)) | |
89 (while list | |
90 (intern (pop list))))) | |
91 | |
92 (defun gnus-dup-read () | |
93 "Read the duplicate suppression list." | |
94 (setq gnus-dup-list nil) | |
95 (when (file-exists-p gnus-duplicate-file) | |
96 (load gnus-duplicate-file t t t))) | |
97 | |
98 (defun gnus-dup-save () | |
99 "Save the duplicate suppression list." | |
100 (when (and gnus-save-duplicate-list | |
101 gnus-dup-list-dirty) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
102 (with-temp-file gnus-duplicate-file |
17493 | 103 (gnus-prin1 `(setq gnus-dup-list ',gnus-dup-list)))) |
104 (setq gnus-dup-list-dirty nil)) | |
105 | |
106 ;;; | |
107 ;;; Interface functions | |
108 ;;; | |
109 | |
110 (defun gnus-dup-enter-articles () | |
111 "Enter articles from the current group for future duplicate suppression." | |
112 (unless gnus-dup-list | |
113 (gnus-dup-open)) | |
114 (setq gnus-dup-list-dirty t) ; mark list for saving | |
115 (let ((data gnus-newsgroup-data) | |
116 datum msgid) | |
117 ;; Enter the Message-IDs of all read articles into the list | |
118 ;; and hash table. | |
119 (while (setq datum (pop data)) | |
120 (when (and (not (gnus-data-pseudo-p datum)) | |
121 (> (gnus-data-number datum) 0) | |
24357
15fc6acbae7a
Upgrading to Gnus 5.7; see ChangeLog
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19493
diff
changeset
|
122 (not (memq (gnus-data-number datum) gnus-newsgroup-unreads)) |
17493 | 123 (not (= (gnus-data-mark datum) gnus-canceled-mark)) |
124 (setq msgid (mail-header-id (gnus-data-header datum))) | |
125 (not (nnheader-fake-message-id-p msgid)) | |
126 (not (intern-soft msgid gnus-dup-hashtb))) | |
127 (push msgid gnus-dup-list) | |
128 (intern msgid gnus-dup-hashtb)))) | |
129 ;; Chop off excess Message-IDs from the list. | |
130 (let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list))) | |
131 (when end | |
132 (setcdr end nil)))) | |
133 | |
134 (defun gnus-dup-suppress-articles () | |
135 "Mark duplicate articles as read." | |
136 (unless gnus-dup-list | |
137 (gnus-dup-open)) | |
138 (gnus-message 6 "Suppressing duplicates...") | |
139 (let ((headers gnus-newsgroup-headers) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
140 (auto (and gnus-newsgroup-auto-expire |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
141 (memq gnus-duplicate-mark gnus-auto-expirable-marks))) |
17493 | 142 number header) |
143 (while (setq header (pop headers)) | |
144 (when (and (intern-soft (mail-header-id header) gnus-dup-hashtb) | |
145 (gnus-summary-article-unread-p (mail-header-number header))) | |
146 (setq gnus-newsgroup-unreads | |
147 (delq (setq number (mail-header-number header)) | |
148 gnus-newsgroup-unreads)) | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
149 (if (not auto) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
150 (push (cons number gnus-duplicate-mark) gnus-newsgroup-reads) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
151 (push number gnus-newsgroup-expirable) |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24357
diff
changeset
|
152 (push (cons number gnus-expirable-mark) gnus-newsgroup-reads))))) |
17493 | 153 (gnus-message 6 "Suppressing duplicates...done")) |
154 | |
155 (defun gnus-dup-unsuppress-article (article) | |
156 "Stop suppression of ARTICLE." | |
157 (let ((id (mail-header-id (gnus-data-header (gnus-data-find article))))) | |
158 (when id | |
159 (setq gnus-dup-list-dirty t) | |
160 (setq gnus-dup-list (delete id gnus-dup-list)) | |
161 (unintern id gnus-dup-hashtb)))) | |
162 | |
163 (provide 'gnus-dup) | |
164 | |
165 ;;; gnus-dup.el ends here |