;I've added a bit of lisp to the regular bbdb-ignore-most-messages hook
;so that clauses in the bbdb-ignore-most-messages-alist can be ANDed
;together as well as the implicit ORing already provided.  

;I added this because while reading news, I want bbdb to notice people
;from my company (Oracle) and alma-mater (Stanford) except when those
;people are posting to company (oracle.*) or alma-mater (su.*) specific
;newgroups.

;Here is the elisp (I have only used this with emacs-19):

(defun marks-bbdb-ignore-most-messages-hook (&optional invert-sense)
  "For use as the value of bbdb/news-auto-create-p or bbdb/mail-auto-create-p.
This will automatically create BBDB entries for messages which match
the bbdb-ignore-some-messages-alist (which see) and *no* others."
  ;; don't need to optimize this to check the cache, because if
  ;; bbdb/*-update-record uses the cache, this won't be called.
  (let ((rest (if invert-sense
                  bbdb-ignore-some-messages-alist
                  bbdb-ignore-most-messages-alist))
        (case-fold-search t)
        (done nil)
        (hit t)
        (b (current-buffer))
        (marker (bbdb-header-start))
        field regexp fieldval)
    (set-buffer (marker-buffer marker))
    (save-restriction
      (widen)
      (while (and rest (not done))
        (goto-char marker)
        ;; while loop added in - maw
        (setq clause (car rest))
        (while (and clause hit)
          ;; This allows ANDing values from multiple fields. Alist entries
          ;; can be of the form ((HEADER . REGEXP)[(HEADER . REGEXP)...])
          ;; or of the form (HEADER . REGEXP) This is an extension of
          ;; the regular features of bbdb 1.48.
          (if (listp (car clause))
              (setq field (car (car clause))
                    regexp (cdr (car clause))
                    fieldval (bbdb-extract-field-value field)
                    clause (cdr clause))
            (setq field (car clause)
                  regexp (cdr clause)
                  fieldval (bbdb-extract-field-value field)))
          (if (and fieldval (string-match regexp fieldval))
              (setq hit t)
            (setq hit nil)))
        (setq rest (cdr rest)
              done hit)))
    (set-buffer b)
    (if invert-sense
        (not done)
        done)))


;; Here is a sample use of the ANDing...
;;(setq bbdb-ignore-most-messages-alist
;;      '((("Organization" . "[Oo]racle\\|[Ss]tanford")
;;       ("Newsgroup"."[^s][^u]\\|[^o][^r]"))))

;
; Mark
;___________________________________________________________________________
;[EMAIL PROTECTED]           Fax: 415-506-1113       RIPEM key on server
                             

Reply via email to