emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christopher Suckling <suckling.list@googlemail.com>
To: Carsten Dominik <dominik@science.uva.nl>
Cc: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>,
	Christopher Suckling <suckling.list@googlemail.com>
Subject: Re: [ANN] OS X only: Insert links to flagged emails
Date: Sun, 22 Mar 2009 11:36:58 +0100	[thread overview]
Message-ID: <7CA2F7EA-9632-445A-BE4B-E163FF6A7458@gmail.com> (raw)
In-Reply-To: <BAFE85DA-8213-400B-A0F0-1EF30BA13B50@uva.nl>

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


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


[-- Attachment #2: org-mac-message.patch --]
[-- Type: application/octet-stream, Size: 5180 bytes --]

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 <johnw@gnu.org>
+;; Author: John Wiegley <johnw@gnu.org>, Christopher Suckling <suckling at gmail dot com>
 ;; 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

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



[-- Attachment #4: Type: text/plain, Size: 204 bytes --]

_______________________________________________
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

  reply	other threads:[~2009-03-22 10:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 19:07 [ANN] OS X only: Insert links to flagged emails Christopher Suckling
2009-03-20 20:13 ` Carsten Dominik
2009-03-20 23:22   ` Christopher Suckling
2009-03-21 12:25     ` Carsten Dominik
2009-03-22 10:36       ` Christopher Suckling [this message]
2009-03-22 15:04         ` Carsten Dominik
2009-03-27  9:30           ` Christopher Suckling
2009-03-27  9:55             ` Carsten Dominik

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=7CA2F7EA-9632-445A-BE4B-E163FF6A7458@gmail.com \
    --to=suckling.list@googlemail.com \
    --cc=dominik@science.uva.nl \
    --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).