6
votes

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)
1
Okay, made some progress. Seems like mu4e-message-field returns a the emails as (("Name Surname" . "[email protected]")). So if I change that to a string with something like two calls of car it sort of works, unless the from field in the mail doesn't have a name and email, like "Name Surname <[email protected]>". Not an elegant solution at all, but works for now. - cheese
Another way of going from a list of lists to a string would work better? - cheese
If you look at section 'Message functions' in the manual (it seems SO doesn't let me format this as something very readable...): The contact fields (To, From, Cc, Bcc) are lists of cons-pairs ‘(name . email)’; ‘name’ may be ‘nil’. So, for example: (mu4e-message-field some-msg :to) ;; => (("Jack" . "[email protected]") (nil . "[email protected]")) - djcb
@cheese where you able to get this setup up and running properly? - tatsuhirosatou
yes, thanks for the help djcb - cheese

1 Answers

4
votes

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