5

Q: how can I automate inbox zero with my org-mode agenda by getting linked, deadlined reminders to emails that need a reply?

I get a lot of email, and try to stay at inbox zero, but I don't always want to reply to an email immediately upon reading it. I do, however, want to remind myself that I need to reply.

I'm hoping to automate this recurring use pattern, described here in excruciating detail:

  1. open up inbox (using mu4e)
  2. mark an email for reply with org-store-link
  3. refile that message to All Mail (or wherever; it's a gmail account)
  4. go to my main agenda file (call it agenda.org)
  5. go to the * EMAIL section
  6. use org-insert-link to create a new entry ** Respond to XXXX
  7. set a deadline for later in the day (or tomorrow, or whenever)

The end product is a series of entries in the EMAIL section, each linked to a specific email that needs a reply, and each with a defined deadline so that it will show up in my agenda view to remind me. I'm just not sure how to automate the whole thing.

Does something like this already exist and I just don't know about it? If not, how would one implement it?

PS: I'm loosely aware of mu4e actions, which I expect would be the starting point, but it's also package-specific and wouldn't apply to, say, gnus.

  • 1
    It seems to me that org-capture would be the most natural solution. There's an example here, which does half of what you want. What's missing is refiling the message and adding a deadline. – legoscia Aug 12 '15 at 14:19
  • @legoscia: thanks for the suggestion. I ended up rolling my own and got something that seems to do everything I'm looking for. Hopefully it doesn't turn out to be too fragile. – Dan Aug 12 '15 at 18:39
4

Turns out that it's pretty straightforward to put this function together, although there's a bunch of housekeeping to keep the buffers tidy. The following command words with mu4e in both its headers and view modes. It's minimally tested at this point, but seems to be working in the main. Note that it hard codes a few things such as the section heading and the specific file.

(defun mu4e-msg-to-agenda (arg)
  "Refile a message and add a entry in the agenda file with a
deadline.  Default deadline is today.  With one prefix, deadline
is tomorrow.  With two prefixes, select the deadline."
  (interactive "p")
  (let ((file (car org-agenda-files))
        (sec  "^* EMAIL\\s-*$")
        (msg  (mu4e-message-at-point)))
    (when msg
      ;; put the message in the agenda
      (with-current-buffer (find-file-noselect file)
        (save-excursion
          ;; find header section
          (goto-char (point-min))
          (when (re-search-forward sec nil t)
            (let ((org-M-RET-may-split-line)
                  (lev (org-outline-level))
                  (folded-p (invisible-p (point-at-eol))))
              ;; place the subheader
              (when folded-p (show-branches))    ; unfold if necessary
              (org-end-of-meta-data-and-drawers) ; skip property drawer
              (org-insert-todo-heading 1)        ; insert a todo heading
              (when (= (org-outline-level) lev)  ; demote if necessary
                (org-do-demote))
              ;; insert message and add deadline
              (insert (concat "respond to "
                              "[[mu4e:msgid:"
                              (plist-get msg :message-id) "]["
                              (caar (plist-get msg :from)) "]] "))
              (org-deadline nil
                            (cond ((= arg 1) (format-time-string "%Y-%m-%d"))
                                  ((= arg 4) "+1d")))
              ;; refold as necessary
              (if folded-p
                  (progn
                    (org-up-heading-safe)
                    (hide-subtree))
                (hide-entry))))))
      ;; refile the message and update
      (cond ((eq major-mode 'mu4e-view-mode)
             (mu4e-view-mark-for-refile))
            ((eq major-mode 'mu4e-headers-mode)
             (mu4e-headers-mark-for-refile)))
      (message "Refiled and added to the agenda for %s"
               (cond ((= arg 1) "today")
                     ((= arg 4) "tomorrow")
                     (t         "later"))))))

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.