;; -*- emacs-lisp -*-
;;; gnus-mst-bbdb-split.el --- split groups according to bbdb data

;; Author: Mark Triggs <mst@dishevelled.net>
;; Keywords: news
;; $Id: gnus-mst-bbdb-split.el,v 1.15 2004/01/11 10:38:52 mst Exp $

;; This file 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)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; 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.

;;; Commentary:

;; This can be used by adding something like the following to your ~/.gnus:

;; (setq nnmail-split-fancy '(|
;;                              (: gnus-mst-bbdb-split 'gnus-group)
;;                              "misc"
;;                              ))

;;; Code:

(try-require 'bbdb)

(when (featurep 'bbdb)
  (defun gnus-mst-bbdb-split (property)
    (let* ((from (car (ietf-drums-parse-address (mail-fetch-field "from"))))
             (record (bbdb-search-simple nil from))
             (group (and record (bbdb-get-field record property))))
       (if (> (length group) 0)
           group
         nil)))


  (provide 'gnus-mst-bbdb-split))
;;; gnus-mst-bbdb-split.el ends here
