emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tim Visher <tim.visher@gmail.com>
To: Alexander Adolf <alexander.adolf@condition-alpha.com>
Cc: Emacs Org Mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: How to use `open` to handle `message:*` links on macOS
Date: Thu, 29 Apr 2021 12:21:47 -0400	[thread overview]
Message-ID: <CAHa53uxN7vghznS943ucKgz1+TQHOVLH2eVnvivH1UkB6Ls_rg@mail.gmail.com> (raw)
In-Reply-To: <2acd022ab06f7f7e2fbe74a6b42d816a@condition-alpha.com>

[-- Attachment #1: Type: text/plain, Size: 2964 bytes --]

Hi Diego and Alexander,

Thanks for the tips here. I finally got around to trying them out. Here's
what I ended up with and it's working perfectly.

(defun timvisher-org-link-mac-mail-open-link
    (mid _)
  (start-process "open-link" nil "open" (format "message://%%3C%s%%3E"
                                                mid)))

(defun timvisher-org-link-mac-mail-add-message-links
    ()
  (org-link-set-parameters
   "message" :follow #'timvisher-org-link-mac-mail-open-link))

(eval-after-load 'org
  '(timvisher-org-link-mac-mail-add-message-links))

Pairing that with my org-capture TODO Current Mail Template is a dream come
true. :)

(defun timvisher-org-current-mail-get-selected-message-subject
    ()
  (with-temp-buffer
    (call-process
     "osascript" nil t nil
     "-e" "tell application \"Mail\" to get subject of item 1 of
(selection as list)")
    (buffer-substring-no-properties (point-min) (- (point-max) 1))))

(defun timvisher-org-current-mail-get-selected-message-id
    ()
  (with-temp-buffer
    (call-process
     "osascript" nil t nil
     "-e" "tell application \"Mail\" to get message id of item 1 of
(selection as list)")
    (browse-url-url-encode-chars
     (buffer-substring-no-properties (point-min) (- (point-max) 1))
     "[/]")))

(defun timvisher-org-current-mail-get-link-string
    ()
  (let ((subject (timvisher-org-current-mail-get-selected-message-subject))
        (message-id (timvisher-org-current-mail-get-selected-message-id)))
    (org-link-make-string (format "message:%s" message-id)
                          subject)))

(defun timvisher-org-current-mail-get-body-quote-template-element
    ()
  (let ((body (setq body (with-temp-buffer
                 (call-process
                  "osascript" nil t nil
                  "-e" "tell application \"Mail\" to get content of
item 1 of (selection as list)")
                 (buffer-substring-no-properties (point-min) (-
(point-max) 1))))))
    (format "
  #+begin_quote%s  #+end_quote"
            (string-join
             (seq-reduce
              (lambda (acc next)
                (if (string= next (or (car (last acc)) ""))
                    acc
                  (append acc (list next))))
              (mapcar (lambda (string)
                        (let ((string (string-trim string)))
                          (if (string= "" string)
                              string
                            (format "  %s" string))))
                      (split-string body "\n"))
              '())
             "\n"))))

(setq org-capture-templates
      '(…
        ("twcm" "TODO Work Current Mail" entry
         (file+headline "~/Dropbox/todo/work.org" "Inbox")
         "* TODO %(timvisher-org-current-mail-get-link-string)
  %U%(timvisher-org-current-mail-get-body-quote-template-element)"
:prepend t :immediate-finish t)
        …))

Thanks so much! :)

[-- Attachment #2: Type: text/html, Size: 6720 bytes --]

  reply	other threads:[~2021-04-29 16:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 19:44 How to use `open` to handle `message:*` links on macOS Tim Visher
2021-01-11 21:57 ` Diego Zamboni
2021-01-15 14:12 ` Alexander Adolf
2021-04-29 16:21   ` Tim Visher [this message]
2021-04-29 16:28     ` Diego Zamboni
2021-04-29 19:37     ` Tim Cross
2021-04-29 21:01       ` Tim Visher
2021-04-29 23:38     ` Alexander Adolf
2021-05-02 20:58       ` Tim Visher
2021-05-06 17:04         ` Alexander Adolf
2021-05-06 17:38           ` Tim Visher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHa53uxN7vghznS943ucKgz1+TQHOVLH2eVnvivH1UkB6Ls_rg@mail.gmail.com \
    --to=tim.visher@gmail.com \
    --cc=alexander.adolf@condition-alpha.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).