From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Suckling Subject: Re: [ANN] OS X only: Insert links to flagged emails Date: Sun, 22 Mar 2009 11:36:58 +0100 Message-ID: <7CA2F7EA-9632-445A-BE4B-E163FF6A7458@gmail.com> References: <52888DD3-1730-4F7F-B047-A8F2195F2D35@uva.nl> <613C2101-B997-498C-8383-3D82F6059A28@gmail.com> Mime-Version: 1.0 (Apple Message framework v930.3) Content-Type: multipart/mixed; boundary=Apple-Mail-1--434502700 Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LlL3G-00061e-80 for emacs-orgmode@gnu.org; Sun, 22 Mar 2009 06:37:10 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LlL3A-00061R-Lq for emacs-orgmode@gnu.org; Sun, 22 Mar 2009 06:37:08 -0400 Received: from [199.232.76.173] (port=59782 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LlL3A-00061O-IS for emacs-orgmode@gnu.org; Sun, 22 Mar 2009 06:37:04 -0400 Received: from mail-ew0-f160.google.com ([209.85.219.160]:54730) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LlL39-0002g7-Vl for emacs-orgmode@gnu.org; Sun, 22 Mar 2009 06:37:04 -0400 Received: by ewy4 with SMTP id 4so1674554ewy.42 for ; Sun, 22 Mar 2009 03:37:00 -0700 (PDT) In-Reply-To: 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: Carsten Dominik Cc: emacs-orgmode Mailinglist , Christopher Suckling --Apple-Mail-1--434502700 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On 21 Mar 2009, at 13:25, Carsten Dominik wrote: > > On Mar 21, 2009, at 12:22 AM, Christopher Suckling wrote: > >> >> On 20 Mar 2009, at 21:13, Carsten Dominik wrote: >> >>> Hi Christopher, >>> >>> this is nice! Maybe we could integrate it into org-mac-message.el? >>> >>> - Carsten >> >> Thanks. I'd be delighted for it to be integrated into org-mac- >> message.el. Would you like me to put a patch together, or would you >> prefer to manage the integration yourself? > > I would be glad if you could provide a patch. > Attached is the patch. A thought: at present there are some optional lines (commented out by default) that make calls to Growl (http://growl.info) to provide more tactile feedback during the sometimes lengthy synchronous search made by AppleScript. Growl, however, is under a BSD license. Can these lines be included in Emacs? Christopher --Apple-Mail-1--434502700 Content-Disposition: attachment; filename=org-mac-message.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="org-mac-message.patch" Content-Transfer-Encoding: 7bit diff --git a/lisp/org-mac-message.el b/lisp/org-mac-message.el index 59b5041..7959ea9 100644 --- a/lisp/org-mac-message.el +++ b/lisp/org-mac-message.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc. -;; Author: John Wiegley +;; Author: John Wiegley , Christopher Suckling ;; Version: 6.24trans ;; Keywords: outlines, hypermedia, calendar, wp @@ -26,10 +26,38 @@ ;; Org-mode does not load this module by default - if you would actually like ;; this to happen then configure the variable `org-modules'. +;; If you would like to create links to all flagged messages in an +;; Apple Mail account, please customize the variable +;; org-mac-mail-account and then call one of the following functions: + +;; (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 the 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 +;; 125 to 130. + + + ;;; Code: (require 'org) +(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-account "customize" + "The Mail.app account in which to search for flagged messages" + :group 'org-mac-flagged-mail + :type 'string) + (org-add-link-type "message" 'org-mac-message-open) ;; In mac.c, removed in Emacs 23. @@ -77,6 +105,85 @@ end tell"))) (substring message-id 1 (1- (length message-id)))) (substring subject 1 (1- (length subject)))))) +(defun org-mac-create-flagged-mail () + "Create links to flagged messages in a Mail.app account and +copy them to the kill ring" + (interactive) + (message "AppleScript: searching mailboxes...") + (let* ((as-link-list (do-applescript + (concat + "tell application \"Mail\"\n" + "set theMailboxes to every mailbox of account \"" org-mac-mail-account "\"\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"))) + (link-list (split-string as-link-list "\n")) + split-link + URL + description + orglink + (orglink-list nil)) + (while link-list + (progn + (setq split-link (split-string (pop link-list) "::split::")) + (setq URL (car split-link)) + (setq description (cadr split-link)) + (if (not (string= URL "")) + (progn + (setq orglink (org-make-link-string URL description)) + (push orglink orglink-list))))) + (with-temp-buffer + (while orglink-list + (insert (concat (pop orglink-list)) "\n")) + (kill-region (point-min) (point-max)) + (message "Flagged messages copied to kill ring")))) + +(defun org-mac-insert-flagged-mail (org-buffer org-heading) + "Asks for an org buffer and a heading within it. If heading +exists, delete all message:// links within heading's first +level. If heading doesn't exist, create it at point-max. Insert +list of message:// links to flagged mail after heading." + (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-message) ;; arch-tag: 3806d0c1-abe1-4db6-9c31-f3ed7d4a9b32 --Apple-Mail-1--434502700 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-1--434502700 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-1--434502700--