Hi, I keep an automatic field (mail-folder) that's the vm mail folder
for the person.  I create it automatically with

   bbdb-auto-notes-alist '(
                           ("Newsgroups" (".*" newsgroup 0))
                           ("Organization" (".*" company 0 t))
                           ("From" (".*" mail-folder gec-auto-folder-create t))
                           )

using

;; these regexps also appear in vm-auto-folder-alist
;; this function when called by bbdb-auto-notes-hook will add a
;; mail-folder field to the current entry based on the current From
;; header.  bbdb doesn't seem to offer a way to not do this if the
;; field doesn't already exist, so we have to make that check
;; ourselves.  If the clever (written by someone else) regexps fail,
;; prompt the user for a value.
(defun gec-auto-folder-create (string)

  (let
      (
       (old-field-value (bbdb-record-getprop record 'mail-folder))
       )
    (setq string
          (cond (old-field-value old-field-value)
                ((string-match "<\\([^>@%]+\\)" string)
                 (substring string (match-beginning 1) (match-end 1)))
                ((string-match "\\([^@%]+\\)[@%]" string)
                 (substring string (match-beginning 1) (match-end 1)))
                ((string-match "\\(\\w+\\) " string)
                 (substring string (match-beginning 1) (match-end 1)))
                (t (read-string "Enter mail-folder for this entry: " nil))))
    string))


I want this field to have a sticky value; once it's set on a record, I
never want it to automatically change to anything else.  Thus if
someone's email address keeps changing, I'll still have the same
folder (I have other code from someone else that advises the vm save
routine to make the default be the appropriate field for the sender of
the message).

I accomplished this with the above unpleasant hack of referencing the
free variable record so I could check to see if the record already has
a mail-folder field, and return that original value if so.

Is there a cleaner way to do this?  Should there be?

Since I already had a sizable bbdb database when I started using this,
I don't want to simply make it part of the record creation process.  I
do want to automatically add this field to existing record as more
mail comes in.

Also, when I merge two records who both have mail-folder fields, I end
up with a merged mail-folder field which I generally edit manually.
Can I hook my way out of this one?

Thanks for any assistance.

P.S. I finally grepped in .elc files instead of .el files and found
what was bugging me.




Reply via email to