Import Oort Gnus v0.16.
[elisp/gnus.git-] / lisp / gnus-registry.el
1 ;;; gnus-registry.el --- article registry for Gnus
2 ;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Ted Zlatanov <tzz@lifelogs.com>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 (require 'gnus)
32 (require 'gnus-int)
33 (require 'gnus-sum)
34 (require 'nnmail)
35
36 (defvar gnus-registry-hashtb nil
37   "*The article registry by Message ID.")
38 (setq gnus-registry-hashtb (make-hash-table 
39                             :size 4096
40                             :test 'equal)) ; we test message ID strings equality
41
42 ;; sample data-header
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))
44
45 ;; (maphash (lambda (key value) (message "key: %s value: %s" key value)) gnus-registry-hashtb)
46 ;; (clrhash gnus-registry-hashtb)
47
48 ;; Function(s) missing in Emacs 20
49 (when (memq nil (mapcar 'fboundp '(puthash)))
50   (require 'cl)
51   (unless (fboundp 'puthash)
52     ;; alias puthash is missing from Emacs 20 cl-extra.el
53     (defalias 'puthash 'cl-puthash)))
54
55 (defun gnus-register-action (action data-header from &optional to method)
56   (let* ((id (mail-header-id data-header))
57         (hash-entry (gethash id gnus-registry-hashtb)))
58     (gnus-message 5 "Registry: article %s %s from %s to %s"
59              id
60              (if method "respooling" "going")
61              (gnus-group-guess-full-name from)
62              (if to (gnus-group-guess-full-name to) "the Bit Bucket"))
63     (unless hash-entry 
64       (setq hash-entry (puthash id (list data-header) gnus-registry-hashtb)))
65     (puthash id (cons (list action from to method) 
66                       (gethash id gnus-registry-hashtb)) gnus-registry-hashtb)))
67
68 (defun gnus-register-spool-action (id group)
69   (gnus-message 5 "Registry: article %s spooled to %s"
70            id
71            (gnus-group-prefixed-name 
72             group 
73             gnus-internal-registry-spool-current-method 
74             t)))
75
76 (add-hook 'gnus-summary-article-move-hook 'gnus-register-action) ; also does copy, respool, and crosspost
77 (add-hook 'gnus-summary-article-delete-hook 'gnus-register-action)
78 (add-hook 'gnus-summary-article-expire-hook 'gnus-register-action)
79 (add-hook 'nnmail-spool-hook 'gnus-register-spool-action)
80
81 ;; TODO: a lot of things
82 ;; TODO: we have to load and save the registry through gnus-save-newsrc-file
83
84 (provide 'gnus-registry)
85
86 ;;; gnus-registry.el ends here