emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christopher Suckling <suckling.list@googlemail.com>
To: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>
Subject: [ANN] OS X only: Insert links to flagged emails
Date: Thu, 19 Mar 2009 19:07:46 +0000	[thread overview]
Message-ID: <FFB93821-A507-429C-92F9-099E11485449@gmail.com> (raw)

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

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


[-- Attachment #2: org-mac-flagged-mail.el --]
[-- Type: application/octet-stream, Size: 4579 bytes --]

;;; org-mac-flagged-mail.el --- import links to OS X Mail.app messages
;;
;; Author: Christopher Suckling <suckling at gmail dot com>
;; 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)

[-- 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-19 19:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-19 19:07 Christopher Suckling [this message]
2009-03-20 20:13 ` [ANN] OS X only: Insert links to flagged emails Carsten Dominik
2009-03-20 23:22   ` Christopher Suckling
2009-03-21 12:25     ` Carsten Dominik
2009-03-22 10:36       ` Christopher Suckling
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=FFB93821-A507-429C-92F9-099E11485449@gmail.com \
    --to=suckling.list@googlemail.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
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).