jeremy-compostella / org-msg

OrgMsg is a GNU/Emacs global minor mode mixing up Org mode and Message mode to compose and reply to emails in a Outlook HTML friendly style.
GNU General Public License v3.0
278 stars 60 forks source link

[Feature Request] Addressee tagging generating a mailto link in the message body #179

Open molok opened 8 months ago

molok commented 8 months ago

In my work environment (Outlook based) I often see people tagging each other using @Name, which in Outlook actually generates a mailto link. I think it might be appropriate to have this kind of feature in org-msg.

molok commented 8 months ago

example of such function

(defun org-msg-tag-addressee()
  "Completes an email address in the current buffer with an org-mode mailto link"
  (interactive)
  (let* ((addressees
          (append
           (mail-extract-address-components (org-msg-message-fetch-field "to") t)
           (mail-extract-address-components (org-msg-message-fetch-field "cc") t)))
         (mail-addresses (mapcar (lambda(e)
                                   (if (car e)
                                     (format "%s <%s>" (car e) (cadr e))
                                     (format "<%s>" (cadr e)))) addressees))
         (end (point))
         (start (save-excursion
                  (skip-chars-backward "^@")
                  (point)))
         (prefix (buffer-substring start end))
         (completion (completing-read "Complete email for: "
                                      mail-addresses
                                      (lambda (c)
                                        (string-match-p (regexp-quote prefix)
                                                        (downcase c)))
                                      t)))
    (if (not (string-equal prefix completion))
        (progn
          (delete-region (- start 1) end)
          (insert
            (if (string-match "\\(.*\\) <\\(.*\\)>" completion)
                (let ((name (match-string 1 completion))
                      (email (match-string 2 completion)))
                  (format "[[mailto:%s][@%s]]" email name))
              (if (string-match "<\\(.*\\)>" completion)
                  (let ((email (match-string 1 completion)))
                    (format "[[mailto:%s][@%s]]" email (car (split-string email "@")))))))))))
jeremy-compostella commented 6 months ago

@molok Please review the pull request implementing this feature.