Merge from gnus--rel--5.10
[gnus] / lisp / gnus-registry.el
index 192f644..ca77939 100644 (file)
@@ -60,6 +60,7 @@
 (require 'gnus)
 (require 'gnus-int)
 (require 'gnus-sum)
+(require 'gnus-util)
 (require 'nnmail)
 
 (defvar gnus-registry-dirty t
@@ -240,9 +241,12 @@ way."
       ;; remove empty entries
       (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)
@@ -257,7 +261,7 @@ way."
        (when (stringp key)
         (dolist (group (gnus-registry-fetch-groups key))
           (when (gnus-parameter-registry-ignore group)
-            (gnus-message 
+            (gnus-message
              10 
              "gnus-registry: deleted ignored group %s from key %s"
              group key)
@@ -270,8 +274,7 @@ way."
                  (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)
-                 (stringp key))
+                 (gnus-registry-fetch-extra key 'label))
           (incf count)
           (gnus-registry-delete-id key))
         
@@ -287,9 +290,20 @@ way."
 
 (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.
 Also, drop all gnus-registry-ignored-groups matches."
@@ -310,37 +324,18 @@ Also, drop all gnus-registry-ignored-groups matches."
       (setq alist
            (nthcdr
             trim-length
-            (sort alist 
+            (sort alist
                   (lambda (a b)
                     (time-less-p
                      (or (cdr (gethash (car a) timehash)) '(0 0 0))
                      (or (cdr (gethash (car b) timehash)) '(0 0 0))))))))))
 
-(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))
-
 (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"))
@@ -412,9 +407,10 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
                  references))
 
       ;; 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
+                      (message-fetch-field "subject"))))
            (single-match t))
        (when (and single-match
                   (gnus-registry-track-sender-p)
@@ -496,6 +492,39 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
        (setq res nil))))
     res))
 
+(defun gnus-registry-wash-for-keywords (&optional force)
+  (interactive)
+  (let ((id (gnus-registry-fetch-message-id-fast gnus-current-article))
+       word words)
+    (if (or (not (gnus-registry-fetch-extra id 'keywords))
+           force)
+       (save-excursion
+         (set-buffer gnus-article-buffer)
+         (article-goto-body)
+         (save-window-excursion
+           (save-restriction
+             (narrow-to-region (point) (point-max))
+             (with-syntax-table gnus-adaptive-word-syntax-table
+               (while (re-search-forward "\\b\\w+\\b" nil t)
+                 (setq word (gnus-registry-remove-alist-text-properties
+                             (downcase (buffer-substring
+                                        (match-beginning 0) (match-end 0)))))
+                 (if (> (length word) 3)
+                     (push word words))))))
+         (gnus-registry-store-extra-entry id 'keywords words)))))
+
+(defun gnus-registry-find-keywords (keyword)
+  (interactive "skeyword: ")
+  (let (articles)
+    (maphash
+     (lambda (key value)
+       (when (gnus-registry-grep-in-list
+             keyword
+             (cdr (gnus-registry-fetch-extra key 'keywords)))
+        (push key articles)))
+     gnus-registry-hashtb)
+    articles))
+
 (defun gnus-registry-register-message-ids ()
   "Register the Message-ID of every article in the group"
   (unless (gnus-parameter-registry-ignore gnus-newsgroup-name)
@@ -526,17 +555,19 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
   "Fetch the Subject quickly, using the internal gnus-data-list function"
   (if (and (numberp article)
           (assoc article (gnus-data-list nil)))
-      (gnus-registry-simplify-subject
-       (mail-header-subject (gnus-data-header
-                            (assoc article (gnus-data-list nil)))))
+      (gnus-string-remove-all-properties
+       (gnus-registry-simplify-subject
+       (mail-header-subject (gnus-data-header
+                             (assoc article (gnus-data-list nil))))))
     nil))
 
 (defun gnus-registry-fetch-sender-fast (article)
   "Fetch the Sender quickly, using the internal gnus-data-list function"
   (if (and (numberp article)
           (assoc article (gnus-data-list nil)))
-      (mail-header-from (gnus-data-header
-                        (assoc article (gnus-data-list nil))))
+      (gnus-string-remove-all-properties
+       (mail-header-from (gnus-data-header
+                         (assoc article (gnus-data-list nil)))))
     nil))
 
 (defun gnus-registry-grep-in-list (word list)
@@ -608,8 +639,9 @@ The message must have at least one group name."
 (defun gnus-registry-store-extra-entry (id key value)
   "Put a specific entry in the extras field of the registry entry for id."
   (let* ((extra (gnus-registry-fetch-extra id))
-        (alist (cons (cons key value)
-                (gnus-assq-delete-all key (gnus-registry-fetch-extra id)))))
+        (alist (gnus-registry-remove-alist-text-properties 
+                (cons (cons key value)
+                      (gnus-assq-delete-all key (gnus-registry-fetch-extra id))))))
     (gnus-registry-store-extra id alist)))
 
 (defun gnus-registry-fetch-group (id)
@@ -714,7 +746,7 @@ Returns the first place where the trail finds a group name."
   "Clear the Gnus registry."
   (interactive)
   (setq gnus-registry-alist nil)
-  (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 t))
 
 ;;;###autoload