#EmacsConf backstage: adding notes to Org logbook drawers from e-mails
| emacs, emacsconf, notmuchSometimes I want to work with all the talks associated with an email in my inbox. For example, maybe a speaker said that the draft schedules are fine, and I want to make a note of that in the conference Org file.
First we start with a function that gets the e-mail addresses for a talk. Some speakers have different e-mail addresses for public contact or private contact, and some e-mail us from other addresses.
emacsconf-mail-get-all-email-addresses: Return all the possible e-mail addresses for TALK.
(defun emacsconf-mail-get-all-email-addresses (talk) "Return all the possible e-mail addresses for TALK." (split-string (downcase (string-join (seq-uniq (seq-keep (lambda (field) (plist-get talk field)) '(:email :public-email :email-alias))) ",")) " *, *"))
Then we can use that to find the talks for a given e-mail address.
emacsconf-mail-talks: Return a list of talks matching EMAIL.
(defun emacsconf-mail-talks (email) "Return a list of talks matching EMAIL." (setq email (downcase (mail-strip-quoted-names email))) (seq-filter (lambda (o) (member email (emacsconf-mail-get-all-email-addresses o))) (emacsconf-get-talk-info)))
We can loop over that to add a note for the e-mail.
emacsconf-mail-add-to-logbook: Add to logbook for all matching talks from this speaker.
(defun emacsconf-mail-add-to-logbook (email note) "Add to logbook for all matching talks from this speaker." (interactive (let* ((email (mail-strip-quoted-names (plist-get (plist-get (notmuch-show-get-message-properties) :headers) :From))) (talks (emacsconf-mail-talks email))) (list email (read-string (format "Note for %s: " (mapconcat (lambda (o) (plist-get o :slug)) talks", ")))))) (save-window-excursion (mapc (lambda (talk) (emacsconf-add-to-talk-logbook talk note)) (emacsconf-mail-talks email))))
The actual addition of notes is handled by these functions.
emacsconf-add-to-logbook: Add NOTE as a logbook entry for the current subtree.
(defun emacsconf-add-to-logbook (note) "Add NOTE as a logbook entry for the current subtree." (move-marker org-log-note-return-to (point)) (move-marker org-log-note-marker (point)) (with-temp-buffer (insert note) (let ((org-log-note-purpose 'note)) (org-store-log-note))))
Then we have a function that looks for the heading for a note and then adds a logbook entry to it.
emacsconf-add-to-talk-logbook: Add NOTE as a logbook entry for TALK.
(defun emacsconf-add-to-talk-logbook (talk note) "Add NOTE as a logbook entry for TALK." (interactive (list (emacsconf-complete-talk) (read-string "Note: "))) (save-excursion (emacsconf-with-talk-heading talk (emacsconf-add-to-logbook note))))
All together, that makes it easy to use Emacs as a very simple contact relationship management system where I can take notes based on the e-mails that come in.
These functions are in emacsconf-mail.el.