5

I'm using org-mode and mu4e. I'd like to have each email become the active link so that I can link to it in Org. When viewing an email, I can C-c C-l (bound to (org-store-link)) to make a link to it, and then elsewhere in Org C-c l to paste the link. I'd like the (org-store-link) part to happen automagically each time I send an email.

I've found two hooks: message-send-hook and message-sent-hook but am not sure where to call (org-store-link). I've tried that in a function on each hook, but it doesn't work. I think there is additional trickery to catch the just-sent (or sending) message.

3

My first suggestion would be to try the following.

(add-hook 'message-send-hook (lambda () (org-store-link nil)))

Since you said you tried the hook, another way is to just combine org-store-link and message sending into a single function.

(defun store-link-then-send-message ()
  "Call `org-store-link', then send current email message."
  (interactive)
  (call-interactively #'org-store-link)
  (call-interactively #'message-send-and-exit))

(define-key mu4e-compose-mode-map "\C-c\C-c" #'store-link-then-send-message)

This assumes you're using message-send-and-exit to send the message. You could do something identical with the message-send command.

(define-key mu4e-compose-mode-map "\C-c\C-c" #'store-link-then-send-message)
  • The latter works, sort-of. It stores a link to the file, not a link to the message (message ID). I found code that seems to implement what I want, but it appears surprisingly overly-complex for this simple task (although, granted, not simple enough that I have been able to figure it out myself). That code is here: github.com/danieroux/emacs/blob/master/mine/djr-mu4e.el – mankoff Sep 24 '14 at 12:24
  • @mankoff When you call org-store-link manually, does it link to the file or the message? If it links to the messaage, when are you calling it (before or after sending)? – Malabarba Sep 24 '14 at 12:27
  • djcbsoftware.nl/code/mu/mu4e/Creating-org_002dmode-links.html When viewing messages, org-store-link stores a link to the message. When viewing headers, to the search that created that header view. When editing a draft, it stores it to the file. Probably because "msgid" or other such fields aren't yet set? After sending, it stores a link to the header/message visible, not the just-sent message. – mankoff Sep 24 '14 at 12:33
  • @mankoff I see. I was misled because on the regular message-mode a Message-ID field is created for you when you call org-store-link, even if the message isn't sent. I'll try to figure how mu4e does it. – Malabarba Sep 24 '14 at 12:43
2

Danie Roux developed a solution. See:

https://github.com/danieroux/emacs/blob/master/mine/djr-org-mu4e-capture-sent.el

His instructions are:

  • Define djr/mu4e-org-mode-capture-template-for-sent-email
  • Then, either:
    • Call djr/mu4e-compose-new-with-follow-up
    • Or set djr/org-mu4e-must-capture-message

After sending an email, org-capture will be called with that template. %a will be the link to that email.

org-insert-link will have the email in the list of links, regardless of whether you set the flag or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.