123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- (eval-when-compile (require 'cl))
- (require 'gnus)
- (require 'gnus-art)
- (defgroup gnus-duplicate nil
- "Suppression of duplicate articles."
- :group 'gnus)
- (defcustom gnus-save-duplicate-list nil
- "*If non-nil, save the duplicate list when shutting down Gnus.
- If nil, duplicate suppression will only work on duplicates
- seen in the same session."
- :group 'gnus-duplicate
- :type 'boolean)
- (defcustom gnus-duplicate-list-length 10000
- "*The number of Message-IDs to keep in the duplicate suppression list."
- :group 'gnus-duplicate
- :type 'integer)
- (defcustom gnus-duplicate-file (nnheader-concat gnus-directory "suppression")
- "*The name of the file to store the duplicate suppression list."
- :group 'gnus-duplicate
- :type 'file)
- (defvar gnus-dup-list nil)
- (defvar gnus-dup-hashtb nil)
- (defvar gnus-dup-list-dirty nil)
- (gnus-add-shutdown 'gnus-dup-close 'gnus)
- (defun gnus-dup-close ()
- "Possibly save the duplicate suppression list and shut down the subsystem."
- (gnus-dup-save)
- (setq gnus-dup-list nil
- gnus-dup-hashtb nil
- gnus-dup-list-dirty nil))
- (defun gnus-dup-open ()
- "Possibly read the duplicate suppression list and start the subsystem."
- (if gnus-save-duplicate-list
- (gnus-dup-read)
- (setq gnus-dup-list nil))
- (setq gnus-dup-hashtb (gnus-make-hashtable gnus-duplicate-list-length))
-
- (let ((obarray gnus-dup-hashtb))
- (mapc 'intern gnus-dup-list)))
- (defun gnus-dup-read ()
- "Read the duplicate suppression list."
- (setq gnus-dup-list nil)
- (when (file-exists-p gnus-duplicate-file)
- (load gnus-duplicate-file t t t)))
- (defun gnus-dup-save ()
- "Save the duplicate suppression list."
- (when (and gnus-save-duplicate-list
- gnus-dup-list-dirty)
- (with-temp-file gnus-duplicate-file
- (gnus-prin1 `(setq gnus-dup-list ',gnus-dup-list))))
- (setq gnus-dup-list-dirty nil))
- (defun gnus-dup-enter-articles ()
- "Enter articles from the current group for future duplicate suppression."
- (unless gnus-dup-list
- (gnus-dup-open))
- (setq gnus-dup-list-dirty t)
- (let (msgid)
-
-
- (dolist (datum gnus-newsgroup-data)
- (when (and (not (gnus-data-pseudo-p datum))
- (> (gnus-data-number datum) 0)
- (not (memq (gnus-data-number datum) gnus-newsgroup-unreads))
- (not (= (gnus-data-mark datum) gnus-canceled-mark))
- (setq msgid (mail-header-id (gnus-data-header datum)))
- (not (nnheader-fake-message-id-p msgid))
- (not (intern-soft msgid gnus-dup-hashtb)))
- (push msgid gnus-dup-list)
- (intern msgid gnus-dup-hashtb))))
-
- (let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list)))
- (when end
- (mapc (lambda (id) (unintern id gnus-dup-hashtb)) (cdr end))
- (setcdr end nil))))
- (defun gnus-dup-suppress-articles ()
- "Mark duplicate articles as read."
- (unless gnus-dup-list
- (gnus-dup-open))
- (gnus-message 8 "Suppressing duplicates...")
- (let ((auto (and gnus-newsgroup-auto-expire
- (memq gnus-duplicate-mark gnus-auto-expirable-marks)))
- number)
- (dolist (header gnus-newsgroup-headers)
- (when (and (intern-soft (mail-header-id header) gnus-dup-hashtb)
- (gnus-summary-article-unread-p (mail-header-number header)))
- (setq gnus-newsgroup-unreads
- (delq (setq number (mail-header-number header))
- gnus-newsgroup-unreads))
- (if (not auto)
- (push (cons number gnus-duplicate-mark) gnus-newsgroup-reads)
- (push number gnus-newsgroup-expirable)
- (push (cons number gnus-expirable-mark) gnus-newsgroup-reads)))))
- (gnus-message 8 "Suppressing duplicates...done"))
- (defun gnus-dup-unsuppress-article (article)
- "Stop suppression of ARTICLE."
- (let* ((header (gnus-data-header (gnus-data-find article)))
- (id (when header (mail-header-id header))))
- (when id
- (setq gnus-dup-list-dirty t)
- (setq gnus-dup-list (delete id gnus-dup-list))
- (unintern id gnus-dup-hashtb))))
- (provide 'gnus-dup)
|