(add-to-list 'load-path (concat zonix-elisp-dir "bbdb/lisp"))
(add-to-list 'load-path (concat zonix-elisp-dir "bbdb/bits"))
(add-to-list 'Info-default-directory-list
(expand-file-name (concat zonix-elisp-dir "bbdb/texinfo")))
(add-to-list 'load-path (concat zonix-elisp-dir "bbdb-utils"))
(require 'bbdb)
(bbdb-initialize 'gnus 'message)
(setq bbdb-send-mail-style 'compose-mail)
(add-hook 'message-setup-hook 'bbdb-define-all-aliases)
(add-hook 'message-setup-hook 'mail-abbrevs-setup)
(require 'message)
(define-key message-minibuffer-local-map [(tab)] 'bbdb-complete-name)
(setq bbdb-user-mail-names gnus-ignored-from-addresses)
(setq bbdb-default-country nil)
(setq bbdb-north-american-phone-numbers-p nil)
(setq bbdb-dwim-net-address-allow-redundancy t)
(setq bbdb-complete-name-allow-cycling t)
(setq bbdb-completion-type nil)
(setq bbdb-offer-save 'auto)
(setq bbdb-address-editing-function 'bbdb-address-edit-continental)
(setq bbdb-continental-zip-regexp
"^\\s *\\([A-Z][A-Z]?\\s *-\\s *\\)?[0-9][0-9][0-9]")
(setq window-min-height 1)
(setq bbdb-pop-up-target-lines 1)
(setq bbdb-pop-up-display-layout 'multi-line)
(add-hook 'bbdb-notice-hook 'bbdb-auto-notes-hook)
(setq bbdb-auto-notes-alist
(list
'("Organization" (".*" company 0))
'("Organisation" (".*" company 0))
'("Newsgroups" ("[^,]+" newsgroups 0))
'("X-BeenThere" (".*" mailinglists 0))
'("X-Mailing-List" (".*" mailinglists 0))
'("Mailing-List" (".*" mailinglists 0))
'("Errors-To" (".*" mailinglists 0))
'("List-Post" (".*" mailinglists 0))
'("Subject" (".*" subjects 0))
'("X-Now-Playing" (".*" playlist 0))
'("User-Agent" (".*" mailer 0))
'("X-URL" (".*" www 0))
'("X-Mailer" (".*" mailer 0))
'("X-Newsreader" (".*" mailer 0))
))
(setq rs-bbdb-ignored-from-list
'("member@orkut.com"
"me@privacy.net"
"@public.gmane.org"))
(setq bbdb/news-auto-create-p nil)
(setq bbdb/news-auto-create-hook 'bbdb-ignore-some-messages-hook)
(setq bbdb/mail-auto-create-p 'bbdb-ignore-some-messages-hook)
(setq bbdb-ignore-some-messages-alist
`(("From" . , (regexp-opt rs-bbdb-ignored-from-list))))
(setq bbdb-notes-default-separator "\n")
(add-hook 'bbdb-notice-hook 'bbdb-timestamp-hook)
(add-hook 'bbdb-create-hook 'bbdb-creation-date-hook)
(require 'bbdb-obsolete-net "bbdb-obsolete")
(setq bbdb-canonicalize-net-hook
'(lambda (addr)
(cond ((string-match
"\\`\\([^=-]+\\)[=-].*public\.gmane\.org\\'" addr)
(concat (substring addr (match-beginning 1) (match-end 1)) "@public.gmane.org"))
((string-match
"\\`\\([^0-9]+\\)\\(-\\(dated\\|exp\\)-[^@]+\\|-[0-9ABCDEF]+\\|\\+[^@]+\\)\\(@.*\\)\\'"
addr)
(concat (substring addr (match-beginning 1) (match-end 1))
(substring addr (match-beginning 4) (match-end 4))))
(t (bbdb-obsolete-net-canonicalize-net-hook addr)))))
(defun ulmer:bbdb-trim-notes (record field num-to-keep)
"Remove all but the first some lines from a notes field of a BBDB
record. Meant to be added to bbdb-notice-hook."
(let* ((sep (get field 'field-separator))
(foo (reverse
(split-string
(or (bbdb-record-getprop record field) "")
sep)))
(new-field ""))
(while (and (> num-to-keep 0) (> (length foo) 0))
(if (> (length (car foo)) 0)
(setq new-field (concat (car foo)
(if (> (length new-field) 0)
(concat sep new-field)
""))
num-to-keep (- num-to-keep 1)))
(setq foo (cdr foo)))
(and (> (length foo) 0)
(bbdb-record-putprop record field new-field))))
(defun ulmer:bbdb-trim-subjects (record)
(ulmer:bbdb-trim-notes record 'subjects 20))
(defun ulmer:bbdb-trim-playlist (record)
(ulmer:bbdb-trim-notes record 'playlist 20))
(defun ulmer:bbdb-trim-mailer (record)
(ulmer:bbdb-trim-notes record 'mailer 20))
(defun ulmer:bbdb-trim-newsgroups (record)
(ulmer:bbdb-trim-notes record 'newsgroups 20))
(defun ulmer:bbdb-trim-company (record)
(ulmer:bbdb-trim-notes record 'company 3))
(put 'subjects 'field-separator "\n")
(put 'playlist 'field-separator "\n")
(put 'mailer 'field-separator "\n")
(put 'newsgroups 'field-separator "\n")
(add-hook 'bbdb-notice-hook 'ulmer:bbdb-trim-subjects)
(add-hook 'bbdb-notice-hook 'ulmer:bbdb-trim-playlist)
(add-hook 'bbdb-notice-hook 'ulmer:bbdb-trim-mailer)
(add-hook 'bbdb-notice-hook 'ulmer:bbdb-trim-newsgroups)
(add-hook 'bbdb-notice-hook 'ulmer:bbdb-trim-company)
(add-hook 'bbdb-load-hook (function (lambda () (require 'bbdb-print))))
(setq bbdb-print-require t)
(require 'bbdb-query)
(global-set-key [C-f10] 'bbdb-create)
(global-set-key [C-f11] 'bbdb-query)
(setq bbdb-elided-display nil)
(add-hook 'gnus-exit-group-hook
'(lambda nil
(let ((buf (get-buffer "*BBDB*")))
(when buf
(bury-buffer buf)))))
(require 'bbdb-pgp)
(defun bbdb-switch-to-other-bbdb-file (&optional db dont-ask)
(interactive)
(bbdb-save-db)
(unless db
(setq db (if dont-ask (expand-file-name "~/.bbdb")
(read-file-name "Use bbdb database "))))
(setq bbdb-file db
bbdb-buffer (get-file-buffer db)))
(defun wolf3-bbdb-add-recipients-to-bbdb ()
"Add all recipients to BBDB, using this list of headers:
from, sender,
to, cc, bcc,
resent-from, resent-to, resent-cc, resent-bcc."
(let ((fields '("from" "sender"
"to" "cc" "bcc"
"resent-from" "resent-to" "resent-cc" "resent-bcc")))
(mapc
(lambda (address)
(bbdb-annotate-message-sender address t t t))
(save-restriction
(message-narrow-to-headers)
(message-tokenize-header (mapconcat 'message-fetch-field fields ","))))))