Adding Mail-Abbrev Expansion to Org-MIME

Adding Mail-Abbrev Expansion to Org-MIME

As has been already mentioned, I overcome the temptation to use one of Emacs’ mail-clients. Yet still, I frequently use message-send-mail from within Emacs with a message-body composed with org-mime-subtree. You will find org-mime in the /contrib directory of your org-mode installation. Since manually filling the mail-header is redundant especially for buffers frequently (re)used, I set related properties to the current subtree that org-mime-send-subtree will parse before creating the email buffer. Unfortunately there is no built-in completion for addresses, which is why I use the following code. Apparently it’s wise to set alias_file in Mutt and mail-personal-alias-file in Emacs to the same file. It’s probably worth pointing out that I remove the commas introduced by define-mail-alias that separate the address from the definition in an alias.

(defvar org-mime-properties '("MAIL_TO" "MAIL_CC" "MAIL_BCC")
  "Properties `org-mime-send-subtree' parses.")

(setq mail-aliases-only
      ;; first build `mail-aliases', then create a string for `org-set-property'.
      (mapconcat 'car (build-mail-aliases) " "))

;; hook to replace the alias in the property field with name and email
(defun bp/mail-property-changed (property value)
  (let ((el (cdr (assoc value mail-aliases))))
    (when (and el (member property org-mime-properties))
      (org-set-property
       property
       (replace-regexp-in-string "," "" el)))))

(nconc org-default-properties org-mime-properties)
(nconc org-global-properties
       `(("MAIL_TO_ALL"         . ,mail-aliases-only)
         ("MAIL_BCC_ALL"        . ,mail-aliases-only)
         ("MAIL_CC_ALL"         . ,mail-aliases-only)))
(add-to-list 'org-property-changed-functions
             'bp/mail-property-changed)
Mutt Elisp