;;; gnus-registry.el --- article registry for Gnus
-;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
-;; Free Software Foundation, Inc.
+
+;; Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+;; 2005, 2006, 2007 Free Software Foundation, Inc.
;; Author: Ted Zlatanov <tzz@lifelogs.com>
;; Keywords: news
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(require 'gnus)
(require 'gnus-int)
(require 'gnus-sum)
+(require 'gnus-util)
(require 'nnmail)
(defvar gnus-registry-dirty t
(defgroup gnus-registry nil
"The Gnus registry."
+ :version "22.1"
:group 'gnus)
-(defvar gnus-registry-hashtb nil
+(defvar gnus-registry-hashtb (make-hash-table
+ :size 256
+ :test 'equal)
"*The article registry by Message ID.")
-(defcustom gnus-registry-unfollowed-groups '("delayed" "drafts" "queue")
- "List of groups that gnus-registry-split-fancy-with-parent won't follow.
-The group names are matched, they don't have to be fully qualified."
+(defcustom gnus-registry-unfollowed-groups '("delayed$" "drafts$" "queue$" "INBOX$")
+ "List of groups that gnus-registry-split-fancy-with-parent won't return.
+The group names are matched, they don't have to be fully
+qualified. This parameter tells the Registry 'never split a
+message into a group that matches one of these, regardless of
+references.'"
:group 'gnus-registry
- :type '(repeat string))
+ :type '(repeat regexp))
(defcustom gnus-registry-install nil
"Whether the registry should be installed."
The Subject and Sender (From:) headers are currently tracked this
way."
:group 'gnus-registry
- :type
+ :type
'(set :tag "Tracking choices"
(const :tag "Track by subject (Subject: header)" subject)
(const :tag "Track by sender (From: header)" sender)))
"Maximum number of entries in the registry, nil for unlimited."
:group 'gnus-registry
:type '(radio (const :format "Unlimited " nil)
- (integer :format "Maximum number: %v\n" :size 0)))
+ (integer :format "Maximum number: %v")))
(defun gnus-registry-track-subject-p ()
(memq 'subject gnus-registry-track-extra))
(gnus-load file)
(gnus-message 5 "Reading %s...done" file))))
+;; FIXME: Get rid of duplicated code, cf. `gnus-save-newsrc-file' in
+;; `gnus-start.el'. --rsteib
(defun gnus-registry-cache-save ()
"Save the registry cache file."
(interactive)
"%s#tmp#%d"))
working-dir (setq i (1+ i))))
(file-exists-p working-file)))
-
+
(unwind-protect
(progn
(gnus-with-output-to-file working-file
(gnus-gnus-to-quick-newsrc-format t "gnus registry startup file" 'gnus-registry-alist))
-
+
;; These bindings will mislead the current buffer
;; into thinking that it is visiting the startup
;; file.
(setmodes (file-modes startup-file)))
;; Backup the current version of the startup file.
(backup-buffer)
-
+
;; Replace the existing startup file with the temp file.
(rename-file working-file startup-file t)
(gnus-set-file-modes startup-file setmodes)))
(condition-case nil
(delete-file working-file)
(file-error nil)))))
-
+
(gnus-kill-buffer (current-buffer))
(gnus-message 5 "Saving %s...done" file))))
(remhash key gnus-registry-hashtb)))
gnus-registry-hashtb)
;; remove empty entries
- (when gnus-registry-clean-empty
+ (when gnus-registry-clean-empty
(gnus-registry-clean-empty-function))
- ;; now trim the registry appropriately
- (setq gnus-registry-alist (gnus-registry-trim
- (hashtable-to-alist gnus-registry-hashtb)))
+ ;; now trim and clean text properties from the registry appropriately
+ (setq gnus-registry-alist
+ (gnus-registry-remove-alist-text-properties
+ (gnus-registry-trim
+ (gnus-hashtable-to-alist
+ gnus-registry-hashtb))))
;; really save
(gnus-registry-cache-save)
(setq gnus-registry-entry-caching caching)
(defun gnus-registry-clean-empty-function ()
"Remove all empty entries from the registry. Returns count thereof."
(let ((count 0))
+
(maphash
(lambda (key value)
- (unless (or
- (gnus-registry-fetch-group key)
- ;; TODO: look for specific extra data here!
- ;; in this example, we look for 'label
- (gnus-registry-fetch-extra key 'label))
- (incf count)
- (remhash key gnus-registry-hashtb)))
+ (when (stringp key)
+ (dolist (group (gnus-registry-fetch-groups key))
+ (when (gnus-parameter-registry-ignore group)
+ (gnus-message
+ 10
+ "gnus-registry: deleted ignored group %s from key %s"
+ group key)
+ (gnus-registry-delete-group key group)))
+
+ (unless (gnus-registry-group-count key)
+ (gnus-registry-delete-id key))
+
+ (unless (or
+ (gnus-registry-fetch-group key)
+ ;; TODO: look for specific extra data here!
+ ;; in this example, we look for 'label
+ (gnus-registry-fetch-extra key 'label))
+ (incf count)
+ (gnus-registry-delete-id key))
+
+ (unless (stringp key)
+ (gnus-message
+ 10
+ "gnus-registry key %s was not a string, removing"
+ key)
+ (gnus-registry-delete-id key))))
+
gnus-registry-hashtb)
count))
(defun gnus-registry-read ()
(gnus-registry-cache-read)
- (setq gnus-registry-hashtb (alist-to-hashtable gnus-registry-alist))
+ (setq gnus-registry-hashtb (gnus-alist-to-hashtable gnus-registry-alist))
(setq gnus-registry-dirty nil))
+(defun gnus-registry-remove-alist-text-properties (v)
+ "Remove text properties from all strings in alist."
+ (if (stringp v)
+ (gnus-string-remove-all-properties v)
+ (if (and (listp v) (listp (cdr v)))
+ (mapcar 'gnus-registry-remove-alist-text-properties v)
+ (if (and (listp v) (stringp (cdr v)))
+ (cons (gnus-registry-remove-alist-text-properties (car v))
+ (gnus-registry-remove-alist-text-properties (cdr v)))
+ v))))
+
(defun gnus-registry-trim (alist)
- "Trim alist to size, using gnus-registry-max-entries."
+ "Trim alist to size, using gnus-registry-max-entries.
+Also, drop all gnus-registry-ignored-groups matches."
(if (null gnus-registry-max-entries)
alist ; just return the alist
;; else, when given max-entries, trim the alist
(lambda (key value)
(puthash key (gnus-registry-fetch-extra key 'mtime) timehash))
gnus-registry-hashtb)
-
+
;; we use the return value of this setq, which is the trimmed alist
(setq alist
(nthcdr
trim-length
- (sort alist
+ (sort alist
(lambda (a b)
- (time-less-p
- (cdr (gethash (car a) timehash))
- (cdr (gethash (car b) timehash))))))))))
-
-(defun alist-to-hashtable (alist)
- "Build a hashtable from the values in ALIST."
- (let ((ht (make-hash-table
- :size 4096
- :test 'equal)))
- (mapc
- (lambda (kv-pair)
- (puthash (car kv-pair) (cdr kv-pair) ht))
- alist)
- ht))
-
-(defun hashtable-to-alist (hash)
- "Build an alist from the values in HASH."
- (let ((list nil))
- (maphash
- (lambda (key value)
- (setq list (cons (cons key value) list)))
- hash)
- list))
+ (time-less-p
+ (or (cdr (gethash (car a) timehash)) '(0 0 0))
+ (or (cdr (gethash (car b) timehash)) '(0 0 0))))))))))
(defun gnus-registry-action (action data-header from &optional to method)
(let* ((id (mail-header-id data-header))
- (subject (gnus-registry-simplify-subject
- (mail-header-subject data-header)))
- (sender (mail-header-from data-header))
+ (subject (gnus-string-remove-all-properties
+ (gnus-registry-simplify-subject
+ (mail-header-subject data-header))))
+ (sender (gnus-string-remove-all-properties (mail-header-from data-header)))
(from (gnus-group-guess-full-name-from-command-method from))
(to (if to (gnus-group-guess-full-name-from-command-method to) nil))
(to-name (if to to "the Bit Bucket"))
;; All except copy will need a delete
(gnus-registry-delete-group id from)
- (when (equal 'copy action)
+ (when (equal 'copy action)
(gnus-registry-add-group id from subject sender)) ; undo the delete
(gnus-registry-add-group id to subject sender)))
"Split this message into the same group as its parent. The parent
is obtained from the registry. This function can be used as an entry
in `nnmail-split-fancy' or `nnimap-split-fancy', for example like
-this: (: gnus-registry-split-fancy-with-parent)
+this: (: gnus-registry-split-fancy-with-parent)
This function tracks ALL backends, unlike
`nnmail-split-fancy-with-parent' which tracks only nnmail
messages.
For a message to be split, it looks for the parent message in the
-References or In-Reply-To header and then looks in the registry to
-see which group that message was put in. This group is returned.
+References or In-Reply-To header and then looks in the registry
+to see which group that message was put in. This group is
+returned, unless it matches one of the entries in
+gnus-registry-unfollowed-groups or
+nnmail-split-fancy-with-parent-ignore-groups.
See the Info node `(gnus)Fancy Mail Splitting' for more details."
(let* ((refstr (or (message-fetch-field "references") "")) ; guarantee string
(if (listp nnmail-split-fancy-with-parent-ignore-groups)
nnmail-split-fancy-with-parent-ignore-groups
(list nnmail-split-fancy-with-parent-ignore-groups)))
- references res)
- (if refstr
- (progn
- (setq references (nreverse (gnus-extract-references refstr)))
- (mapcar (lambda (x)
- (setq res (or (gnus-registry-fetch-group x) res))
- (when (or (gnus-registry-grep-in-list
- res
- gnus-registry-unfollowed-groups)
- (gnus-registry-grep-in-list
- res
- nnmail-split-fancy-with-parent-ignore-groups))
- (setq res nil)))
- references))
+ res)
+ ;; the references string must be valid and parse to valid references
+ (if (and refstr (gnus-extract-references refstr))
+ (dolist (reference (nreverse (gnus-extract-references refstr)))
+ (setq res (or (gnus-registry-fetch-group reference) res))
+ (when (or (gnus-registry-grep-in-list
+ res
+ gnus-registry-unfollowed-groups)
+ (gnus-registry-grep-in-list
+ res
+ nnmail-split-fancy-with-parent-ignore-groups))
+ (setq res nil)))
;; else: there were no references, now try the extra tracking
- (let ((sender (message-fetch-field "from"))
- (subject (gnus-registry-simplify-subject
- (message-fetch-field "subject")))
+ (let ((sender (gnus-string-remove-all-properties(message-fetch-field "from")))
+ (subject (gnus-string-remove-all-properties
+ (gnus-registry-simplify-subject
+ &nb