:type 'boolean)
(defcustom gnus-registry-track-extra nil
- "Whether the registry should track other things about a message.
-The Subject header is currently the only thing that can be
-tracked this way."
+ "Whether the registry should track extra data about a message.
+The Subject and Sender (From:) headers are currently tracked this
+way."
:group 'gnus-registry
- :type 'boolean)
+ :type
+ '(set :tag "Tracking choices"
+ (const :tag "Track by subject (Subject: header)" subject)
+ (const :tag "Track by sender (From: header)" sender)))
(defcustom gnus-registry-entry-caching t
"Whether the registry should cache extra information."
;; alias puthash is missing from Emacs 20 cl-extra.el
(defalias 'puthash 'cl-puthash)))
+(defun gnus-registry-track-subject-p ()
+ (memq 'subject gnus-registry-track-extra))
+
+(defun gnus-registry-track-sender-p ()
+ (memq 'sender gnus-registry-track-extra))
+
(defun gnus-registry-cache-read ()
"Read the registry cache file."
(interactive)
(let* ((id (mail-header-id data-header))
(subject (gnus-registry-simplify-subject
(mail-header-subject 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"))
- (old-entry (gethash id gnus-registry-hashtb)))
+ (sender (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"))
+ (old-entry (gethash id gnus-registry-hashtb)))
(gnus-message 5 "Registry: article %s %s from %s to %s"
id
(if method "respooling" "going")
(gnus-registry-delete-group id from)
(when (equal 'copy action)
- (gnus-registry-add-group id from subject)) ; undo the delete
+ (gnus-registry-add-group id from subject sender)) ; undo the delete
- (gnus-registry-add-group id to subject)))
+ (gnus-registry-add-group id to subject sender)))
-(defun gnus-registry-spool-action (id group &optional subject)
+(defun gnus-registry-spool-action (id group &optional subject sender)
(let ((group (gnus-group-guess-full-name-from-command-method group)))
(when (and (stringp id) (string-match "\r$" id))
(setq id (substring id 0 -1)))
(gnus-message 5 "Registry: article %s spooled to %s"
id
group)
- (gnus-registry-add-group id group subject)))
+ (gnus-registry-add-group id group subject sender)))
;; Function for nn{mail|imap}-split-fancy: look up all references in
;; the cache and if a match is found, return that group.
nnmail-split-fancy-with-parent-ignore-groups))
(setq res nil)))
references))
- ;; there were no references, now try the extra tracking
- (when gnus-registry-track-extra
- (let ((subject (gnus-registry-simplify-subject
- (message-fetch-field "subject"))))
- (when (and subject
- (< gnus-registry-minimum-subject-length (length subject)))
- (maphash
- (lambda (key value)
- (let ((this-subject (cdr
- (gnus-registry-fetch-extra key 'subject))))
- (when (and this-subject
- (equal subject this-subject))
- (setq res (gnus-registry-fetch-group key))
- (gnus-message
- ;; raise level of messaging if gnus-registry-track-extra
- (if gnus-registry-track-extra 5 9)
- "%s (extra tracking) traced subject %s to group %s"
- "gnus-registry-split-fancy-with-parent"
- subject
- (if res res "nil")))))
- gnus-registry-hashtb)))))
+
+ ;; 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")))
+ (single-match t))
+ (when (and single-match
+ (gnus-registry-track-sender-p)
+ sender)
+ (maphash
+ (lambda (key value)
+ (let ((this-sender (cdr
+ (gnus-registry-fetch-extra key 'sender))))
+ (when (and single-match
+ this-sender
+ (equal sender this-sender))
+ ;; too many matches, bail
+ (unless (equal res (gnus-registry-fetch-group key))
+ (setq single-match nil))
+ (setq res (gnus-registry-fetch-group key))
+ (gnus-message
+ ;; raise level of messaging if gnus-registry-track-extra
+ (if gnus-registry-track-extra 5 9)
+ "%s (extra tracking) traced sender %s to group %s"
+ "gnus-registry-split-fancy-with-parent"
+ sender
+ (if res res "nil")))))
+ gnus-registry-hashtb))
+ (when (and single-match
+ (gnus-registry-track-subject-p)
+ subject
+ (< gnus-registry-minimum-subject-length (length subject)))
+ (maphash
+ (lambda (key value)
+ (let ((this-subject (cdr
+ (gnus-registry-fetch-extra key 'subject))))
+ (when (and single-match
+ this-subject
+ (equal subject this-subject))
+ ;; too many matches, bail
+ (unless (equal res (gnus-registry-fetch-group key))
+ (setq single-match nil))
+ (setq res (gnus-registry-fetch-group key))
+ (gnus-message
+ ;; raise level of messaging if gnus-registry-track-extra
+ (if gnus-registry-track-extra 5 9)
+ "%s (extra tracking) traced subject %s to group %s"
+ "gnus-registry-split-fancy-with-parent"
+ subject
+ (if res res "nil")))))
+ gnus-registry-hashtb))
+ (unless single-match
+ (gnus-message
+ 5
+ "gnus-registry-split-fancy-with-parent: too many extra matches for %s"
+ refstr)
+ (setq res nil))))
(gnus-message
5
"gnus-registry-split-fancy-with-parent traced %s to group %s"
(gnus-registry-add-group
(gnus-registry-fetch-message-id-fast article)
gnus-newsgroup-name
- (gnus-registry-fetch-simplified-message-subject-fast article)))))))
+ (gnus-registry-fetch-simplified-message-subject-fast article)
+ (gnus-registry-fetch-sender-fast article)))))))
(defun gnus-registry-fetch-message-id-fast (article)
"Fetch the Message-ID quickly, using the internal gnus-data-list function"
(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))))
+ nil))
+
(defun gnus-registry-grep-in-list (word list)
(when word
(memq nil
(remhash id value)))
gnus-registry-hashtb)))
-(defun gnus-registry-add-group (id group &optional subject)
+(defun gnus-registry-add-group (id group &optional subject sender)
"Add a group for a message, based on the message ID."
(when group
(when (and id
(list group))
gnus-registry-hashtb)
- (when gnus-registry-track-extra
- (gnus-registry-store-extra-entry
+ (when (and (gnus-registry-track-subject-p)
+ subject)
+ (gnus-registry-store-extra-entry
id
'subject
(gnus-registry-simplify-subject subject)))
+ (when (and (gnus-registry-track-sender-p)
+ sender)
+ (gnus-registry-store-extra-entry
+ id
+ 'sender
+ sender))
(gnus-registry-store-extra-entry id 'mtime (current-time)))))))