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.")
39 (defvar gnus-registry-headers-hashtb nil
40 "*The article header registry by Message ID.")
41 ;; (setq gnus-registry-hashtb (make-hash-table
43 ;; :test 'equal)) ; we test message ID strings equality
46 ;; (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))
48 ;; (maphash (lambda (key value) (message "key: %s value: %s" key value)) gnus-registry-hashtb)
49 ;; (clrhash gnus-registry-hashtb)
50 ;; (setq gnus-registry-alist nil)
52 ;; Function(s) missing in Emacs 20
53 (when (memq nil (mapcar 'fboundp '(puthash)))
55 (unless (fboundp 'puthash)
56 ;; alias puthash is missing from Emacs 20 cl-extra.el
57 (defalias 'puthash 'cl-puthash)))
59 (defun gnus-registry-translate-to-alist ()
60 (setq gnus-registry-alist (hashtable-to-alist gnus-registry-hashtb))
61 (setq gnus-registry-headers-alist (hashtable-to-alist gnus-registry-headers-hashtb)))
63 (defun gnus-registry-translate-from-alist ()
64 (setq gnus-registry-hashtb (alist-to-hashtable gnus-registry-alist))
65 (setq gnus-registry-headers-hashtb (alist-to-hashtable gnus-registry-headers-alist)))
67 (defun alist-to-hashtable (alist)
68 "Build a hashtable from the values in ALIST."
69 (let ((ht (make-hash-table
74 (puthash (car kv-pair) (cdr kv-pair) ht))
78 (defun hashtable-to-alist (hash)
79 "Build an alist from the values in HASH."
83 (setq list (cons (cons key value) list)))
87 (defun gnus-register-action (action data-header from &optional to method)
88 (let* ((id (mail-header-id data-header)))
89 (gnus-message 5 "Registry: article %s %s from %s to %s"
91 (if method "respooling" "going")
92 (gnus-group-guess-full-name from)
93 (if to (gnus-group-guess-full-name to) "the Bit Bucket"))
94 (unless (gethash id gnus-registry-headers-hashtb)
95 (puthash id (list data-header) gnus-registry-headers-hashtb))
96 (puthash id (cons (list action from to method)
97 (gethash id gnus-registry-hashtb)) gnus-registry-hashtb)))
99 (defun gnus-register-spool-action (id group)
100 (when (string-match "
\r$" id)
101 (setq id (substring id 0 -1)))
102 (gnus-message 5 "Registry: article %s spooled to %s"
104 (gnus-group-prefixed-name
106 gnus-internal-registry-spool-current-method
108 (puthash id (cons (list 'spool nil group nil)
109 (gethash id gnus-registry-hashtb)) gnus-registry-hashtb))
111 (add-hook 'gnus-summary-article-move-hook 'gnus-register-action) ; also does copy, respool, and crosspost
112 (add-hook 'gnus-summary-article-delete-hook 'gnus-register-action)
113 (add-hook 'gnus-summary-article-expire-hook 'gnus-register-action)
114 (add-hook 'nnmail-spool-hook 'gnus-register-spool-action)
116 (add-hook 'gnus-save-newsrc-hook 'gnus-registry-translate-to-alist)
117 (add-hook 'gnus-read-newsrc-el-hook 'gnus-registry-translate-from-alist)
119 ;; TODO: a lot of things
121 (provide 'gnus-registry)
123 ;;; gnus-registry.el ends here