Monday, November 08, 2010 at 12:01 AM.

system.verbs.apps.Manila.windowTypes.types.manilaMessage.openMessage

on openMessage (siteurl, msgnum, flHidden=false, flHomePage=false, adradrwindow=nil) {
	<<Open a message in a Manila site.
	<<Changes
		<<3/11/02; 11:56:46 AM by JES
			<<If this is a Mac, and the message is opml, convert to Mac text.
	
	bundle { //if the window is already open, bring it to the front
		local (t); new (tableType, @t);
		local (adrtype = parentOf (this^));
		t.type = nameOf (adrtype^);
		t.msgnum = msgnum;
		manila.windowTypes.findSiteInfo (siteurl, @t.adrSiteInfo);
		local (adrwindow);
		if Frontier.tools.windowTypes.findWindowWithMatchingAtts (@t, @adrwindow) {
			local (title, flReadOnly = false);
			window.attributes.getOne ("title", @title, adrwindow);
			window.attributes.getOne ("flReadOnly", @flReadOnly, adrwindow);
			if not flHidden {
				edit (adrwindow, title, flReadOnly)};
			return (true)}};
	
	local (username, password);
	on createInfoCallback (adrinfo) {
		if manila.windowTypes.getUsernameAndPassword (adrinfo, @username, @password) {
			manila.windowTypes.setUsernameAndPassword (adrinfo, username, password)}
		else {
			bundle { //don't leave stale data lying around
				local (adrtempinfo = @system.temp.manila.data.sites.[nameOf (adrinfo^)]);
				if defined (adrtempinfo^) {delete (adrtempinfo)};
				delete (adrinfo)};
			return (false)}};
	
	local (adrinfo);
	if not manila.windowTypes.findSiteInfo (siteUrl, @adrinfo, @createInfoCallback) {
		return (false)}; //the user cancelled the username/password dialog
	
	bundle { //get the site name and displaySiteName if we need them
		if adrinfo^.siteName == "" {
			adrinfo^.siteName = manila.getSiteName (nameOf (adrinfo^))};
		if adrinfo^.displaySiteName == "" {
			adrinfo^.displaySiteName = adrinfo^.siteName}};
	
	manila.windowTypes.getUsernameAndPassword (adrinfo, @username, @password);
	local (siteinfo = adrinfo^);
	siteinfo.username = username;
	siteinfo.password = password;
	
	local (msg = manila.message.get (@siteinfo, msgnum)); //get the message from the server
	
	bundle { //update server info
		if defined (msg.flServerAcceptsOpml) {
			adrinfo^.flServerAcceptsOpml = msg.flServerAcceptsOpml};
		if defined (msg.displaySiteName) {
			adrinfo^.displaySiteName = msg.displaySiteName}};
	
	local (windowTitle = adrinfo^.displaySiteName + ": " + msg.subject);
	local (flReadOnly = false); //the server doesn't support this, but there may be need in the future
	local (adr = Frontier.tools.windowTypes.newWindow ("manilaMessage", true, windowTitle));
	window.attributes.setOne ("adrSiteInfo", adrinfo, adr);
	
	bundle { //put the message text in the window
		local (bodyType = "text/html");
		if defined (msg.bodyType) {
			bodyType = msg.bodyType};
		case bodyType {
			"text/html" {
				op.newOutlineObject (msg.body, adr)};
			"text/x-outline-tabbed" {
				op.newOutlineObject (msg.outline, adr)};
			"text/x-opml" {
				if defined (msg.opml) {
					local (opmltext = msg.opml);
					if system.environment.isMac {
						opmltext = latinToMac.convert (opmltext)};
					op.xmlToOutline (opmltext, adr)}
				else {
					op.newOutlineObject (msg.body, adr)}}};
		if defined (msg.windowInfo) {
			manila.windowTypes.restoreWindowState (adr, @msg.windowInfo)};
		if defined (msg.flReadOnly) {
			flReadOnly = msg.flReadOnly}};
	
	bundle { //set window attributes
		local (atts); new (tableType, @atts);
		atts.subject = msg.subject;
		atts.msgnum = msg.msgnum;
		atts.inResponseTo = msg.inResponseTo;
		atts.responses = msg.responses;
		atts.flAddToStoriesList = false; //if it's already a story, we don't need to add it again
		atts.timeCreated = msg.postTime;
		if defined (msg.lastUpdate) { //set lastSaved and the window's timeModified
			local (lastSaved = msg.lastUpdate, now = clock.now ());
			if msg.lastUpdate > now { //make sure lastSaved is not later than now
				lastSaved = now};
			atts.lastSaved = lastSaved;
			setTimeModified (adr, lastSaved)};
		if defined (msg.url) {
			atts.url = msg.url};
		if flHomePage { //get the home page url from the siteinfo table's name
			local (url = nameOf (adrinfo^));
			local (parts = string.urlSplit (url));
			if parts[2] contains ":" {
				if string.nthField (parts[2], ':', 2) == "80" {
					url = parts[1] + string.nthField (parts[2], ':', 1) + "/" + parts[3]}};
			atts.url = url};
		if defined (msg.rendererInfo) {
			atts.rendererInfo = msg.rendererInfo};
		if defined (msg.member) {
			atts.authorEmail = msg.member};
		if defined (msg.memberName) {
			atts.authorName = msg.memberName};
		if defined (msg.ctReads) {
			atts.ctReads = msg.ctReads};
		window.attributes.addGroup (@atts, adr)};
	
	manila.message.checkOut (adrinfo, msgnum);
	
	if not flHidden { //open the window
		edit (adr, windowTitle, flReadOnly)};
	
	if adradrwindow != nil {
		adradrwindow^ = adr};
	
	return (true)};

bundle { //debugging
	openMessage ("http://test.w2k.jspace.org/", 3)}



This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.