-- This is a simple modification of a script by John Delacour.
-- Addition by Markus Frischknecht: use startup disk, i.e. it is not dependent
-- on name of scratch disk any more (note that the script doesn't check
-- if the startup disk is locked or not...).
-- Also finds Eudora and Netscape Nav/Comm by their creator code.

-- Documentation from the original version:
-- What it does: If a message arrives with content-type set to text/html,
-- Eudora Pro 3.1 (and perhaps Eudora Light 3.1?) will have an option under
-- the "File" menu to "Open in Browser."  

-- If, however, the MIME type is not set to text/html, you will most likely
-- see HTML in the body of the message. Or you may have to hit the "blah blah"
-- button to see the HTML markup. But since the MIME type is not set to HTML,
-- "Open in Browser" is not on. This script will copy the currently selected
-- or open message and open it in Netscape. If the message has no HTML markup,
-- it will display as plain text, and will look silly. (I.e. carriage returns
-- don't display, etc.)
-- 
-- If, when sending a message (not an attachment) for which you wish the
-- MIME type to be set to text/html, download "Send HTML" from
-- Andrew Starr's Eudora Site.

-- (The site's address is <http://www.emailman.com/eudora/>.)

-- set up double tell mechanism, a generic way for identifying programs
-- under any System from Mac OS 7.5 to 8.5 (and probably later)

tell application "Finder"
	try
		set EU to (process 1 whose creator type is "CSOm") as «class psn »
		
		-- temporary file is placed on startup disk		
		set startupDisk to (first disk whose startup is true) as text
		
	on error
		-- Eudora is not running, so abort
		beep
		return
	end try
end tell


tell application "Finder"
	try
		 -- "MOSS" is the creator type of Netscape Comm.
		set NAV to (process 1 whose creator type is "MOSS") as «class psn »
	on error
		-- process couldn't be found, therefore launch it first
		set appPath to application file id "MOSS" as string
		-- launch application appPath -- opens in background, does not wait for reply
		open alias appPath	-- waits until open
		
		-- and get process now that the app is open
		set NAV to (process 1 whose creator type is "MOSS") as «class psn »
		
		-- Note: under Mac OS 8.x, it's probably better to use call to start
		-- standard browser (as defined in the Internet Control Panel); the same
		-- could be achieved under earlier Systems with the ICScriptor osax.
	end try
end tell


try
	set tempHTML to startupDisk & "temp.html"
	
	-- get body text of selected message
	tell application "Eudora Pro 3.1.3" to set myMessage to field "" of message ""
	-- write contents into new file
	open for access file tempHTML with write permission
	write myMessage to file tempHTML
	
	-- change creator of saved file
	tell application "Finder" to set creator type of file tempHTML to "MOSS"
	
	close access file tempHTML -- and close file
	
	-- tell Netscape Navigator/Communicator to open this file
	tell application "Netscape Communicator™" to tell NAV
		activate
		open tempHTML
	end tell
	
	tell application "Finder" to move file tempHTML to trash
	
on error
	beep
end try