nnml.el (nnml-request-accept-article): pass sender to
[gnus] / 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 ;; This is the gnus-registry.el package, works with other backends
28 ;; besides nnmail.  The major issue is that it doesn't go across
29 ;; backends, so for instance if an article is in nnml:sys and you see
30 ;; a reference to it in nnimap splitting, the article will end up in
31 ;; nnimap:sys
32
33 ;; gnus-registry.el intercepts article respooling, moving, deleting,
34 ;; and copying for all backends.  If it doesn't work correctly for
35 ;; you, submit a bug report and I'll be glad to fix it.  It needs
36 ;; documentation in the manual (also on my to-do list).
37
38 ;; Put this in your startup file (~/.gnus.el for instance)
39
40 ;; (setq gnus-registry-max-entries 2500
41 ;;       gnus-registry-use-long-group-names t)
42
43 ;; (gnus-registry-initialize)
44
45 ;; Then use this in your fancy-split:
46
47 ;; (: gnus-registry-split-fancy-with-parent)
48
49 ;; TODO:
50
51 ;; - get the correct group on spool actions
52
53 ;; - articles that are spooled to a different backend should be handled
54
55 ;;; Code:
56
57 (eval-when-compile (require 'cl))
58
59 (require 'gnus)
60 (require 'gnus-int)
61 (require 'gnus-sum)
62 (require 'nnmail)
63
64 (defvar gnus-registry-dirty t
65  "Boolean set to t when the registry is modified")
66
67 (defgroup gnus-registry nil
68   "The Gnus registry."
69   :group 'gnus)
70
71 (defvar gnus-registry-hashtb nil
72   "*The article registry by Message ID.")
73
74 (defcustom gnus-registry-unfollowed-groups '("delayed" "drafts" "queue")
75   "List of groups that gnus-registry-split-fancy-with-parent won't follow.
76 The group names are matched, they don't have to be fully qualified."
77   :group 'gnus-registry
78   :type '(repeat string))
79
80 (defcustom gnus-registry-install nil
81   "Whether the registry should be installed."
82   :group 'gnus-registry
83   :type 'boolean)
84
85 (defcustom gnus-registry-clean-empty t
86   "Whether the empty registry entries should be deleted.
87 Registry entries are considered empty when they have no groups."
88   :group 'gnus-registry
89   :type 'boolean)
90
91 (defcustom gnus-registry-use-long-group-names nil
92   "Whether the registry should use long group names (BUGGY)."
93   :group 'gnus-registry
94   :type 'boolean)
95
96 (defcustom gnus-registry-track-extra nil
97   "Whether the registry should track other things about a message.
98 The Subject and Sender (From:) headers are currently tracked this
99 way."
100   :group 'gnus-registry
101   :type 'boolean)
102
103 (defcustom gnus-registry-entry-caching t
104   "Whether the registry should cache extra information."
105   :group 'gnus-registry
106   :type 'boolean)
107
108 (defcustom gnus-registry-minimum-subject-length 5
109   "The minimum length of a subject before it's considered trackable."
110   :group 'gnus-registry
111   :type 'integer)
112
113 (defcustom gnus-registry-trim-articles-without-groups t
114   "Whether the registry should clean out message IDs without groups."
115   :group 'gnus-registry
116   :type 'boolean)
117
118 (defcustom gnus-registry-cache-file "~/.gnus.registry.eld"
119   "File where the Gnus registry will be stored."
120   :group 'gnus-registry
121   :type 'file)
122
123 (defcustom gnus-registry-max-entries nil
124   "Maximum number of entries in the registry, nil for unlimited."
125   :group 'gnus-registry
126   :type '(radio (const :format "Unlimited " nil)
127                 (integer :format "Maximum number: %v\n" :size 0)))
128
129 ;; Function(s) missing in Emacs 20
130 (when (memq nil (mapcar 'fboundp '(puthash)))
131   (require 'cl)
132   (unless (fboundp 'puthash)
133     ;; alias puthash is missing from Emacs 20 cl-extra.el
134     (defalias 'puthash 'cl-puthash)))
135
136 (defun gnus-registry-cache-read ()
137   "Read the registry cache file."
138   (interactive)
139   (let ((file gnus-registry-cache-file))
140     (when (file-exists-p file)
141       (gnus-message 5 "Reading %s..." file)
142       (gnus-load file)
143       (gnus-message 5 "Reading %s...done" file))))
144
145 (defun gnus-registry-cache-save ()
146   "Save the registry cache file."
147   (interactive)
148   (let ((file gnus-registry-cache-file))
149     (save-excursion
150       (set-buffer (gnus-get-buffer-create " *Gnus-registry-cache*"))
151       (make-local-variable 'version-control)
152     (setq version-control gnus-backup-startup-file)
153     (setq buffer-file-name file)
154     (setq default-directory (file-name-directory buffer-file-name))
155     (buffer-disable-undo)
156     (erase-buffer)
157     (gnus-message 5 "Saving %s..." file)
158     (if gnus-save-startup-file-via-temp-buffer
159         (let ((coding-system-for-write gnus-ding-file-coding-system)
160               (standard-output (current-buffer)))
161           (gnus-gnus-to-quick-newsrc-format t "gnus registry startup file" 'gnus-registry-alist)
162           (gnus-registry-cache-whitespace file)
163           (save-buffer))
164       (let ((coding-system-for-write gnus-ding-file-coding-system)
165             (version-control gnus-backup-startup-file)
166             (startup-file file)
167             (working-dir (file-name-directory file))
168             working-file
169             (i -1))
170         ;; Generate the name of a non-existent file.
171         (while (progn (setq working-file
172                             (format
173                              (if (and (eq system-type 'ms-dos)
174                                       (not (gnus-long-file-names)))
175                                  "%s#%d.tm#" ; MSDOS limits files to 8+3
176                                (if (memq system-type '(vax-vms axp-vms))
177                                    "%s$tmp$%d"
178                                  "%s#tmp#%d"))
179                              working-dir (setq i (1+ i))))
180                       (file-exists-p working-file)))
181         
182         (unwind-protect
183             (progn
184               (gnus-with-output-to-file working-file
185                 (gnus-gnus-to-quick-newsrc-format t "gnus registry startup file" 'gnus-registry-alist))
186               
187               ;; These bindings will mislead the current buffer
188               ;; into thinking that it is visiting the startup
189               ;; file.
190               (let ((buffer-backed-up nil)
191                     (buffer-file-name startup-file)
192                     (file-precious-flag t)
193                     (setmodes (file-modes startup-file)))
194                 ;; Backup the current version of the startup file.
195                 (backup-buffer)
196                 
197                 ;; Replace the existing startup file with the temp file.
198                 (rename-file working-file startup-file t)
199                 (set-file-modes startup-file setmodes)))
200           (condition-case nil
201               (delete-file working-file)
202             (file-error nil)))))
203     
204     (gnus-kill-buffer (current-buffer))
205     (gnus-message 5 "Saving %s...done" file))))
206
207 ;; Idea from Dan Christensen <jdc@chow.mat.jhu.edu>
208 ;; Save the gnus-registry file with extra line breaks.
209 (defun gnus-registry-cache-whitespace (filename)
210   (gnus-message 5 "Adding whitespace to %s" filename)
211   (save-excursion
212     (goto-char (point-min))
213     (while (re-search-forward "^(\\|(\\\"" nil t)
214       (replace-match "\n\\&" t))
215     (goto-char (point-min))
216     (while (re-search-forward " $" nil t)
217       (replace-match "" t t))))
218
219 (defun gnus-registry-save (&optional force)
220   (when (or gnus-registry-dirty force)
221     (let ((caching gnus-registry-entry-caching))
222       ;; turn off entry caching, so mtime doesn't get recorded
223       (setq gnus-registry-entry-caching nil)
224       ;; remove entry caches
225       (maphash
226        (lambda (key value)
227          (if (hash-table-p value)
228              (remhash key gnus-registry-hashtb)))
229        gnus-registry-hashtb)
230       ;; remove empty entries
231       (when gnus-registry-clean-empty 
232         (gnus-registry-clean-empty-function))
233       ;; now trim the registry appropriately
234       (setq gnus-registry-alist (gnus-registry-trim 
235                                  (hashtable-to-alist gnus-registry-hashtb)))
236       ;; really save
237       (gnus-registry-cache-save)
238       (setq gnus-registry-entry-caching caching)
239       (setq gnus-registry-dirty nil))))
240
241 (defun gnus-registry-clean-empty-function ()
242   "Remove all empty entries from the registry.  Returns count thereof."
243   (let ((count 0))
244     (maphash
245      (lambda (key value)
246        (unless (gnus-registry-fetch-group key)
247          (incf count)
248          (remhash key gnus-registry-hashtb)))
249      gnus-registry-hashtb)
250     count))
251
252 (defun gnus-registry-read ()
253   (gnus-registry-cache-read)
254   (setq gnus-registry-hashtb (alist-to-hashtable gnus-registry-alist))
255   (setq gnus-registry-dirty nil))
256
257 (defun gnus-registry-trim (alist)
258   "Trim alist to size, using gnus-registry-max-entries."
259   (if (null gnus-registry-max-entries)
260       alist                             ; just return the alist
261     ;; else, when given max-entries, trim the alist
262     (let ((timehash (make-hash-table                        
263                      :size 4096
264                      :test 'equal)))
265       (maphash
266        (lambda (key value)
267          (puthash key (gnus-registry-fetch-extra key 'mtime) timehash))
268        gnus-registry-hashtb)
269
270       ;; we use the return value of this setq, which is the trimmed alist
271       (setq alist
272             (nthcdr
273              (- (length alist) gnus-registry-max-entries)
274              (sort alist 
275                    (lambda (a b)
276                      (time-less-p 
277                       (cdr (gethash (car a) timehash))
278                       (cdr (gethash (car b) timehash))))))))))
279
280 (defun alist-to-hashtable (alist)
281   "Build a hashtable from the values in ALIST."
282   (let ((ht (make-hash-table                        
283              :size 4096
284              :test 'equal)))
285     (mapc
286      (lambda (kv-pair)
287        (puthash (car kv-pair) (cdr kv-pair) ht))
288      alist)
289      ht))
290
291 (defun hashtable-to-alist (hash)
292   "Build an alist from the values in HASH."
293   (let ((list nil))
294     (maphash
295      (lambda (key value)
296        (setq list (cons (cons key value) list)))
297      hash)
298     list))
299
300 (defun gnus-registry-action (action data-header from &optional to method)
301   (let* ((id (mail-header-id data-header))
302          (subject (gnus-registry-simplify-subject 
303                    (mail-header-subject data-header)))
304          (sender (mail-header-from data-header))
305          (from (gnus-group-guess-full-name-from-command-method from))
306          (to (if to (gnus-group-guess-full-name-from-command-method to) nil))
307          (to-name (if to to "the Bit Bucket"))
308          (old-entry (gethash id gnus-registry-hashtb)))
309     (gnus-message 5 "Registry: article %s %s from %s to %s"
310                   id
311                   (if method "respooling" "going")
312                   from
313                   to)
314
315     ;; All except copy will need a delete
316     (gnus-registry-delete-group id from)
317
318     (when (equal 'copy action) 
319       (gnus-registry-add-group id from subject sender)) ; undo the delete
320
321     (gnus-registry-add-group id to subject sender)))
322
323 (defun gnus-registry-spool-action (id group &optional subject sender)
324   (let ((group (gnus-group-guess-full-name-from-command-method group)))
325     (when (and (stringp id) (string-match "\r$" id))
326       (setq id (substring id 0 -1)))
327     (gnus-message 5 "Registry: article %s spooled to %s"
328                   id
329                   group)
330     (gnus-registry-add-group id group subject sender)))
331
332 ;; Function for nn{mail|imap}-split-fancy: look up all references in
333 ;; the cache and if a match is found, return that group.
334 (defun gnus-registry-split-fancy-with-parent ()
335   "Split this message into the same group as its parent.  The parent
336 is obtained from the registry.  This function can be used as an entry
337 in `nnmail-split-fancy' or `nnimap-split-fancy', for example like
338 this: (: gnus-registry-split-fancy-with-parent) 
339
340 For a message to be split, it looks for the parent message in the
341 References or In-Reply-To header and then looks in the registry to
342 see which group that message was put in.  This group is returned.
343
344 See the Info node `(gnus)Fancy Mail Splitting' for more details."
345   (let ((refstr (or (message-fetch-field "references")
346                     (message-fetch-field "in-reply-to")))
347         (nnmail-split-fancy-with-parent-ignore-groups
348          (if (listp nnmail-split-fancy-with-parent-ignore-groups)
349              nnmail-split-fancy-with-parent-ignore-groups
350            (list nnmail-split-fancy-with-parent-ignore-groups)))
351         references res)
352     (if refstr
353         (progn
354           (setq references (nreverse (gnus-split-references refstr)))
355           (mapcar (lambda (x)
356                     (setq res (or (gnus-registry-fetch-group x) res))
357                     (when (or (gnus-registry-grep-in-list
358                                res
359                                gnus-registry-unfollowed-groups)
360                               (gnus-registry-grep-in-list 
361                                res
362                                nnmail-split-fancy-with-parent-ignore-groups))
363                       (setq res nil)))
364                   references))
365       ;; there were no references, now try the extra tracking
366       (when gnus-registry-track-extra
367         (let ((sender (message-fetch-field "from"))
368               (subject (gnus-registry-simplify-subject
369                         (message-fetch-field "subject"))))
370           (when (and subject
371                      (< gnus-registry-minimum-subject-length (length subject)))
372             (maphash
373              (lambda (key value)
374                (let ((this-subject (cdr 
375                                     (gnus-registry-fetch-extra key 'subject))))
376                  (when (and this-subject
377                             (equal subject this-subject))
378                    (setq res (gnus-registry-fetch-group key))
379                    (gnus-message
380                     ;; raise level of messaging if gnus-registry-track-extra
381                     (if gnus-registry-track-extra 5 9)
382                     "%s (extra tracking) traced subject %s to group %s"
383                     "gnus-registry-split-fancy-with-parent"
384                     subject
385                     (if res res "nil")))))
386              gnus-registry-hashtb))
387           (when sender
388             (maphash
389              (lambda (key value)
390                (let ((this-sender (cdr 
391                                     (gnus-registry-fetch-extra key 'sender))))
392                  (when (and this-sender
393                             (equal sender this-sender))
394                    (setq res (gnus-registry-fetch-group key))
395                    (gnus-message
396                     ;; raise level of messaging if gnus-registry-track-extra
397                     (if gnus-registry-track-extra 5 9)
398                     "%s (extra tracking) traced sender %s to group %s"
399                     "gnus-registry-split-fancy-with-parent"
400                     sender
401                     (if res res "nil")))))
402              gnus-registry-hashtb)))))
403     (gnus-message
404      5 
405      "gnus-registry-split-fancy-with-parent traced %s to group %s"
406      refstr (if res res "nil"))
407
408     (when (and res gnus-registry-use-long-group-names)
409       (let ((m1 (gnus-find-method-for-group res))
410             (m2 (or gnus-command-method 
411                     (gnus-find-method-for-group gnus-newsgroup-name)))
412             (short-res (gnus-group-short-name res)))
413       (if (gnus-methods-equal-p m1 m2)
414           (progn
415             (gnus-message
416              9 
417              "gnus-registry-split-fancy-with-parent stripped group %s to %s"
418              res
419              short-res)
420             (setq res short-res))
421         ;; else...
422         (gnus-message
423          5 
424          "gnus-registry-split-fancy-with-parent ignored foreign group %s"
425          res)
426         (setq res nil))))
427     res))
428
429 (defun gnus-registry-register-message-ids ()
430   "Register the Message-ID of every article in the group"
431   (unless (gnus-parameter-registry-ignore gnus-newsgroup-name)
432     (dolist (article gnus-newsgroup-articles)
433       (let ((id (gnus-registry-fetch-message-id-fast article)))
434         (unless (gnus-registry-fetch-group id)
435           (gnus-message 9 "Registry: Registering article %d with group %s" 
436                         article gnus-newsgroup-name)
437           (gnus-registry-add-group 
438            (gnus-registry-fetch-message-id-fast article)
439            gnus-newsgroup-name
440            (gnus-registry-fetch-simplified-message-subject-fast article)
441            (gnus-registry-fetch-sender-fast article)))))))
442
443 (defun gnus-registry-fetch-message-id-fast (article)
444   "Fetch the Message-ID quickly, using the internal gnus-data-list function"
445   (if (and (numberp article)
446            (assoc article (gnus-data-list nil)))
447       (mail-header-id (gnus-data-header (assoc article (gnus-data-list nil))))
448     nil))
449
450 (defun gnus-registry-simplify-subject (subject)
451   (if (stringp subject)
452       (gnus-simplify-subject subject)
453     nil))
454
455 (defun gnus-registry-fetch-simplified-message-subject-fast (article)
456   "Fetch the Subject quickly, using the internal gnus-data-list function"
457   (if (and (numberp article)
458            (assoc article (gnus-data-list nil)))
459       (gnus-registry-simplify-subject
460        (mail-header-subject (gnus-data-header
461                              (assoc article (gnus-data-list nil)))))
462     nil))
463
464 (defun gnus-registry-fetch-sender-fast (article)
465   "Fetch the Sender quickly, using the internal gnus-data-list function"
466   (if (and (numberp article)
467            (assoc article (gnus-data-list nil)))
468       (mail-header-from (gnus-data-header
469                          (assoc article (gnus-data-list nil))))
470     nil))
471
472 (defun gnus-registry-grep-in-list (word list)
473   (when word
474     (memq nil
475           (mapcar 'not
476                   (mapcar 
477                    (lambda (x)
478                      (string-match x word))
479                    list)))))
480
481 (defun gnus-registry-fetch-extra (id &optional entry)
482   "Get the extra data of a message, based on the message ID.
483 Returns the first place where the trail finds a nonstring."
484   (let ((entry-cache (gethash entry gnus-registry-hashtb)))
485     (if (and entry
486              (hash-table-p entry-cache)
487              (gethash id entry-cache))
488         (gethash id entry-cache)
489       ;; else, if there is no caching possible...
490       (let ((trail (gethash id gnus-registry-hashtb)))
491         (when (listp trail)
492           (dolist (crumb trail)
493             (unless (stringp crumb)
494               (return (gnus-registry-fetch-extra-entry crumb entry id)))))))))
495
496 (defun gnus-registry-fetch-extra-entry (alist &optional entry id)
497   "Get the extra data of a message, or a specific entry in it.
498 Update the entry cache if needed."
499   (if (and entry id)
500       (let ((entry-cache (gethash entry gnus-registry-hashtb))
501             entree)
502         (when gnus-registry-entry-caching
503           ;; create the hash table
504           (unless (hash-table-p entry-cache)
505             (setq entry-cache (make-hash-table
506                                :size 4096
507                                :test 'equal))
508             (puthash entry entry-cache gnus-registry-hashtb))
509
510           ;; get the entree from the hash table or from the alist
511           (setq entree (gethash id entry-cache)))
512         
513         (unless entree
514           (setq entree (assq entry alist))
515           (when gnus-registry-entry-caching
516             (puthash id entree entry-cache)))
517         entree)
518     alist))
519
520 (defun gnus-registry-store-extra (id extra)
521   "Store the extra data of a message, based on the message ID.
522 The message must have at least one group name."
523   (when (gnus-registry-group-count id)
524     ;; we now know the trail has at least 1 group name, so it's not empty
525     (let ((trail (gethash id gnus-registry-hashtb))
526           (old-extra (gnus-registry-fetch-extra id))
527           entry-cache)
528       (dolist (crumb trail)
529         (unless (stringp crumb)
530           (dolist (entry crumb)
531             (setq entry-cache (gethash (car entry) gnus-registry-hashtb))
532           (when entry-cache
533             (remhash id entry-cache))))
534       (puthash id (cons extra (delete old-extra trail))
535                gnus-registry-hashtb)
536       (setq gnus-registry-dirty t)))))
537
538 (defun gnus-registry-store-extra-entry (id key value)
539   "Put a specific entry in the extras field of the registry entry for id."
540   (let* ((extra (gnus-registry-fetch-extra id))
541          (alist (cons (cons key value)
542                  (gnus-assq-delete-all key (gnus-registry-fetch-extra id)))))
543     (gnus-registry-store-extra id alist)))
544
545 (defun gnus-registry-fetch-group (id)
546   "Get the group of a message, based on the message ID.
547 Returns the first place where the trail finds a group name."
548   (when (gnus-registry-group-count id)
549     ;; we now know the trail has at least 1 group name
550     (let ((trail (gethash id gnus-registry-hashtb)))
551       (dolist (crumb trail)
552         (when (stringp crumb)
553           (return (if gnus-registry-use-long-group-names 
554                        crumb 
555                      (gnus-group-short-name crumb))))))))
556
557 (defun gnus-registry-group-count (id)
558   "Get the number of groups of a message, based on the message ID."
559   (let ((trail (gethash id gnus-registry-hashtb)))
560     (if (and trail (listp trail))
561         (apply '+ (mapcar (lambda (x) (if (stringp x) 1 0)) trail))
562       0)))
563
564 (defun gnus-registry-delete-group (id group)
565   "Delete a group for a message, based on the message ID."
566   (when group
567     (when id
568       (let ((trail (gethash id gnus-registry-hashtb))
569             (group (gnus-group-short-name group)))
570         (puthash id (if trail
571                         (delete group trail)
572                       nil)
573                  gnus-registry-hashtb))
574       ;; now, clear the entry if there are no more groups
575       (when gnus-registry-trim-articles-without-groups
576         (unless (gnus-registry-group-count id)
577           (gnus-registry-delete-id id)))
578       (gnus-registry-store-extra-entry id 'mtime (current-time)))))
579
580 (defun gnus-registry-delete-id (id)
581   "Delete a message ID from the registry."
582   (when (stringp id)
583     (remhash id gnus-registry-hashtb)
584     (maphash
585      (lambda (key value)
586        (when (hash-table-p value)
587          (remhash id value)))
588      gnus-registry-hashtb)))
589
590 (defun gnus-registry-add-group (id group &optional subject sender)
591   "Add a group for a message, based on the message ID."
592   (when group
593     (when (and id
594                (not (string-match "totally-fudged-out-message-id" id)))
595       (let ((full-group group)
596             (group (if gnus-registry-use-long-group-names 
597                        group 
598                      (gnus-group-short-name group))))
599         (gnus-registry-delete-group id group)
600
601         (unless gnus-registry-use-long-group-names ;; unnecessary in this case
602           (gnus-registry-delete-group id full-group))
603
604         (let ((trail (gethash id gnus-registry-hashtb)))
605           (puthash id (if trail
606                           (cons group trail)
607                         (list group))
608                    gnus-registry-hashtb)
609
610           (when gnus-registry-track-extra
611             (when subject
612               (gnus-registry-store-extra-entry
613                id 
614                'subject 
615                (gnus-registry-simplify-subject subject)))
616             (when sender
617               (gnus-registry-store-extra-entry
618                id 
619                'sender
620                sender)))
621           
622           (gnus-registry-store-extra-entry id 'mtime (current-time)))))))
623
624 (defun gnus-registry-clear ()
625   "Clear the Gnus registry."
626   (interactive)
627   (setq gnus-registry-alist nil)
628   (setq gnus-registry-hashtb (alist-to-hashtable gnus-registry-alist))
629   (setq gnus-registry-dirty t))
630
631 ;;;###autoload
632 (defun gnus-registry-initialize ()
633   (interactive)
634   (setq gnus-registry-install t)
635   (gnus-registry-install-hooks)
636   (gnus-registry-read))
637
638 ;;;###autoload
639 (defun gnus-registry-install-hooks ()
640   "Install the registry hooks."
641   (interactive)
642   (add-hook 'gnus-summary-article-move-hook 'gnus-registry-action) 
643   (add-hook 'gnus-summary-article-delete-hook 'gnus-registry-action)
644   (add-hook 'gnus-summary-article-expire-hook 'gnus-registry-action)
645   (add-hook 'nnmail-spool-hook 'gnus-registry-spool-action)
646   
647   (add-hook 'gnus-save-newsrc-hook 'gnus-registry-save)
648   (add-hook 'gnus-read-newsrc-el-hook 'gnus-registry-read)
649
650   (add-hook 'gnus-summary-prepare-hook 'gnus-registry-register-message-ids))
651
652 (defun gnus-registry-unload-hook ()
653   "Uninstall the registry hooks."
654   (interactive)
655   (remove-hook 'gnus-summary-article-move-hook 'gnus-registry-action) 
656   (remove-hook 'gnus-summary-article-delete-hook 'gnus-registry-action)
657   (remove-hook 'gnus-summary-article-expire-hook 'gnus-registry-action)
658   (remove-hook 'nnmail-spool-hook 'gnus-registry-spool-action)
659   
660   (remove-hook 'gnus-save-newsrc-hook 'gnus-registry-save)
661   (remove-hook 'gnus-read-newsrc-el-hook 'gnus-registry-read)
662
663   (remove-hook 'gnus-summary-prepare-hook 'gnus-registry-register-message-ids))
664
665 (when gnus-registry-install
666   (gnus-registry-install-hooks)
667   (gnus-registry-read))
668
669 ;; TODO: a lot of things
670
671 (provide 'gnus-registry)
672
673 ;;; gnus-registry.el ends here