org-mac-message.el – linking to messages in OS X Mail.app

{Back to Worg's contibutions index}

The org-mac-message.el library provides various methods for linking to OS X Mail.app messages from within org-mode.

Installation

  • To load org-mac-message.el by default:
    (add-to-list 'org-modules 'org-mac-message)
    

    Note that org-modules must be set before org-mode is loaded.

  • Configure the default Mail.app account you would like to use:
    (setq org-mac-mail-account "account")
    

Usage

org-mac-message.el will create links with the format:

[[message://message-ID][Subject]]

When followed, these links will open the relevant message in Mail.app.

New functions

(org-mac-message-insert-selected)

Inserts formatted list of links at point to selected messages in Mail.app.

To ensure backwards compatability, (org-mac-message-insert-link) is aliased to this function.

(org-mac-message-insert-flagged (org-buffer org-heading))

Asks for an org buffer and heading within it. If the heading does not exist, create it at `point-max'.

Warning: the next step is destructive

Search for flagged mail in Mail.app and insert a formatted list. Delete all message:// links within the heading's first level. of links under the specified heading.

If you have Growl installed, notifications will inform you of the progress of the AppleScript search.

(org-mac-message-get-links (select-or-flag)

Searches for selected messages or flagged messages in the Mail.app account specified by org-mac-mail-account. Creates a formatted list of these links and copies them to the kill-ring.

Examples of usage

The following function will search the account Gmail for flagged messages and insert them in the org-mode buffer taskpool.org under the heading Flagged mail.

(defun my-mail-import ()
  (let ((org-mac-mail-account "Gmail"))
    (org-mac-message-insert-flagged "taskpool.org" "Flagged mail")))

This function could then be linked to from an org-mode buffer:

[[elisp:(my-mail-import)][Flagged%20Gmail]]

or set as a command in the agenda dispatcher:

(setq org-agenda custom-commands
      '(("F" "Import links to flagged mail" agenda ""
         ((org-agenda-mode-hook
           (my-mail-import))))))