girzel / ebdb

An EIEIO port of BBDB, Emacs' contact-management package
67 stars 12 forks source link

Code example for implementing auto-notes functionality #96

Open matsl opened 3 years ago

matsl commented 3 years ago

Hi,

In commit https://github.com/girzel/ebdb/commit/d7bc0c920b97f8dafec00793826a1298821f898a the auto-notes feature was dropped. It would be nice if there was some code samples on how you could implement a feature like that in order to automatically populating you own fields.

I have particular found great use of storing the subject line using BBDB and would like to implement that for EBDB. So I'm not asking for something fully customizable but rather specialized for just the subject line. (Which hopefully is much simpler.)

Yours Mats

girzel commented 3 years ago

Hi Mats,

The current tools aren't all that easy to use, it's true. The "Noticing and Automatic Rules" section of the manual gives the bare-bones, but it's not too clear how one would use it.

I can provide more examples in the manual, but I wonder if some more convenient code tools are in order, as well. You can get the information you need using the function ebdb-mua-message-header, like so:

(defun my-test-notice-func (_rec _type)
  (let ((subject (ebdb-mua-message-header "Subject")))
    (message "Subject is %s"
         (message-simplify-subject subject))))

(add-hook 'ebdb-notice-record-hook #'my-test-notice-func)

But what isn't clear is how to update or edit a record's existing field with a new value, which can actually be a little bit difficult. I think I should probably provide some short-cut functions for doing that.

What exactly would you like your function to do? What kind of information do you need in the hook, and what would you expect to be able to do to the record in question?

matsl commented 3 years ago

Hi Eric,

I would like to store the subject of the last received mail in the record.

As I'm typing I realize that can be tricky. In BBDB it kicks in when I manually hit bbdb-mua-display-sender. But in the best of world I would want it to whenever I read an unread article the subject line would be inserted in a last-received field in the record for that user. If I move around re-reading articles from that user the field should not be updated.

As an extra bonus if a last-sent field could be populated when I send mail to users I have in my EBDB I think that would be useful as well.

girzel commented 3 years ago

Okay, I quite understand what you're after. First of all, just FYI, I've just pushed a change to master that adds a little more documentation about automatically updating records, as well as a couple of new convenience functions for setting notes and tags. Come to think of it that section could still use some full examples, I'll add that maybe over the weekend. I haven't released this change yet, but it's here on Github.

For your specific request, I've also wanted the same thing, and have implemented it unfortunately as a part of a separate package, Gnorb. Actually, there's a whole "in between" package that does exactly this and nothing more, and you can see the code here:

https://git.savannah.gnu.org/gitweb/?p=emacs/elpa.git;a=blob;f=ebdb-gnorb.el;h=f2107378abc7a7434a32bee4253bcce0656e01ef;hb=refs/heads/externals/ebdb-gnorb

This might do more than you wanted! But it handles the question of last-seen vs last-received, lets you store references to multiple messages, and turns the references into clickable links so you can jump to the message.

Looking at the code, there's almost no reason why this would need to belong to the Gnorb package at all. I only see one gnorb-* function being used in there, and it would be easy to replace. If I did that, all this code could be moved into the EBDB package, in ebdb-gnus.el.

In fact, it might not be too hard to remove the dependencies on Gnus, either, in which case the field type could be generalized to work with all the MUAs that EBDB supports. It might take a while to do that. In the meantime, you could refer to the library linked above to implement something for yourself, or wait until I've moved it into EBDB and use it from there.

matsl commented 3 years ago

Hi Eric,

Thanks for putting this together but after I had a look at this I'm afraid I would still need a simple code example to get going. It is probably easy if I would have known more about eieio but if I could short circuit that learning effort it would be great.