From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Suckling Subject: [ANN] OS X only: Insert links to flagged emails Date: Thu, 19 Mar 2009 19:07:46 +0000 Message-ID: Mime-Version: 1.0 (Apple Message framework v930.3) Content-Type: multipart/mixed; boundary=Apple-Mail-7--663054427 Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LkNaw-0002of-C2 for emacs-orgmode@gnu.org; Thu, 19 Mar 2009 15:07:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LkNar-0002nk-Mx for emacs-orgmode@gnu.org; Thu, 19 Mar 2009 15:07:57 -0400 Received: from [199.232.76.173] (port=57709 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LkNar-0002nh-IS for emacs-orgmode@gnu.org; Thu, 19 Mar 2009 15:07:53 -0400 Received: from mail-ew0-f160.google.com ([209.85.219.160]:36509) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LkNaq-0000mI-U4 for emacs-orgmode@gnu.org; Thu, 19 Mar 2009 15:07:53 -0400 Received: by ewy4 with SMTP id 4so817913ewy.42 for ; Thu, 19 Mar 2009 12:07:51 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode Mailinglist --Apple-Mail-7--663054427 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit All, For various reasons (mainly Spotlight and an excess of HTML mail send by employers), I've migrated back to Mail.app after some time in Mutt (and how I miss the speed and threading). I habitually flag mails that need attention at a later date, and rather than use both org-mode and Mail.app to keep track of what needs doing, I've written a couple of hybid elisp AppleScript functions to suck links to my flagged email into org-mode. More details in the attached file. Comments and improvements welcome. Best, Christopher --Apple-Mail-7--663054427 Content-Disposition: attachment; filename=org-mac-flagged-mail.el Content-Type: application/octet-stream; x-mac-hide-extension=yes; x-unix-mode=0644; name="org-mac-flagged-mail.el" Content-Transfer-Encoding: 7bit ;;; org-mac-flagged-mail.el --- import links to OS X Mail.app messages ;; ;; Author: Christopher Suckling ;; Keywords: outlines, hypermedia, org, mail ;; Version: 0.624 ;; Commentary ;; This library searches for flagged messages in a Mail.app ;; account. It creates hyperlinks to these messages and copies them to ;; the kill ring for further processing, for example, the included ;; function (org-mac-insert-flagged-mail), inserts these links into an ;; org-mode buffer. ;; Installation ;; Add (require 'org-mac-flagged-mail) to your .emacs and customize ;; the variable org-mac-mail-theAccount to the Mail.app account you ;; wish to search. ;; Two functions are provided. ;; (org-mac-create-flagged-mail) copies a formatted list of links to ;; the kill ring. ;; (org-mac-insert-flagged-mail) searches within an org-mode buffer ;; for a specific heading, creating it if it doesn't exist. Any ;; message:// links within the first level of that heading are deleted ;; and replaced with links to flagged messages. ;; If you have Growl installed and would like more visual feedback ;; whilst AppleScript searches for messages, please uncomment lines ;; 60 to 65. (require 'org-mac-message) (defgroup org-mac-flagged-mail nil "Options concerning linking to flagged Mail.app messages" :tag "Org Mail.app" :group 'org-link) (defcustom org-mac-mail-theAccount "mailaccount" "The Mail.app account in which to search for flagged messages" :group 'org-mac-flagged-mail :type 'string) (defun org-mac-create-flagged-mail () "Import flagged messages from Mail.app and copy them to the kill ring" (interactive) (message "AppleScript: searching mailboxes...") (let* ((theLinkList (do-applescript (concat "tell application \"Mail\"\n" "set theMailboxes to every mailbox of account \"" org-mac-mail-theAccount "\"\n" "set theLinkList to {}\n" "repeat with aMailbox in theMailboxes\n" "set theSelection to (every message in aMailbox whose flagged status = true)\n" "repeat with theMessage in theSelection\n" "set theID to message id of theMessage\n" "set theSubject to subject of theMessage\n" "set theLink to \"message://\" & theID & \"::split::\" & theSubject & \"\n\"\n" "copy theLink to end of theLinkList\n" ;; "tell application \"GrowlHelperApp\"\n" ;; "set the allNotificationsList to {\"FlaggedMail\"}\n" ;; "set the enabledNotificationsList to allNotificationsList\n" ;; "register as application \"FlaggedMail\" all notifications allNotificationsList default notifications enabledNotificationsList icon of application \"Mail\"\n" ;; "notify with name \"FlaggedMail\" title \"Importing flagged message\" description theSubject application name \"FlaggedMail\"\n" ;; "end tell\n" "end repeat\n" "end repeat\n" "return theLinkList as string\n" "end tell"))) (splitLinkList (split-string theLinkList "\n")) splitLink theURL theTitle orglink (orglinkList nil)) (while splitLinkList (progn (setq splitLink (split-string (pop splitLinkList) "::split::")) (setq theURL (car splitLink)) (setq theTitle (cadr splitLink)) (if (not (string= theURL "")) (progn (setq orglink (org-make-link-string theURL theTitle)) (push orglink orglinkList))))) (with-temp-buffer (while orglinkList (insert (concat (pop orglinkList)) "\n")) (kill-region (point-min) (point-max)) (message "Flagged messages copied to kill ring")))) (defun org-mac-insert-flagged-mail (org-buffer org-heading) "Delete only links to messages" (interactive "bBuffer in which to insert links: \nsHeading after which to insert links: ") (save-excursion (set-buffer org-buffer) (goto-char (point-min)) (let ((isearch-forward t) (message-re "\\[\\[\\(message:\\)?\\([^]]+\\)\\]\\(\\[\\([^]]+\\)\\]\\)?\\]")) (if (org-goto-local-search-headings org-heading nil t) (if (not (eobp)) (progn (save-excursion (while (re-search-forward message-re (save-excursion (outline-next-heading)) t) (delete-region (match-beginning 0) (match-end 0))) (org-mac-create-flagged-mail) (yank)) (flush-lines "^$" (point) (outline-next-heading))) (insert "\n") (org-mac-create-flagged-mail) (yank)) (goto-char (point-max)) (insert "\n") (org-insert-heading) (insert (concat org-heading "\n")) (org-mac-create-flagged-mail) (yank))))) (provide 'org-mac-flagged-mail) --Apple-Mail-7--663054427 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-7--663054427 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --Apple-Mail-7--663054427--