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 (defvar gnus-save-duplicate-list nil
38 "*If non-nil, save the duplicate list when shutting down Gnus.
39 If nil, duplicate suppression will only work on duplicates
40 seen in the same session.")
42 (defvar gnus-duplicate-list-length 10000
43 "*The number of Message-IDs to keep in the duplicate suppression list.")
45 (defvar gnus-duplicate-file (nnheader-concat gnus-directory "suppression")
46 "*The name of the file to store the duplicate suppression list.")
48 ;;; Internal variables
50 (defvar gnus-dup-list nil)
51 (defvar gnus-dup-hashtb nil)
53 (defvar gnus-dup-list-dirty nil)
56 ;;; Starting and stopping
59 (gnus-add-shutdown 'gnus-dup-close 'gnus)
61 (defun gnus-dup-close ()
62 "Possibly save the duplicate suppression list and shut down the subsystem."
64 (setq gnus-dup-list nil
66 gnus-dup-list-dirty nil))
68 (defun gnus-dup-open ()
69 "Possibly read the duplicate suppression list and start the subsystem."
70 (if gnus-save-duplicate-list
72 (setq gnus-dup-list nil))
73 (setq gnus-dup-hashtb (gnus-make-hashtable gnus-duplicate-list-length))
74 ;; Enter all Message-IDs into the hash table.
75 (let ((list gnus-dup-list)
76 (obarray gnus-dup-hashtb))
78 (intern (pop list)))))
80 (defun gnus-dup-read ()
81 "Read the duplicate suppression list."
82 (setq gnus-dup-list nil)
83 (when (file-exists-p gnus-duplicate-file)
84 (load gnus-duplicate-file t t t)))
86 (defun gnus-dup-save ()
87 "Save the duplicate suppression list."
88 (when (and gnus-save-duplicate-list
90 (nnheader-temp-write gnus-duplicate-file
91 (gnus-prin1 `(setq gnus-dup-list ',gnus-dup-list))))
92 (setq gnus-dup-list-dirty nil))
95 ;;; Interface functions
98 (defun gnus-dup-enter-articles ()
99 "Enter articles from the current group for future duplicate suppression."
100 (unless gnus-dup-list
102 (setq gnus-dup-list-dirty t) ; mark list for saving
103 (let ((data gnus-newsgroup-data)
105 ;; Enter the Message-IDs of all read articles into the list
107 (while (setq datum (pop data))
108 (when (and (not (gnus-data-pseudo-p datum))
109 (gnus-data-read-p datum)
110 (not (intern-soft (mail-header-id (gnus-data-header datum))
112 (intern (car (push (mail-header-id (gnus-data-header datum))
115 ;; Chop off excess Message-IDs from the list.
116 (let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list)))
120 (defun gnus-dup-suppress-articles ()
121 "Mark duplicate articles as read."
122 (unless gnus-dup-list
124 (gnus-message 6 "Suppressing duplicates...")
125 (let ((headers gnus-newsgroup-headers)
127 (while (setq header (pop headers))
128 (when (intern-soft (mail-header-id header) gnus-dup-hashtb)
129 (setq gnus-newsgroup-unreads
130 (delq (setq number (mail-header-number header))
131 gnus-newsgroup-unreads))
132 (push (cons number gnus-duplicate-mark)
133 gnus-newsgroup-reads))))
134 (gnus-message 6 "Suppressing duplicates...done"))
136 (defun gnus-dup-unsuppress-article (article)
137 "Stop suppression of ARTICLE."
138 (let ((id (mail-header-id (gnus-data-header (gnus-data-find article)))))
140 (setq gnus-dup-list-dirty t)
141 (setq gnus-dup-list (delete id gnus-dup-list))
142 (unintern id gnus-dup-hashtb))))
146 ;;; gnus-dup.el ends here