#!/opt/p9p/bin/rc

rfork e

while () {
	eval `{plumbread plumb/showmail}
	msgdir=`{echo $data | sed 's/Mail/mail/'}
	msgid=`{9p read $msgdir^/messageid}

	osascript -e 'tell application "Mail"
		set myInbox to mailbox "INBOX" of account 1
		set myMessages to every message of myInbox
		repeat with theMessage in myMessages
			if message id of theMessage is "'$msgid'" then
				open theMessage
			end if
		end repeat
	end tell'
}
