1 ;;; gnus-dup.el --- suppression of duplicate articles in Gnus
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This package tries to mark articles as read the second time the
27 ;; user reads a copy. This is useful if the server doesn't support
28 ;; Xref properly, or if the user reads the same group from several
36 (defgroup gnus-duplicate nil
37 "Suppression of duplicate articles."
40 (defcustom gnus-save-duplicate-list nil
41 "*If non-nil, save the duplicate list when shutting down Gnus.
42 If nil, duplicate suppression will only work on duplicates
43 seen in the same session."
44 :group
'gnus-duplicate
47 (defcustom gnus-duplicate-list-length
10000
48 "*The number of Message-IDs to keep in the duplicate suppression list."
49 :group
'gnus-duplicate
52 (defcustom gnus-duplicate-file
(nnheader-concat gnus-directory
"suppression")
53 "*The name of the file to store the duplicate suppression list."
54 :group
'gnus-duplicate
57 ;;; Internal variables
59 (defvar gnus-dup-list nil
)
60 (defvar gnus-dup-hashtb nil
)
62 (defvar gnus-dup-list-dirty nil
)
65 ;;; Starting and stopping
68 (gnus-add-shutdown 'gnus-dup-close
'gnus
)
70 (defun gnus-dup-close ()
71 "Possibly save the duplicate suppression list and shut down the subsystem."
73 (setq gnus-dup-list nil
75 gnus-dup-list-dirty nil
))
77 (defun gnus-dup-open ()
78 "Possibly read the duplicate suppression list and start the subsystem."
79 (if gnus-save-duplicate-list
81 (setq gnus-dup-list nil
))
82 (setq gnus-dup-hashtb
(gnus-make-hashtable gnus-duplicate-list-length
))
83 ;; Enter all Message-IDs into the hash table.
84 (let ((list gnus-dup-list
)
85 (obarray gnus-dup-hashtb
))
87 (intern (pop list
)))))
89 (defun gnus-dup-read ()
90 "Read the duplicate suppression list."
91 (setq gnus-dup-list nil
)
92 (when (file-exists-p gnus-duplicate-file
)
93 (load gnus-duplicate-file t t t
)))
95 (defun gnus-dup-save ()
96 "Save the duplicate suppression list."
97 (when (and gnus-save-duplicate-list
99 (nnheader-temp-write gnus-duplicate-file
100 (gnus-prin1 `(setq gnus-dup-list
',gnus-dup-list
))))
101 (setq gnus-dup-list-dirty nil
))
104 ;;; Interface functions
107 (defun gnus-dup-enter-articles ()
108 "Enter articles from the current group for future duplicate suppression."
109 (unless gnus-dup-list
111 (setq gnus-dup-list-dirty t
) ; mark list for saving
112 (let ((data gnus-newsgroup-data
)
114 ;; Enter the Message-IDs of all read articles into the list
116 (while (setq datum
(pop data
))
117 (when (and (not (gnus-data-pseudo-p datum
))
118 (> (gnus-data-number datum
) 0)
119 (gnus-data-read-p datum
)
120 (not (= (gnus-data-mark datum
) gnus-canceled-mark
))
121 (setq msgid
(mail-header-id (gnus-data-header datum
)))
122 (not (nnheader-fake-message-id-p msgid
))
123 (not (intern-soft msgid gnus-dup-hashtb
)))
124 (push msgid gnus-dup-list
)
125 (intern msgid gnus-dup-hashtb
))))
126 ;; Chop off excess Message-IDs from the list.
127 (let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list
)))
131 (defun gnus-dup-suppress-articles ()
132 "Mark duplicate articles as read."
133 (unless gnus-dup-list
135 (gnus-message 6 "Suppressing duplicates...")
136 (let ((headers gnus-newsgroup-headers
)
138 (while (setq header
(pop headers
))
139 (when (and (intern-soft (mail-header-id header
) gnus-dup-hashtb
)
140 (gnus-summary-article-unread-p (mail-header-number header
)))
141 (setq gnus-newsgroup-unreads
142 (delq (setq number
(mail-header-number header
))
143 gnus-newsgroup-unreads
))
144 (push (cons number gnus-duplicate-mark
)
145 gnus-newsgroup-reads
))))
146 (gnus-message 6 "Suppressing duplicates...done"))
148 (defun gnus-dup-unsuppress-article (article)
149 "Stop suppression of ARTICLE."
150 (let ((id (mail-header-id (gnus-data-header (gnus-data-find article
)))))
152 (setq gnus-dup-list-dirty t
)
153 (setq gnus-dup-list
(delete id gnus-dup-list
))
154 (unintern id gnus-dup-hashtb
))))
158 ;;; gnus-dup.el ends here