org-msg icon indicating copy to clipboard operation
org-msg copied to clipboard

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

Open molok opened this issue 1 year ago • 2 comments

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 avatar Jan 17 '24 13:01 molok

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 "@")))))))))))

molok avatar Jan 31 '24 00:01 molok

@molok Please review the pull request implementing this feature.

jeremy-compostella avatar Mar 19 '24 20:03 jeremy-compostella