1 ;;; gnus-registry.el --- article registry for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;; Free Software Foundation, Inc.
5 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
36 (defvar gnus-registry-hashtb nil
37 "*The article registry by Message ID.")
38 (setq gnus-registry-hashtb (make-hash-table
40 :test 'equal)) ; we test message ID strings equality
43 ;; (defvar tzz-header '(49 "Re[2]: good news" "\"Jonathan Pryor\" <offerlm@aol.com>" "Mon, 17 Feb 2003 10:41:46 +-0800" "<88288020@dytqq>" "" 896 18 "lockgroove.bwh.harvard.edu spam.asian:49" nil))
45 ;; (maphash (lambda (key value) (message "key: %s value: %s" key value)) gnus-registry-hashtb)
46 ;; (clrhash gnus-registry-hashtb)
48 ;; Function(s) missing in Emacs 20
49 (when (memq nil (mapcar 'fboundp '(puthash)))
51 (unless (fboundp 'puthash)
52 ;; alias puthash is missing from Emacs 20 cl-extra.el
53 (defalias 'puthash 'cl-puthash)))
55 (defun gnus-registry-translate-to-alist ()
56 (setq gnus-registry-alist (hashtable-to-alist gnus-registry-hashtb)))
58 (defun gnus-registry-translate-from-alist ()
59 (setq gnus-registry-hashtb (alist-to-hashtable gnus-registry-alist)))
61 (defun alist-to-hashtable (alist)
62 "Build a hashtable from the values in ALIST."
63 (let ((ht (make-hash-table
68 (puthash (car kv-pair) (cdr kv-pair) ht))
72 (defun hashtable-to-alist (hash)
73 "Build an alist from the values in HASH."
77 (setq list (cons (cons key value) list)))
80 (defun gnus-register-action (action data-header from &optional to method)
81 (let* ((id (mail-header-id data-header))
82 (hash-entry (gethash id gnus-registry-hashtb)))
83 (gnus-message 5 "Registry: article %s %s from %s to %s"
85 (if method "respooling" "going")
86 (gnus-group-guess-full-name from)
87 (if to (gnus-group-guess-full-name to) "the Bit Bucket"))
89 (setq hash-entry (puthash id (list data-header) gnus-registry-hashtb)))
90 (puthash id (cons (list action from to method)
91 (gethash id gnus-registry-hashtb)) gnus-registry-hashtb)))
93 (defun gnus-register-spool-action (id group)
94 (gnus-message 5 "Registry: article %s spooled to %s"
96 (gnus-group-prefixed-name
98 gnus-internal-registry-spool-current-method
100 (puthash id (cons (list 'spool nil group nil)
101 (gethash id gnus-registry-hashtb)) gnus-registry-hashtb))
103 (add-hook 'gnus-summary-article-move-hook 'gnus-register-action) ; also does copy, respool, and crosspost
104 (add-hook 'gnus-summary-article-delete-hook 'gnus-register-action)
105 (add-hook 'gnus-summary-article-expire-hook 'gnus-register-action)
106 (add-hook 'nnmail-spool-hook 'gnus-register-spool-action)
108 (add-hook 'gnus-save-newsrc-hook 'gnus-registry-translate-to-alist)
109 (add-hook 'gnus-read-newsrc-el-hook 'gnus-registry-translate-from-alist)
111 ;; TODO: a lot of things
113 (provide 'gnus-registry)
115 ;;; gnus-registry.el ends here