Org-mode mailing list
 help / color / mirror / Atom feed
From: Tim Cross <theophilusx@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: How to use `open` to handle `message:*` links on macOS
Date: Fri, 30 Apr 2021 05:37:19 +1000
Message-ID: <87pmycj2y6.fsf@gmail.com> (raw)
In-Reply-To: <CAHa53uxN7vghznS943ucKgz1+TQHOVLH2eVnvivH1UkB6Ls_rg@mail.gmail.com>


Tim Visher <tim.visher@gmail.com> writes:

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

I think this would be great content to add to the worg site. Would you
be willing to add this, plus a short outline of the issue you needed to
resolve so that others might benefit from your experience?


-- 
Tim Cross


  parent reply	other threads:[~2021-04-29 19:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-11 19:44 Tim Visher
2021-01-11 21:57 ` Diego Zamboni
2021-01-15 14:12 ` Alexander Adolf
2021-04-29 16:21   ` Tim Visher
2021-04-29 16:28     ` Diego Zamboni
2021-04-29 19:37     ` Tim Cross [this message]
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://orgmode.org

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

  git send-email \
    --in-reply-to=87pmycj2y6.fsf@gmail.com \
    --to=theophilusx@gmail.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

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git