Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using org-capture-templates with mu4e

I'm trying to create a template using org-capture templates when using mu4e. When viewing a message in mu4e:view mode, I can call org-capture-templates with a keystroke and then add a reminder in a file with a link to the message. Something like this:

* NEXT Respond to Person A on Message Subject 
SCHEDULED: <2013-06-22 Sat>
[2013-06-22 Sat 22:05]
Email subject linked to mu4e message

Here's the template in my .emacs:

(setq org-capture-templates
(quote (("r" "respond" entry (file "~/refile.org")
"* NEXT Respond to %:from on %:subject\nSCHEDULED: %t\n%U\n%a\n\n" 
 :clock-in t :clock-resume t :immediate-finish t)))) 

But the variables in section 9.1.3.2 of the orgmode official manual are not set in mu4e. My guess is it should be set in the following function in org-mu4e.el. See the 3 lines marked by a comment I added, but this does not solve the problem. The link (%a) gets initialized, but not :to, :from and :subject.

If I debug, I can see the function call to org-store-link-props looks like this:

org-store-link-props(:type "mu4e" :from (("Person Name" . "[email protected]"))
:to (("Me Surname" . "[email protected]")) :subject "Re: Subject of Email" 
:message-id "message-id")

However, the template evaluates to:

* NEXT Respond to %:from on %:subject
SCHEDULED: <2013-06-23 Sun>
[2013-06-23 Sun 21:08]

Thanks for the help - this is the final function that works for me:

(defun org-mu4e-store-link ()
"Store a link to a mu4e query or message."
(cond
 ;; storing links to queries
 ((eq major-mode 'mu4e-headers-mode)
  (let* ((query (mu4e-last-query))
      desc link)
(org-store-link-props :type "mu4e" :query query)
(setq
  desc (concat "mu4e:query:" query)
  link desc)
(org-add-link-props :link link :description desc)
link))
  ;; storing links to messages
((eq major-mode 'mu4e-view-mode)
  (let* ((msg  (mu4e-message-at-point))
     (msgid   (or (plist-get msg :message-id) "<none>"))
     (from (car (car (mu4e-message-field msg :from))))
     (to (car (car (mu4e-message-field msg :to))))
     (subject (mu4e-message-field msg :subject))
     link)
   (setq link (concat "mu4e:msgid:" msgid))
   (org-store-link-props :type "mu4e" :link link
             :message-id msgid)
   (setq link (concat "mu4e:msgid:" msgid))
   (org-store-link-props 
    :type "mu4e" :from from :to to :subject subject
          :message-id msgid)

   (org-add-link-props :link link
           :description (funcall org-mu4e-link-desc-func msg))
   link))))

(org-add-link-type "mu4e" 'org-mu4e-open)
(add-hook 'org-store-link-functions 'org-mu4e-store-link)
like image 843
cheese Avatar asked Jun 22 '13 20:06

cheese


1 Answers

Something like this should work:

(setq from
   (let ((first (car (mu4e-message-field-at-point :from))))
     (if (car first)
       (format "%s <%s>" (car first) (cdr first))
       (cdr first))))
like image 53
djcb Avatar answered Nov 15 '22 08:11

djcb