emacs/lisp/gnus/gnus-dup.el

162 lines
5.1 KiB
EmacsLisp
Raw Normal View History

1997-04-16 22:13:18 +00:00
;;; gnus-dup.el --- suppression of duplicate articles in Gnus
2005-08-06 19:51:42 +00:00
;; Copyright (C) 1996-2018 Free Software Foundation, Inc.
1997-04-16 22:13:18 +00:00
1999-02-20 14:05:57 +00:00
;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
1997-04-16 22:13:18 +00:00
;; Keywords: news
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
1997-04-16 22:13:18 +00:00
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
1997-04-16 22:13:18 +00:00
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1997-04-16 22:13:18 +00:00
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
1997-04-16 22:13:18 +00:00
;;; Commentary:
;; This package tries to mark articles as read the second time the
;; user reads a copy. This is useful if the server doesn't support
;; Xref properly, or if the user reads the same group from several
;; servers.
;;; Code:
1997-08-23 20:23:37 +00:00
(eval-when-compile (require 'cl))
1997-04-16 22:13:18 +00:00
(require 'gnus)
(require 'gnus-art)
(defgroup gnus-duplicate nil
"Suppression of duplicate articles."
:group 'gnus)
(defcustom gnus-save-duplicate-list nil
Remove obsolete leading * from defcustom, defface doc strings. * lisp/cedet/ede/linux.el, lisp/cedet/ede/project-am.el: * lisp/cedet/ede/simple.el, lisp/cedet/semantic/bovine/c.el: * lisp/cedet/semantic/complete.el, lisp/cedet/semantic/db.el: * lisp/cedet/semantic/decorate/include.el: * lisp/cedet/semantic/decorate/mode.el, lisp/cedet/semantic/format.el: * lisp/cedet/semantic/ia.el, lisp/cedet/semantic/idle.el: * lisp/cedet/semantic/imenu.el, lisp/cedet/semantic/lex-spp.el: * lisp/cedet/semantic/mru-bookmark.el, lisp/cedet/semantic/sb.el: * lisp/cedet/srecode/fields.el, lisp/ecomplete.el: * lisp/gnus/gnus-agent.el, lisp/gnus/gnus-art.el: * lisp/gnus/gnus-async.el, lisp/gnus/gnus-cache.el: * lisp/gnus/gnus-cite.el, lisp/gnus/gnus-delay.el: * lisp/gnus/gnus-diary.el, lisp/gnus/gnus-dup.el: * lisp/gnus/gnus-fun.el, lisp/gnus/gnus-group.el: * lisp/gnus/gnus-kill.el, lisp/gnus/gnus-msg.el: * lisp/gnus/gnus-picon.el, lisp/gnus/gnus-salt.el: * lisp/gnus/gnus-score.el, lisp/gnus/gnus-start.el: * lisp/gnus/gnus-sum.el, lisp/gnus/gnus-topic.el: * lisp/gnus/gnus-util.el, lisp/gnus/gnus-uu.el, lisp/gnus/gnus-win.el: * lisp/gnus/gnus.el, lisp/gnus/mail-source.el, lisp/gnus/message.el: * lisp/gnus/mm-url.el, lisp/gnus/mm-uu.el, lisp/gnus/mml.el: * lisp/gnus/nndiary.el, lisp/gnus/nnir.el, lisp/gnus/nnmail.el: * lisp/gnus/smiley.el, lisp/gnus/smime.el, lisp/mail/mail-extr.el: * lisp/mh-e/mh-e.el, lisp/net/mailcap.el, lisp/net/pop3.el: * lisp/net/starttls.el, lisp/progmodes/cc-vars.el: * lisp/progmodes/cperl-mode.el, test/manual/cedet/tests/test.el: Remove obsolete leading * from defcustom, defface doc strings.
2016-06-09 20:13:12 -04:00
"If non-nil, save the duplicate list when shutting down Gnus.
1997-04-16 22:13:18 +00:00
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
Remove obsolete leading * from defcustom, defface doc strings. * lisp/cedet/ede/linux.el, lisp/cedet/ede/project-am.el: * lisp/cedet/ede/simple.el, lisp/cedet/semantic/bovine/c.el: * lisp/cedet/semantic/complete.el, lisp/cedet/semantic/db.el: * lisp/cedet/semantic/decorate/include.el: * lisp/cedet/semantic/decorate/mode.el, lisp/cedet/semantic/format.el: * lisp/cedet/semantic/ia.el, lisp/cedet/semantic/idle.el: * lisp/cedet/semantic/imenu.el, lisp/cedet/semantic/lex-spp.el: * lisp/cedet/semantic/mru-bookmark.el, lisp/cedet/semantic/sb.el: * lisp/cedet/srecode/fields.el, lisp/ecomplete.el: * lisp/gnus/gnus-agent.el, lisp/gnus/gnus-art.el: * lisp/gnus/gnus-async.el, lisp/gnus/gnus-cache.el: * lisp/gnus/gnus-cite.el, lisp/gnus/gnus-delay.el: * lisp/gnus/gnus-diary.el, lisp/gnus/gnus-dup.el: * lisp/gnus/gnus-fun.el, lisp/gnus/gnus-group.el: * lisp/gnus/gnus-kill.el, lisp/gnus/gnus-msg.el: * lisp/gnus/gnus-picon.el, lisp/gnus/gnus-salt.el: * lisp/gnus/gnus-score.el, lisp/gnus/gnus-start.el: * lisp/gnus/gnus-sum.el, lisp/gnus/gnus-topic.el: * lisp/gnus/gnus-util.el, lisp/gnus/gnus-uu.el, lisp/gnus/gnus-win.el: * lisp/gnus/gnus.el, lisp/gnus/mail-source.el, lisp/gnus/message.el: * lisp/gnus/mm-url.el, lisp/gnus/mm-uu.el, lisp/gnus/mml.el: * lisp/gnus/nndiary.el, lisp/gnus/nnir.el, lisp/gnus/nnmail.el: * lisp/gnus/smiley.el, lisp/gnus/smime.el, lisp/mail/mail-extr.el: * lisp/mh-e/mh-e.el, lisp/net/mailcap.el, lisp/net/pop3.el: * lisp/net/starttls.el, lisp/progmodes/cc-vars.el: * lisp/progmodes/cperl-mode.el, test/manual/cedet/tests/test.el: Remove obsolete leading * from defcustom, defface doc strings.
2016-06-09 20:13:12 -04:00
"The number of Message-IDs to keep in the duplicate suppression list."
1997-04-16 22:13:18 +00:00
:group 'gnus-duplicate
:type 'integer)
(defcustom gnus-duplicate-file (nnheader-concat gnus-directory "suppression")
Remove obsolete leading * from defcustom, defface doc strings. * lisp/cedet/ede/linux.el, lisp/cedet/ede/project-am.el: * lisp/cedet/ede/simple.el, lisp/cedet/semantic/bovine/c.el: * lisp/cedet/semantic/complete.el, lisp/cedet/semantic/db.el: * lisp/cedet/semantic/decorate/include.el: * lisp/cedet/semantic/decorate/mode.el, lisp/cedet/semantic/format.el: * lisp/cedet/semantic/ia.el, lisp/cedet/semantic/idle.el: * lisp/cedet/semantic/imenu.el, lisp/cedet/semantic/lex-spp.el: * lisp/cedet/semantic/mru-bookmark.el, lisp/cedet/semantic/sb.el: * lisp/cedet/srecode/fields.el, lisp/ecomplete.el: * lisp/gnus/gnus-agent.el, lisp/gnus/gnus-art.el: * lisp/gnus/gnus-async.el, lisp/gnus/gnus-cache.el: * lisp/gnus/gnus-cite.el, lisp/gnus/gnus-delay.el: * lisp/gnus/gnus-diary.el, lisp/gnus/gnus-dup.el: * lisp/gnus/gnus-fun.el, lisp/gnus/gnus-group.el: * lisp/gnus/gnus-kill.el, lisp/gnus/gnus-msg.el: * lisp/gnus/gnus-picon.el, lisp/gnus/gnus-salt.el: * lisp/gnus/gnus-score.el, lisp/gnus/gnus-start.el: * lisp/gnus/gnus-sum.el, lisp/gnus/gnus-topic.el: * lisp/gnus/gnus-util.el, lisp/gnus/gnus-uu.el, lisp/gnus/gnus-win.el: * lisp/gnus/gnus.el, lisp/gnus/mail-source.el, lisp/gnus/message.el: * lisp/gnus/mm-url.el, lisp/gnus/mm-uu.el, lisp/gnus/mml.el: * lisp/gnus/nndiary.el, lisp/gnus/nnir.el, lisp/gnus/nnmail.el: * lisp/gnus/smiley.el, lisp/gnus/smime.el, lisp/mail/mail-extr.el: * lisp/mh-e/mh-e.el, lisp/net/mailcap.el, lisp/net/pop3.el: * lisp/net/starttls.el, lisp/progmodes/cc-vars.el: * lisp/progmodes/cperl-mode.el, test/manual/cedet/tests/test.el: Remove obsolete leading * from defcustom, defface doc strings.
2016-06-09 20:13:12 -04:00
"The name of the file to store the duplicate suppression list."
1997-04-16 22:13:18 +00:00
:group 'gnus-duplicate
:type 'file)
;;; Internal variables
(defvar gnus-dup-list nil)
(defvar gnus-dup-hashtb nil)
(defvar gnus-dup-list-dirty nil)
;;;
;;; Starting and stopping
;;;
(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))
;; Enter all Message-IDs into the hash table.
(let ((obarray gnus-dup-hashtb))
(mapc 'intern gnus-dup-list)))
1997-04-16 22:13:18 +00:00
(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
1997-04-16 22:13:18 +00:00
(gnus-prin1 `(setq gnus-dup-list ',gnus-dup-list))))
(setq gnus-dup-list-dirty nil))
;;;
;;; Interface functions
;;;
(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) ; mark list for saving
(let (msgid)
1997-04-16 22:13:18 +00:00
;; Enter the Message-IDs of all read articles into the list
;; and hash table.
(dolist (datum gnus-newsgroup-data)
1997-04-16 22:13:18 +00:00
(when (and (not (gnus-data-pseudo-p datum))
(> (gnus-data-number datum) 0)
1999-02-20 14:05:57 +00:00
(not (memq (gnus-data-number datum) gnus-newsgroup-unreads))
1997-04-16 22:13:18 +00:00
(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)))
1997-04-16 22:13:18 +00:00
(push msgid gnus-dup-list)
(intern msgid gnus-dup-hashtb))))
1997-04-16 22:13:18 +00:00
;; Chop off excess Message-IDs from the list.
(let ((end (nthcdr gnus-duplicate-list-length gnus-dup-list)))
(when end
(mapc (lambda (id) (unintern id gnus-dup-hashtb)) (cdr end))
1997-04-16 22:13:18 +00:00
(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)
1997-04-16 22:13:18 +00:00
(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"))
1997-04-16 22:13:18 +00:00
(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))))
1997-04-16 22:13:18 +00:00
(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)
;;; gnus-dup.el ends here