1 ;;; gnus-dup.el --- suppression of duplicate articles in Gnus
2 ;; Copyright (C) 1996 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
37 (defgroup gnus-duplicate nil
38 "Suppression of duplicate articles."
41 (defcustom gnus-save-duplicate-list nil
42 "*If non-nil, save the duplicate list when shutting down Gnus.
43 If nil, duplicate suppression will only work on duplicates
44 seen in the same session."
45 :group 'gnus-duplicate
48 (defcustom gnus-duplicate-list-length 10000
49 "*The number of Message-IDs to keep in the duplicate suppression list."
50 :group 'gnus-duplicate
53 (defcustom gnus-duplicate-file (nnheader-concat gnus-directory "suppression")
54 "*The name of the file to store the duplicate suppression list."
55 :group 'gnus-duplicate
58 ;;; Internal variables
60 (defvar gnus-dup-list nil)
61 (defvar gnus-dup-hashtb nil)
63 (defvar gnus-dup-list-dirty nil)
66 ;;; Starting and stopping
69 (gnus-add-shutdown 'gnus-dup-close 'gnus)
71 (defun gnus-dup-close ()
72 "Possibly save the duplicate suppression list and shut down the subsystem."
74 (setq gnus-dup-list nil
76 gnus-dup-list-dirty nil))
78 (defun gnus-dup-open ()
79 "Possibly read the duplicate suppression list and start the subsystem."
80 (if gnus-save-duplicate-list
82 (setq gnus-dup-list nil))
83 (setq gnus-dup-hashtb (gnus-make-hashtable gnus-duplicate-list-length))
84 ;; Enter all Message-IDs into the hash table.
85 (let ((list gnus-dup-list)
86 (obarray gnus-dup-hashtb))
88 (intern (pop list)))))
90 (defun gnus-dup-read ()
91 "Read the duplicate suppression list."
92 (setq gnus-dup-list nil)
93 (when (file-exists-p gnus-duplicate-file)
94 (load gnus-duplicate-file t t t)))
96 (defun gnus-dup-save ()
97 "Save the duplicate suppression list."
98 (when (and gnus-save-duplicate-list
100 (nnheader-temp-write gnus-duplicate-file
101 (gnus-prin1 `(setq gnus-dup-list ',gnus-dup-list))))
102 (setq gnus-dup-list-dirty nil))
105 ;;; Interface functions
108 (defun gnus-dup-enter-articles ()
109 "Enter articles from the current group for future duplicate suppression."
110 (unless gnus-dup-list
112 (setq gnus-dup-list-dirty t) ; mark list for saving
113 (let ((data gnus-newsgroup-data)
115 ;; Enter the Message-IDs of all read articles into the list
117 (while (setq datum (pop data))
118 (when (and (not (gnus-data-pseudo-p datum))
119 (gnus-data-read-p datum)
120 (not (intern-soft (mail-header-id (gnus-data-header datum))
122 (intern (car (push (mail-header-id (gnus-data-header datum))
125 ;; Chop off excess Message-IDs from the list.
126 (let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list)))
130 (defun gnus-dup-suppress-articles ()
131 "Mark duplicate articles as read."
132 (unless gnus-dup-list
134 (gnus-message 6 "Suppressing duplicates...")
135 (let ((headers gnus-newsgroup-headers)
137 (while (setq header (pop headers))
138 (when (intern-soft (mail-header-id header) gnus-dup-hashtb)
139 (setq gnus-newsgroup-unreads
140 (delq (setq number (mail-header-number header))
141 gnus-newsgroup-unreads))
142 (push (cons number gnus-duplicate-mark)
143 gnus-newsgroup-reads))))
144 (gnus-message 6 "Suppressing duplicates...done"))
146 (defun gnus-dup-unsuppress-article (article)
147 "Stop suppression of ARTICLE."
148 (let ((id (mail-header-id (gnus-data-header (gnus-data-find article)))))
150 (setq gnus-dup-list-dirty t)
151 (setq gnus-dup-list (delete id gnus-dup-list))
152 (unintern id gnus-dup-hashtb))))
156 ;;; gnus-dup.el ends here