home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2005-07-29 | 79.7 KB | 2,306 lines
var gWebMailObv; var webmail = { WEBMAIL_DEBUG : true, services : Array(), Prefs : null, WEBMAIL_NS : "http://netscape.com/spui/components/email/services/1.0#", WEBMAIL_RES_NAME : null, WEBMAIL_RES_INBOX : null, WEBMAIL_RES_PCDOMAIN : null, WEBMAIL_RES_PCUSERNAME : null, WEBMAIL_RES_PCPASSWORD : null, WEBMAIL_RES_WRITE : null, WEBMAIL_RES_ADDRESS : null, WEBMAIL_RES_NOTIFY : null, WEBMAIL_RES_USERNAME : null, WEBMAIL_RES_ICON : null, WEBMAIL_RES_AUTOLOGURL : null, WEBMAIL_RES_NEEDLOGIN : null, WEBMAIL_RES_URLCAPTURE : null, WEBMAIL_RES_DEFAULTURL : null, WEBMAIL_RES_COMPOSEFIELDS : null, RDFService : null, RDFDataSource : null, RDFLoadObserver : null, CheckedNumbers : Array(), CapturedData : Array(), AutologObservers : Array(), mDefaultAccount : null, mCustomAccountsArray: Array(), Init : function () { // Initialize the webmail preferences branch object this.debug("webmail.Init() called"); if (!this.Prefs) { this.Prefs=gPrefService.getBranch("browser.webmail."); } if (!this.RDFService) { this.RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"] .getService(Components.interfaces.nsIRDFService); this.WEBMAIL_RES_NAME = this.RDFService.GetResource(this.WEBMAIL_NS+'name'); this.WEBMAIL_RES_INBOX = this.RDFService.GetResource(this.WEBMAIL_NS+'inboxuri'); this.WEBMAIL_RES_PCDOMAIN = this.RDFService.GetResource(this.WEBMAIL_NS+'passcarddomain'); this.WEBMAIL_RES_PCUSERNAME = this.RDFService.GetResource(this.WEBMAIL_NS+'passcardusername'); this.WEBMAIL_RES_PCPASSWORD = this.RDFService.GetResource(this.WEBMAIL_NS+'passcardpassword'); this.WEBMAIL_RES_WRITE = this.RDFService.GetResource(this.WEBMAIL_NS+'newemailuri'); this.WEBMAIL_RES_ADDRESS = this.RDFService.GetResource(this.WEBMAIL_NS+'addressbookuri'); this.WEBMAIL_RES_NOTIFY = this.RDFService.GetResource(this.WEBMAIL_NS+'notify'); this.WEBMAIL_RES_USERNAME = this.RDFService.GetResource(this.WEBMAIL_NS+'usernametext'); this.WEBMAIL_RES_ICON = this.RDFService.GetResource(this.WEBMAIL_NS+'icon'); this.WEBMAIL_RES_AUTOLOGURL = this.RDFService.GetResource(this.WEBMAIL_NS+'autologurl'); this.WEBMAIL_RES_NEEDLOGIN = this.RDFService.GetResource(this.WEBMAIL_NS+'needlogin'); this.WEBMAIL_RES_URLCAPTURE = this.RDFService.GetResource(this.WEBMAIL_NS+'urlcapture'); this.WEBMAIL_RES_DEFAULTURL = this.RDFService.GetResource(this.WEBMAIL_NS+'defaulturl'); this.WEBMAIL_RES_COMPOSEFIELDS = this.RDFService.GetResource(this.WEBMAIL_NS+'composefields'); this.RDFDataSource = null; this.mCustomAccountsArray = new Array(); } if (!this.RDFLoadObserver) { this.RDFLoadObserver = { onBeginLoad : function(sink){}, onInterrupt : function(sink){}, onResume : function(sink){}, onError : function(sink,status,msg){}, onEndLoad : function(sink) { RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"] .getService(Components.interfaces.nsIRDFService); sink.removeXMLSinkObserver(this); sink.QueryInterface(Components.interfaces.nsIRDFDataSource); this.parent.debug('Loaded datasource: '+sink.URI); resources = sink.GetAllResources(); while (resources.hasMoreElements()) { res = resources.getNext(); res.QueryInterface(Components.interfaces.nsIRDFResource); this.parent.HandleResource(sink, res); RDFService.UnregisterResource(res); } RDFService.UnregisterDataSource(sink); this.parent.services.sort(sort_services); for (var i=0;i<this.parent.services.length;i++) { this.parent.debug("services["+i+"]="+this.parent.services[i].name); } this.parent.fixMenus(); webmail.fixCustomAccountMenus(); }, }; this.RDFLoadObserver.parent = this; } // Get pref value for URL to grab supported components from var WEBMAIL_SUPPORTED_SERVICES = gPrefService.getCharPref("browser.webmail.services"); // Start loading RDF file of supported components this.RDFDataSource = this.RDFService.GetDataSource(WEBMAIL_SUPPORTED_SERVICES); // Register a listener to pick things up when the file is done // loading. (Control will go to the onEndLoad function...) this.RDFDataSource.QueryInterface(Components.interfaces.nsIRDFXMLSink); this.RDFDataSource.addXMLSinkObserver(this.RDFLoadObserver); }, readDefault : function () { if (this.mDefaultAccount) { this.read(this.mDefaultAccount); } else { this.openManage(null); } }, writeDefault : function () { if (this.mDefaultAccount) { this.write(this.mDefaultAccount); } else { this.openManage(null); } }, addressDefault : function () { if (this.mDefaultAccount) { this.address(this.mDefaultAccount); } else { this.openManage(null); } }, getServiceByName : function (wantname) { // Return a service by name for (var i = 0;i<this.services.length;i++) { if (wantname == this.services[i].name) { return this.services[i]; } } return null; }, setChecked : function (accountName,num) { for (var i=0;i<this.CheckedNumbers.length;i++){ if (this.CheckedNumbers[i].name == accountName) { this.CheckedNumbers[i].value=num; return; } } var last=this.CheckedNumbers.length; this.CheckedNumbers[last] = new Object(); this.CheckedNumbers[last].name = new String(accountName); this.CheckedNumbers[last].value = new Number(num); }, getChecked : function (accountName) { for (var i=0;i<this.CheckedNumbers.length;i++){ if (this.CheckedNumbers[i].name == accountName) { return this.CheckedNumbers[i].value; } } return 0; }, getServiceById : function (wantid) { // Return a service by id for (var i=0;i<this.services.length;i++) { if (wantid == this.services[i].id) { return this.services[i]; } } return null; }, dumpMenu : function (menuId) { try { var temp = document.getElementById(menuId).firstChild; this.debug("Menu: "+menuId+" dump:"); while(temp) { this.debug("\tItem ("+temp.id+")"+temp.label); temp = temp.nextSibling; } } catch (ex) { this.debug("can't dump menu: "+menuId); this.debug(ex); } }, // MERC - JCH: Get all custom accounts and set their icons if possible fixCustomAccountMenus: function () { // Get all webmail accounts stored as prefs var count = {value:0}; var prefAccounts; try { prefAccounts = this.Prefs.getChildList("provider.", count); } catch (ex) { return; } var arrayCount = 0; mCustomAccountsArray = new Array(); for (var i=0; i<prefAccounts.length; i++) { // Get the name of the account's provider if (this.Prefs.prefHasUserValue(prefAccounts[i]) && (this.Prefs.getPrefType(prefAccounts[i]) == this.Prefs.PREF_STRING)) { // If it is not a custom account, go to next provider if (this.Prefs.getCharPref(prefAccounts[i]) != "webmail:other") { continue; } mCustomAccountsArray[arrayCount] = new Object(); // Custom provider found, record name var accountName = prefAccounts[i].substr(9); mCustomAccountsArray[arrayCount].name = prefAccounts[i].substr(9); // Record the inbox url for account var inboxPrefName = "InboxURL."+accountName; var inboxUrl = ""; if (this.Prefs.prefHasUserValue(inboxPrefName) && (this.Prefs.getPrefType(inboxPrefName) == this.Prefs.PREF_STRING)) { inboxUrl = this.Prefs.getCharPref(inboxPrefName); mCustomAccountsArray[arrayCount].url = this.Prefs.getCharPref(inboxPrefName); } arrayCount++; var hostName; var protocol; var endDomain; // Check if inbox url is basically valid var start = inboxUrl.indexOf("://"); // If some scheme was provided and length is valid. // Note: assuming that a valid protocol has at least four letters. if ((start > 3) && ((start + 3) <= (inboxUrl.length -1))) { start = start + 3; protocol = inboxUrl.substring(0, start); var tempstr = inboxUrl.substring(start); endDomain = tempstr.indexOf("/"); // If there is a slash after '://', set defaults. // Otherwise, assume a valid domain is defined. if (endDomain != 0) { // Construct hostname => "http://bla.bla.bla" if (endDomain != -1) { hostName = protocol + inboxUrl.substring(start, endDomain); } else { hostName = protocol + inboxUrl.substring(start, inboxUrl.length); } // Retrieve favicons from site using a short delay before execution setTimeout("webmail.connectToRemoteSite('" + inboxUrl + "', '" + hostName + "')", 50); continue; } } // If we get here, assume that inbox url is garbage and set defaults this.setCustomAccountIcons(inboxUrl); } // End if } // End for }, // MERC - JCH: Set custom account(s) menu item favicon setCustomAccountIcons : function(aUri, faviconUri) { // If no input favicons, set default icons if (!faviconUri) faviconUri = "chrome://browser/skin/icons/mail_sm.png"; var accountName; for (var i=0; i<mCustomAccountsArray.length; i++) { if (mCustomAccountsArray[i].url == aUri) { accountName = mCustomAccountsArray[i].name; document.getElementById(accountName).setAttribute("image", faviconUri); document.getElementById(accountName).setAttribute("class", "menu-iconic"); // If this webmail account is the default account, set the toolbar button icon as well if (accountName == this.mDefaultAccount) { document.getElementById("webmail-menu-image").setAttribute("image", faviconUri); document.getElementById("webmail-menu-image").setAttribute("tooltiptext", "Webmail"); document.getElementById("webmail-toolbarbutton").setAttribute("tooltiptext", "Webmail"); document.getElementById("webmail-readmenuitem").setAttribute("src", faviconUri); } } } }, connectToRemoteSite: function(aUri, hostName) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onload = function(event) { webmail.myCallBackFunc(event, hostName, aUri); } //xmlhttp.onload = this.myCallBackFunc; xmlhttp.overrideMimeType("text/xml"); // And override content-type to avoid breakage try { xmlhttp.open("GET", aUri, true, null, null); } catch (ex) {} xmlhttp.url=aUri; xmlhttp.send(''); }, myCallBackFunc: function(event, hostName, myURL) { var httpRequest = event.target; var response; //Make sure we received a valid response switch(httpRequest.readyState) { case 1,2,3: debug('Bad Ready State: '+ httpRequest.status); this.setCustomAccountIcons(myURL); return false; break; case 4: if(httpRequest.status !=200) { debug('The server respond with a bad status code: '+httpRequest.status); this.setCustomAccountIcons(myURL); return false; } else { response = httpRequest.responseText; } break; } // MERC (rpaul) string mangling.. for now doesn't appear we can get valid // xml back from html pages... will look into this later, dom manipulations // would be alot cleaner // loop through the document looking for <link tags var currIndex = 0; var linkTagStartPos; var linkTagEndPos; var linkTag; var favicon = ""; var faviconUri = ""; while (currIndex != -1) { var validXmlTag = true; linkTagStartPos = response.indexOf("<link", currIndex); linkTagEndPos = response.indexOf("/>", linkTagStartPos); if (linkTagEndPos == -1) { linkTagEndPos = response.indexOf(">", linkTagStartPos); validXmlTag = false; } linkTag = response.substring(linkTagStartPos, linkTagEndPos+1); // make the extracted tag valid if needed by appending a "/>" to close the tag if (!validXmlTag) { var validTag = linkTag.substring(0, linkTag.length - 1) + "/>"; } parser = new DOMParser(); var xmlDocString = '<?xml version="1.0"?>\n<!DOCTYPE doc [\n<!ATTLIST d id ID #IMPLIED>\n]>\n<doc>\n <foo xmlns="foobar">One</foo> <x:bar xmlns:x="barfoo">Two</x:bar>\n ' + validTag + '\n</doc>\n'; //this.debug(xmlDocString); var doc = parser.parseFromString(xmlDocString, "text/xml"); var linkTags = doc.getElementsByTagName('link'); // sanity check if (linkTags.length) { if (linkTags[0].getAttribute("rel") == "icon" || linkTags[0].getAttribute("rel") == "shortcut icon") { // found the favicon tag, so break out of loop favicon = linkTags[0].getAttribute("href"); break; } } else { break; } currIndex = linkTagEndPos+1; } // end while // if we can't get the favicon from the xmlhttp request, try to get it off the root of the server if (favicon == "") { // check to see if <hostname>/favicon.ico exists, otherwise set the icon as // the default netscape xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", hostName + "/favicon.ico",true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { faviconUri = hostName + "/favicon.ico"; } else { faviconUri = "chrome://browser/skin/icons/mail_sm.png"; } } xmlhttp.send(null) } else { faviconUri = hostName + "/" + favicon; } // Iterate through the custom accounts array and set favicons for matching urls this.setCustomAccountIcons(myURL, faviconUri); }, getEmailAddress: function (accountName, defaultService, defaultProvider) { if (defaultProvider != "webmail:other") { var providerParts = defaultProvider.split(':'); var domain = providerParts[providerParts.length-1]; } else { // for other webmail accounts set the tooltip text to "webmail" // since a username is not provided return "Webmail"; } var myUserid; var myPassword; var mKey="webmail:"+accountName; var pc = GetWebmailPasscard(defaultService.passcarddomain, mKey); if (pc) { webmail.debug('Found a passcard for this account, un/pw = '+pc.user+'/'+pc.password); myUserid = pc.user; myPassword = pc.password; } else { webmail.debug('\nWEBMAIL ERROR: Did not find passcard for mKey = '+mKey+'\n'); return "Webmail"; } // couldn't get a valid key entry if (!myUserid && !myPassword) { webmail.debug("userID or Password not found, but needed"); return "Webmail"; } // if the sign in name is the email address, return it if (defaultService.username == "Email Address" || defaultService.username == "E-mail Address") { return myUserid; } //otherwise construct the email address // provider is split up by ':' we can get the domain for the account here var emailAddress = myUserid + '@' + domain + '.com'; return emailAddress; }, fixMenus : function () { this.debug('fixMenus()'); // Initialize the webmail menu and create any necessary mini-webmail menus // look for default account this.dumpMenu("webmail-menu"); var defaultWebmail = null; var defaultProvider = null; var checkUpdates = null; var numCustomAccounts = 0; if (this.Prefs.prefHasUserValue("default") && (this.Prefs.getPrefType("default") == this.Prefs.PREF_STRING)) { defaultWebmail = this.Prefs.getCharPref("default"); } else { this.debug("No Default Webmail provider set"); } // MERC - JCH: Do processing of default account if it exists. If it // doesn't exist, don't prevent adding other webmail accounts. if (defaultWebmail && (defaultWebmail != "")) { // verify that default is valid try { defaultProvider = this.Prefs.getCharPref("provider."+defaultWebmail); this.debug("Default Provider information found"); } catch(ex) { this.debug("No provider listed for default account"); return; } // MERC - JCH: Set the 'global' default account name variable here this.mDefaultAccount = defaultWebmail; var defaultService = this.getServiceById(defaultProvider); if (defaultService) { try { // setting default service images document.getElementById("webmail-menu-image").setAttribute("image", defaultService.icon); document.getElementById("webmail-menu-image").setAttribute("tooltiptext", "Webmail"); document.getElementById("webmail-toolbarbutton").setAttribute("tooltiptext", "Webmail"); document.getElementById("webmail-readmenuitem").setAttribute("src", defaultService.icon); } catch (ex) { this.debug('Unable to set tooltips and icon srcs'); } } // modify top of webmail menu as per prefs // set the name // set the inbox // set the write // set the addressbook try { checkUpdates=this.Prefs.getCharPref("checkUpdates."+defaultWebmail); } catch (ex) { checkUpdates="false"; } if (document.getElementById('webmail-button')) { //document.getElementById("webmail-menu-label").setAttribute("webmailAccel",defaultWebmail); document.getElementById("webmail-readmenuitem").setAttribute("webmailAccel",defaultWebmail); document.getElementById("webmail-toolbarbutton").setAttribute("webmailAccel",defaultWebmail); if (checkUpdates && checkUpdates=="true") { this.debug("submitting checkNewWebmail("+defaultWebmail+")"); setTimeout("checkNewWebmail('"+defaultWebmail+"');",5000); this.debug("returned."); } document.getElementById("webmail-readmenuitem").removeAttribute("disabled"); document.getElementById("webmail-readmenuitem").label="Read "+defaultWebmail; document.getElementById("webmail-readmenuitem").setAttribute("oncommand","webmail.read('"+defaultWebmail+"');"); if (defaultService && defaultService.writeurl.length > 0) { document.getElementById("webmail-writemenuitem").setAttribute("oncommand","webmail.write('"+defaultWebmail+"');"); document.getElementById("webmail-writemenuitem").removeAttribute("disabled"); document.getElementById("webmail-writemenuitem").removeAttribute("hidden"); } else { document.getElementById("webmail-writemenuitem").setAttribute("hidden", "true"); } if (defaultService && defaultService.addressurl.length > 0) { document.getElementById("webmail-addressmenuitem").setAttribute("oncommand","webmail.address('"+defaultWebmail+"');"); document.getElementById("webmail-addressmenuitem").removeAttribute("disabled"); document.getElementById("webmail-addressmenuitem").removeAttribute("hidden"); } else { document.getElementById("webmail-addressmenuitem").setAttribute("hidden", "true"); } } } else if (document.getElementById('webmail-button')) { // MERC - JCH: If no default account defined then set global var to null. this.mDefaultAccount = null; document.getElementById("webmail-menu-image").setAttribute("image","chrome://browser/skin/icons/mail_sm.png"); document.getElementById("webmail-readmenuitem").label="Read E-mail"; document.getElementById("webmail-readmenuitem").setAttribute("disabled", "true"); document.getElementById("webmail-readmenuitem").removeAttribute("src"); document.getElementById("webmail-writemenuitem").label="Write New E-Mail"; document.getElementById("webmail-writemenuitem").setAttribute("disabled", "true"); document.getElementById("webmail-addressmenuitem").label="Address Book"; document.getElementById("webmail-addressmenuitem").setAttribute("disabled", "true"); } // End of default account processing. // get list of all accounts var childcount = new Object; try { var myprefs=this.Prefs.getChildList("provider.",childcount); } catch (ex) { myprefs=new Array(); } myprefs.sort(); var i; var accountName; var first=true; var newpopup; var newitem; var newmenu; var temp; var nextMenu; var myService; var addrMenu = document.getElementById("webmail-addressmenuitem"); var curMenu; if (addrMenu) { curMenu = document.getElementById("webmail-addressmenuitem").nextSibling; while (curMenu && curMenu.id != "webmail-menu-mainsep") { nextMenu=curMenu.nextSibling; try { this.debug("removing child: ("+curMenu.id+") "+curMenu.label); delete document.getElementById("webmail-menu").removeChild(curMenu); } catch (ex) { this.debug("Error removing child:\n"+ex); } curMenu = nextMenu; } } if (curMenu) { this.debug("curMenu.id ="+curMenu.id); } this.debug("Finished deleting, starting rebuild"); this.dumpMenu("webmail-menu"); for (i=0; i<myprefs.length; i++) { this.debug("webmail pref ("+myprefs[i]+") found"); // ignore default account accountName=myprefs[i].substr(9); // if (accountName == defaultWebmail) { // continue; // } var temp=null; try { temp = this.Prefs.getCharPref(myprefs[i]); } catch (ex){} if (!temp || temp == "") continue; this.debug("making menu item, provider="+temp); myService=this.getServiceById(temp); // build up sub-menu for each account if (first){ var newsep = document.createElement("menuseparator"); newsep.setAttribute("id","webmail-menu-altsep"); var webmailMenu = document.getElementById("webmail-menu"); if (webmailMenu) webmailMenu.insertBefore(newsep,document.getElementById("webmail-menu-mainsep")); first = false; } newpopup=document.createElement("menupopup"); newpopup.setAttribute("label","mpop "+accountName); newitem = document.createElement("menuitem"); newitem.setAttribute("label","Read "+accountName); newitem.setAttribute("tooltiptext","Go to inbox for "+accountName); newitem.setAttribute("webmailAccel",accountName); newitem.setAttribute("oncommand","webmail.read('"+accountName+"');"); newpopup.appendChild(newitem); if (myService && (myService.writeurl.length > 0)) { newitem = document.createElement("menuitem"); newitem.setAttribute("label","New Email"); newitem.setAttribute("tooltiptext","Create a new Email using "+accountName); newitem.setAttribute("oncommand","webmail.write('"+accountName+"');"); newpopup.appendChild(newitem); } // MERC - JCH : If the account is a custom account and it has a write url defined. else if (temp == "webmail:other") { if (this.Prefs.prefHasUserValue("WriteURL."+accountName) && (this.Prefs.getPrefType("WriteURL."+accountName) == this.Prefs.PREF_STRING)) { newitem = document.createElement("menuitem"); newitem.setAttribute("label","New Email"); newitem.setAttribute("tooltiptext","Create a new Email using "+accountName); newitem.setAttribute("oncommand","webmail.write('"+accountName+"');"); newpopup.appendChild(newitem); } } if (myService && myService.addressurl.length > 0) { newitem = document.createElement("menuitem"); newitem.setAttribute("tooltiptext","Go to the address book for "+accountName); newitem.setAttribute("label","Address Book"); newitem.setAttribute("oncommand","webmail.address('"+accountName+"');"); newpopup.appendChild(newitem); } // MERC - JCH : If the account is a custom account and it has an address book url defined. else if (temp == "webmail:other") { if (this.Prefs.prefHasUserValue("AddressURL."+accountName) && (this.Prefs.getPrefType("AddressURL."+accountName) == this.Prefs.PREF_STRING)) { newitem = document.createElement("menuitem"); newitem.setAttribute("tooltiptext","Go to the address book for "+accountName); newitem.setAttribute("label","Address Book"); newitem.setAttribute("oncommand","webmail.address('"+accountName+"');"); newpopup.appendChild(newitem); } } newmenu = document.createElement("menu"); newmenu.appendChild(newpopup); newmenu.setAttribute("label",accountName); newmenu.setAttribute("tooltiptext",accountName+" webmail account"); if (defaultWebmail && accountName == defaultWebmail) { newmenu.setAttribute("style","font-weight:bold;"); } newmenu.setAttribute("webmailAccel",accountName); if (myService) { newmenu.setAttribute("image",myService.icon); newmenu.setAttribute("class","menu-iconic"); } else { // Set a custom account id using its unique name newmenu.setAttribute("id", accountName); } var webmailMenu = document.getElementById("webmail-menu"); if (webmailMenu) webmailMenu.insertBefore(newmenu,document.getElementById("webmail-menu-mainsep")); //create mini-webmail menu if needed. try { // MERC - JCH: Display webmail account as a separate button if pref set this.displayAccountButton(accountName); } catch (ex) { this.debug("Display Separately Failed"); this.debug(ex); } try { checkUpdates=this.Prefs.getCharPref("checkUpdates."+accountName); } catch (ex) { checkUpdates="false"; } if (checkUpdates && checkUpdates=="true") { this.debug("submitting checkNewWebmail("+accountName+")"); setTimeout("checkNewWebmail('"+accountName+"');",5000); } } try { this.dumpMenu("webmail-menu"); // MERC (rpaul) if the user creates a webmail account, then set the label to "Webmail" document.getElementById('webmail-toolbarbutton').setAttribute('label', 'Webmail'); } catch (ex) { } }, // MERC - JCH: Display webmail account as a separate button if 'dispSep' pref set to 'true' and // button doesn't exist. displayAccountButton : function(accountName) { // Construct the pref name var prefName = "dispSep."+accountName; if (this.Prefs.prefHasUserValue(prefName) && (this.Prefs.getPrefType(prefName) == this.Prefs.PREF_STRING)) { // Get the pref value for the display separately property var dispSep = this.Prefs.getCharPref(prefName); if (dispSep == "true") { // Determine where to place the button IF it is okay to add it to // the toolbar...it might be on the palette var webmailBtn = document.getElementById('webmail-button'); if (webmailBtn) { var toolbar = webmailBtn.parentNode; while ((toolbar) && (toolbar.localName != 'toolbar') && (toolbar.localName != 'multibartray')) { toolbar = toolbar.parentNode; } } if (!toolbar) { throw "No toolbar found for webmail-button"; } var newId = 'webmail-toolbaritem-'+accountName; // Check if button is in the currentSet for the toolbar. // This will prevent removing it from the palette if it's there. var currentSet = toolbar.currentSet.split(','); var found = false; for (var i = 0; i < currentSet.length; i++) { if (currentSet[i] == newId) { found = true; break; } } // Button is in the current set, so don't add it if (found) return; // If it's not in the current set, add it found = false; for (var i = 0; i < currentSet.length; i++) { if (currentSet[i] == 'webmail-button') { currentSet[i] = 'webmail-button,'+newId; found = true; break; } } if (!found) { dump(' - adding item to END of toolbar\n'); var lastItem = currentSet[currentSet.length-1]; currentSet[currentSet.length] = lastItem+','+newId; } var newCurrentSet = currentSet.join(','); //toolbar.currentSetAtLoadTime = newCurrentSet; // If the button has been added already, call returns true var alreadyAddedButton = this.addEmailButton(accountName); if (webmailBtn.nextSibling && !alreadyAddedButton) { toolbar.insertItem(newId, webmailBtn.nextSibling, null, false); toolbar.currentSetAtLoadTime = toolbar.currentSet; } } } }, openManage : function (accountName) { this.debug("opening dialog, accountName="+accountName); if (accountName) { window.openDialog('chrome://browser/content/manageEmailDialog.xul', 'manageEmailDialog','modal=yes',accountName); } else { window.openDialog('chrome://browser/content/manageEmailDialog.xul', 'manageEmailDialog','modal=yes'); } this.debug("done dialog, accountName="+accountName); }, /** * Parse the description for a particular resource **/ HandleResource : function(datasource, res) { // See if this resource specifies an actual webmail component //this.debug("Attempting to handle resource: "+res.Value); if (datasource.hasArcOut(res, webmail.WEBMAIL_RES_NAME) && datasource.hasArcOut(res, this.WEBMAIL_RES_INBOX) && datasource.hasArcOut(res, this.WEBMAIL_RES_WRITE) && datasource.hasArcOut(res, this.WEBMAIL_RES_ADDRESS) && datasource.hasArcOut(res, this.WEBMAIL_RES_NOTIFY)) { var new_service = this.services.length; this.services[new_service] = new Object(); this.debug("new service is #"+new_service); var info = datasource.GetTarget(res, this.WEBMAIL_RES_NAME, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].name = new String(info.Value); info = datasource.GetTarget(res, this.WEBMAIL_RES_INBOX, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].inboxurl = new String(info.Value); if (datasource.hasArcOut(res, this.WEBMAIL_RES_PCDOMAIN)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_PCDOMAIN, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].passcarddomain = new String(info.Value); } else { var host = this.services[new_service].inboxurl; host = host.replace(/.*:\/\/(.*)/,"$1"); // Remove http:// = mail.yahoo.com/help/test.php?test=yes if (host.indexOf("/") > 0) host = host.substring(0,host.indexOf("/")); // Remove /help/test.php?test=yes = mail.yahoo.com var domain = host.replace(/.*\.+(\w+\.\w+)$/,"$1"); // Remove mail. = yahoo.com this.services[new_service].passcarddomain = new String(domain); } if (datasource.hasArcOut(res, this.WEBMAIL_RES_PCUSERNAME)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_PCUSERNAME, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].passcardusername = new String(info.Value); } if (datasource.hasArcOut(res, this.WEBMAIL_RES_PCPASSWORD)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_PCPASSWORD, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].passcardpassword = new String(info.Value); } info = datasource.GetTarget(res, this.WEBMAIL_RES_WRITE, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].writeurl = new String(info.Value); info = datasource.GetTarget(res, this.WEBMAIL_RES_ADDRESS, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].addressurl = new String(info.Value); info = datasource.GetTarget(res, this.WEBMAIL_RES_NOTIFY, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].notify = new String(info.Value); this.services[new_service].id = new String(res.Value); if (datasource.hasArcOut(res,this.WEBMAIL_RES_USERNAME)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_USERNAME, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].username = new String(info.Value); } else this.services[new_service].username = new String("User Name"); if (datasource.hasArcOut(res,this.WEBMAIL_RES_ICON)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_ICON, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].icon = new String(info.Value); } else this.services[new_service].icon = new String("chrome://browser/skin/icons/mail_sm.png"); if (datasource.hasArcOut(res,this.WEBMAIL_RES_AUTOLOGURL)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_AUTOLOGURL, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].autologurl = new String(info.Value); this.services[new_service].autologurl = this.services[new_service].autologurl.replace(/;/g,"&"); } else this.services[new_service].autologurl = this.services[new_service].inboxurl; if (datasource.hasArcOut(res,this.WEBMAIL_RES_NEEDLOGIN)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_NEEDLOGIN, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].needlogin = new String(info.Value); } else this.services[new_service].needlogin = null; if (datasource.hasArcOut(res,this.WEBMAIL_RES_URLCAPTURE)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_URLCAPTURE, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].urlcapture = new String(info.Value); } else this.services[new_service].urlcapture = null; if (datasource.hasArcOut(res,this.WEBMAIL_RES_DEFAULTURL)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_DEFAULTURL, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].defaulturl = new String(info.Value); } else this.services[new_service].defaulturl = null; if (datasource.hasArcOut(res,this.WEBMAIL_RES_COMPOSEFIELDS)) { info = datasource.GetTarget(res, this.WEBMAIL_RES_COMPOSEFIELDS, true); info.QueryInterface(Components.interfaces.nsIRDFLiteral); this.services[new_service].composefields = new String(info.Value); } else this.services[new_service].composefields = null; this.debug("Webmail service, "+res.Value+", added to list with usernametext="+this.services[new_service].username); this.debug(" icon="+this.services[new_service].icon); this.debug(" defaulturl="+this.services[new_service].defaulturl); this.debug(" urlcapture="+this.services[new_service].urlcapture); this.debug(" needlogin="+this.services[new_service].needlogin); this.debug(" composefields="+this.services[new_service].composefields); } }, debug : function(msg) { if (gPrefService.getPrefType("webmail.debug") && gPrefService.getBoolPref("webmail.debug")) dump('WEBMAIL: '+msg+'\n'); }, addEmailButton : function(accountName) { this.debug('addEmailButton('+accountName+')'); var mItem; var mPopup; var tbButton; var tbItem=null; var stack; var vbox; var previewBox; var draggableBox; var myID="webmail-toolbaritem-"+accountName; var myService; var myProvider; var mSpacer; var spacer2,spacer3,hbox,vbox2; var toolbox = document.getElementById('navigator-toolbox'); var palette = toolbox.palette; // Check if button already exists - if it does, assume that it is OK try { tbItem=document.getElementById(myID); } catch (ex) {} if (tbItem) { return true; } // MERC - JCH: Check if account is already in palette so as not to create duplicates var isItem = palette.getElementsByAttribute("id", myID); if (isItem.length > 0) return true; try { myProvider=this.Prefs.getCharPref("provider."+accountName); } catch (ex) {} if (myProvider && myProvider != "") { myService=this.getServiceById(myProvider); } // Construction of the menupopup mPopup=document.createElement("menupopup"); mItem=document.createElement("menuitem"); mItem.setAttribute("label","Read "+accountName); if (myService) { mItem.setAttribute("image",myService.icon); mItem.setAttribute("class","menuitem-iconic"); } mItem.setAttribute("webmailAccel",accountName); mItem.setAttribute("tooltiptext","Go to inbox for "+accountName); mItem.setAttribute("oncommand","webmail.read('"+accountName+"');"); mPopup.appendChild(mItem); // JMC - If we don't have a valid compose page, don't show the button if (myService && myService.writeurl.length > 0) { mItem=document.createElement("menuitem"); mItem.setAttribute("label","Write Mail"); mItem.setAttribute("tooltiptext","Create a new Email using "+accountName); mItem.setAttribute("oncommand","webmail.write('"+accountName+"');"); mPopup.appendChild(mItem); } // JMC - If we don't have a valid addressbook page, don't show the button if (myService && myService.addressurl.length > 0) { mItem=document.createElement("menuitem"); mItem.setAttribute("label","Address Book"); mItem.setAttribute("tooltiptext","Go to the address book for "+accountName); mItem.setAttribute("oncommand","webmail.address('"+accountName+"');"); mPopup.appendChild(mItem); } mItem=document.createElement("menuseparator"); mPopup.appendChild(mItem); mItem=document.createElement("menuitem"); mItem.setAttribute("label","Manage Email Account..."); mItem.setAttribute("tooltiptext","Manage "+accountName+" webmail account information"); mItem.setAttribute("oncommand","this.parentNode.hidePopup();webmail.openManage('"+accountName+"');"); mPopup.appendChild(mItem); mPopup.setAttribute("position","at_pointer"); mPopup.setAttribute("label","NewEmailButton"); mPopup.setAttribute("id","webmail-menu-"+accountName); var popupSet = document.createElement("popupset"); popupSet.appendChild(mPopup); // construct fancy looking button var imageLeft=document.createElement("image"); imageLeft.setAttribute("id","webmail-button-left-edge"); spacer=document.createElement("spacer"); spacer.setAttribute("id","webmail-button-slice"); spacer.setAttribute("flex","1"); var imageRight=document.createElement("image"); imageRight.setAttribute("id","webmail-button-right-edge"); hbox=document.createElement("hbox"); hbox.appendChild(imageLeft); hbox.appendChild(spacer); hbox.appendChild(imageRight); hbox.setAttribute("align","center"); hbox.setAttribute("pack","end"); hbox.setAttribute("style","width: 80px;"); hbox.setAttribute("id","webmailClickStyleTarget-"+accountName); var clickStyleTarget = hbox; spacer=document.createElement("spacer"); spacer.setAttribute("style","height: 1px;"); vbox=document.createElement("vbox"); vbox.appendChild(spacer); //vbox.appendChild(hbox); var box=document.createElement("box"); box.setAttribute("flex","1"); box.setAttribute("id","webmailPopupTarget-"+accountName); box.setAttribute("style","margin-top: 1px;"); hbox=document.createElement("hbox"); hbox.appendChild(box); hbox.setAttribute("style","width: 80px;"); hbox.setAttribute("align","stretch"); spacer=document.createElement("spacer"); spacer.setAttribute("flex","1"); spacer.setAttribute("style","min-width: 6px;"); image2=document.createElement("image"); if (myService) { image2.setAttribute("src",myService.icon); } else { image2.setAttribute("src","chrome://browser/skin/icons/mail_sm.png"); } image2.setAttribute("left","0"); image2.setAttribute("top","0"); image2.setAttribute("class","toolbarbutton-icon rolloverFlash"); var imageButton = document.createElement('toolbarbutton'); imageButton.setAttribute('image','chrome://browser/skin/icons/mail_sm.png'); imageButton.setAttribute('tooltiptext','Webmail'); imageButton.setAttribute('id','webmail-menu-image-'+accountName); spacer2=document.createElement("spacer"); spacer2.setAttribute("flex","1"); //construction of the toolbarbutton (visible) tbButton=document.createElement("toolbarbutton"); // tbButton.setAttribute("type","menu-button"); tbButton.setAttribute("oncommand","if (event.target==this) webmail.read('"+accountName+"');"); tbButton.setAttribute("tooltiptext", this.getEmailAddress(accountName, myService, myProvider)) tbButton.setAttribute("id","webmail-tb-button-"+accountName); tbButton.setAttribute("allowtransparency","true"); tbButton.setAttribute("class","webmail-toolbarbutton"); tbButton.setAttribute("allowTransparency","true"); // MERC - JCH: Limit button label length to prevent button from growing too large. var shortAcctName = null; if (accountName.length > 7) { shortAcctName = accountName.substr(0,7)+"..."; tbButton.setAttribute("label", shortAcctName); } else { shortAcctName = accountName; tbButton.setAttribute("label", accountName); } tbButton.setAttribute("baselabel", shortAcctName); tbButton.setAttribute("style","min-width: 60px !important;"); // Make the button have acceltext when webmail checking is done. tbButton.setAttribute("webmailAccel",accountName); //tbButton.appendChild(mPopup); spacer3=document.createElement("spacer"); spacer3.setAttribute("flex","1"); spacer3.setAttribute("style","min-width: 4px !important;"); var dropmarker = document.createElement('dropmarker'); dropmarker.setAttribute('id','webmail-dropmarker-'+accountName); dropmarker.setAttribute('class','webmail-dropmarker'); dropmarker.setAttribute('align','center'); imageRight=document.createElement("image"); //imageRight.setAttribute("style","list-style-image: inherit; margin-right: 6px;"); dropmarker.setAttribute("onmousedown","document.getElementById('webmailClickStyleTarget-"+accountName+ "').setAttribute('clickDown','true');"); dropmarker.setAttribute("onmouseup","document.getElementById('webmailClickStyleTarget-"+accountName+ "').removeAttribute('clickDown');"); dropmarker.setAttribute("onmouseout","document.getElementById('webmailClickStyleTarget-"+accountName+ "').removeAttribute('clickDown');"); dropmarker.setAttribute("onclick","document.getElementById('webmail-menu-"+accountName+ "').showPopup(document.getElementById('webmailPopupTarget-"+accountName+ "'),-1,-1,'popup','bottomleft','bottomleft');"); dropmarker.appendChild(imageRight); var hbox2=document.createElement("hbox"); hbox2.appendChild(spacer); hbox2.appendChild(imageButton); hbox2.appendChild(spacer2); hbox2.appendChild(tbButton); hbox2.appendChild(spacer3); hbox2.appendChild(dropmarker); hbox2.setAttribute("tooltip",accountName+" Webmail Account"); hbox2.setAttribute("align","center"); hbox2.setAttribute("pack","end"); var spacer4 = document.createElement("spacer"); spacer4.setAttribute("style","height: 1px;"); stack=document.createElement("stack"); stack.appendChild(spacer4); stack.appendChild(clickStyleTarget); stack.appendChild(hbox); stack.appendChild(hbox2); stack.setAttribute("align","center"); stack.setAttribute("pack","center"); stack.setAttribute("id","webmail-button-container-"+accountName); stack.setAttribute("style","width: 80px;"); spacer=document.createElement("spacer"); spacer.setAttribute("style","width:4px !important"); spacer2=document.createElement("spacer"); spacer2.setAttribute("style","width:4px !important"); hbox=document.createElement("hbox"); hbox.appendChild(spacer); hbox.appendChild(stack); hbox.appendChild(spacer2); spacer=document.createElement("spacer"); spacer.setAttribute("style","min-width:2px !important"); spacer.setAttribute("flex","1"); spacer2=document.createElement("spacer"); spacer2.setAttribute("style","min-width:2px !important"); spacer2.setAttribute("flex","1"); spacer2.setAttribute("id","webmailPopupTarget-"+accountName); vbox=document.createElement("vbox"); vbox.appendChild(spacer); vbox.appendChild(hbox); vbox.appendChild(spacer2); vbox.setAttribute("class","webmail-content"); // construction of preview toolbarbutton previewBox=document.createElement("toolbarbutton"); newImage=document.createElement("image"); if (myService) { newImage.setAttribute("src",myService.icon); } else { newImage.setAttribute("src","chrome://browser/skin/icons/mail_sm.png"); } previewBox.appendChild(newImage); previewBox.setAttribute("class","webmail-preview"); previewBox.setAttribute("mousethrough","never"); previewBox.setAttribute("label",accountName); previewBox.setAttribute("style","min-width: 60px !important;"); // construction of draggable toolbarbutton draggableBox=document.createElement("toolbarbutton"); draggableBox.setAttribute("class","webmail-draggable"); draggableBox.setAttribute("mousethrough","never"); draggableBox.setAttribute("label",accountName); draggableBox.setAttribute("style","min-width: 60px !important;"); // construction of the toolbaritem tbItem=document.createElement("toolbaritem"); tbItem.setAttribute("label",accountName); var myID="webmail-toolbaritem-"+accountName; tbItem.setAttribute("id",myID); tbItem.setAttribute("class","webmail-toolbaritem"); tbItem.setAttribute("title",accountName); tbItem.setAttribute("toolgroup","personal"); stack=document.createElement("stack"); stack.appendChild(popupSet); stack.appendChild(vbox); stack.appendChild(previewBox); stack.appendChild(draggableBox); tbItem.appendChild(stack); var toolbar = toolbox.firstChild; var placed = false; while (toolbar) { if (toolbar.currentSetAtLoadTime) { this.debug(' looking at toolbar: '+toolbar.id+', currentSet: ' +toolbar.currentSetAtLoadTime); var currentSet = toolbar.currentSetAtLoadTime.split(','); for (var i = 0; i < currentSet.length; i++) { this.debug(' '+currentSet[i]); if (currentSet[i] == myID) { // Found it! placed = this.placeItemRelative(tbItem, toolbar, currentSet, i,10); if (!placed) { // That didn't work, so just tack it on the end toolbar.appendChild(tbItem); this.debug(' placed at end of toolbar!'); placed = true; } break; } } } if (toolbar.localName == 'multibar') toolbar = toolbar.firstChild; else if (toolbar.localName == 'multibartray' && (!toolbar.nextSibling)) { toolbar = toolbar.parentNode.nextSibling; } else { toolbar = toolbar.nextSibling; } } var paletteItem = tbItem; if (placed) { paletteItem = tbItem.cloneNode(true); } // Regardless of whether this component got placed on a toolbar, we still // need to put it in the tool palette as well, because that represents the // set of all available toolbar items. palette.appendChild(paletteItem); return placed; }, removeMenus : function(accountName) { var myItem; var myItems; try { while (myItem=document.getElementById("webmail-toolbaritem-"+accountName)) { delete myItem.parentNode.removeChild(myItem); } var toolbox = document.getElementById('navigator-toolbox'); var palette = toolbox.palette; myItems=palette.getElementsByAttribute("id","webmail-toolbaritem-"+accountName); for (var i=0;i<myItems.length;i++) { delete myItems[i].parentNode.removeChild(myItems[i]); } } catch (ex) { this.debug("error removing menus for: "+accountName); this.debug(ex); } }, setAutoLoginPref : function (accountName, myService, autoLogFlag) { // Get a domain name from the mail service login URL var domain = myService.passcarddomain; if (!domain) { var host = myService.inboxurl.replace(/.*:\/\/(.*)/,"$1"); // Remove http:// if (host.indexOf("/") > 0) host = host.substring(0,host.indexOf("/")); // Remove /help/test.php?test=yes = mail.yahoo.com var domain = host.replace(/.*\.+(\w+\.\w+)$/,"$1"); // Remove mail. = yahoo.com //domain = 'aol.com'; //hackety hack } this.debug(' - domain: '+domain); // Get the passcard for the mail service login site var webmailPasscard = GetWebmailPasscard(domain, "webmail:"+accountName); if (!webmailPasscard) return; var passcardFlag; if (autoLogFlag) passcardFlag = '2'; else passcardFlag = '0'; // Ensure this passcard is set up properly for auto login //this.debug(' autologin used to be: '+webmailPasscard.autologin); //webmailPasscard.autologin = '2'; // fill & submit //this.debug(' autologin is now: '+webmailPasscard.autologin); var passcardMgr = Components.classes["@mozilla.org/passwordmanager;1"] .getService(Components.interfaces.nsIPasswordManager); passcardMgr.updateSignon( webmailPasscard.host, webmailPasscard.passcard, webmailPasscard.user, webmailPasscard.password, passcardFlag, webmailPasscard.protect, webmailPasscard.lastUsed, webmailPasscard.uniqueID, webmailPasscard.advancedFields); }, autoLogin : function(accountName, myService, action, aExtra) { this.debug('autoLogin(accountName:'+accountName+')'); // Open a new tab on the login URL this.debug(' - opening new tab...'); var newTab = gBrowser.addTabAt("about:blank"); this.mBrowser = gBrowser.getBrowserForTab(newTab); this.mBrowser.webNavigation.loadURI( myService.inboxurl, Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null); gBrowser.selectedTab = newTab; }, getCaptureByAccount : function(aAccountName) { for (var i=0;i<this.CapturedData.length;i++) { if (this.CapturedData[i].account==aAccountName) { return this.CapturedData[i].data; } } return null; }, setCaptureData : function(aAccountName,aData) { for (var i=0;i<this.CapturedData.length;i++) { if(this.CapturedData[i].account==aAccountName) { this.CapturedData[i].data = aData; return; } } var nData=this.CapturedData.length; this.CapturedData[nData]=new Object(); this.CapturedData[nData].data = new String(aData); this.CapturedData[nData].account = new String(aAccountName); }, getActionURLFromPref: function(prefix, accountName) { var myURL; if (this.Prefs.prefHasUserValue(prefix+accountName) && (this.Prefs.getPrefType(prefix+accountName) == this.Prefs.PREF_STRING)) { myURL = this.Prefs.getCharPref(prefix+accountName); } else { switch (prefix) { case "InboxURL.": myURL=this.getServiceById("webmail:feed:netscape").inboxurl; case "WriteURL.": myURL=this.getServiceById("webmail:feed:netscape").writeurl; case "AddressURL.": myURL=this.getServiceById("webmail:feed:netscape").addressurl; } } return myURL; }, doAction : function(accountName, action, aExtra) { var myURL; var myProvider; // Determine the provider if (this.Prefs.prefHasUserValue("provider."+accountName) && (this.Prefs.getPrefType("provider."+accountName) == this.Prefs.PREF_STRING)) { myProvider=this.Prefs.getCharPref("provider."+accountName); } else { return; } var myService=this.getServiceById(myProvider); if (this.Prefs.prefHasUserValue("autolog."+accountName) && (this.Prefs.getPrefType("autolog."+accountName) == this.Prefs.PREF_STRING) && this.Prefs.getCharPref("autolog."+accountName) =="true") { this.setAutoLoginPref(accountName, myService, true); } switch (action) { case "read": if (!myProvider || myProvider == "webmail:other") { myURL = this.getActionURLFromPref("InboxURL.", accountName); } else { myURL=myService.inboxurl; } break; case "write": case "mailto": if (!myProvider || myProvider == "webmail:other") { myURL = this.getActionURLFromPref("WriteURL.", accountName); } else { myURL=myService.writeurl; } break; case "address": if (!myProvider || myProvider == "webmail:other") { myURL = this.getActionURLFromPref("AddressURL.", accountName); } else { myURL=myService.addressurl; } break; } loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null); }, doActionOld : function(accountName,action,aExtra) { var myProvider; var myService; var myURL; this.debug("doAction ("+accountName+","+action+") called"); var doneauto=false; if (action.substr(0,9)=="continue_") { action=action.substr(9); doneauto=true; } // Determine the provider try { myProvider=this.Prefs.getCharPref("provider."+accountName); } catch (ex) { this.debug("no provider for account: "+accountName); } // Check that the provider is valid if (myProvider) { myService=this.getServiceById(myProvider); } // Determine the URL to go to if (!myProvider ||(myProvider && myProvider == "webmail:other")) { var prefix; if (action == "read") { prefix="InboxURL."; } else if (action == "write" || action == "mailto") { prefix="WriteURL."; } else if (action == "address") { prefix="AddressURL."; } else { this.debug("doAction called with invalid action!!!!!"); return; } try { myURL = this.Prefs.getCharPref(prefix+accountName); } catch (ex) { myURL = this.getServiceById("webmail:feed:netscape").inboxurl; } } else if (myService) { if (action == "read") { myURL=myService.inboxurl; } else if (action == "write" || action == "mailto") { myURL=myService.writeurl; } else if (action == "address") { myURL=myService.addressurl; } else { this.debug("doAction called with invalid action!!!!!"); return; } // if this service has "urlcapture" data needed, it needs to have been // set for this account, otherwise the default applies. If no url // capture data is needed, just use the standard read/write/address url if (myService.urlcapture) { this.debug("There is urlcapture defined for this webmail provider."); var myCapture=this.getCaptureByAccount(accountName); if (myCapture) { this.debug("Capture data is defined"); this.debug("Capture data is: "+myCapture); varlist=myService.urlcapture.split(';'); valuelist=myCapture.split(';'); if (varlist.length != valuelist.length) { webmail.debug("FATAL problem with urlcapture. Reverting to defaulturl."); if (myService.defaulturl) { myURL=myService.defaulturl } else { this.debug("Bad situation: urlcapture specified with no defaulturl"); this.debug("Attempting to use url without replacement -- probable failure"); } } else { for (var i=0;i<varlist.length;i++) { this.debug("var="+varlist[i]); this.debug("value="+valuelist[i]); if (varlist[i] == ":host:") { myURL=myURL.replace(/\/\/.+?\//,"//"+valuelist[i]+"/"); } else { var x=new RegExp("!"+varlist[i],"gi"); myURL=myURL.replace(x,valuelist[i]); } } } } else if (myService.defaulturl) { this.debug("No URLCapture information defined"); myURL=myService.defaulturl } else { this.debug("Bad situation: urlcapture specified with no defaulturl"); this.debug("Attempting to use url without replacement -- probable failure"); } } } if (!myURL || myURL=="") { if (action == "read") { myURL=this.getServiceById("webmail:feed:netscape").inboxurl; } else if (action == "write" || action == "mailto") { myURL=this.getServiceById("webmail:feed:netscape").writeurl; } else if (action == "address") { myURL=this.getServiceById("webmail:feed:netscape").addressurl; } else { this.debug("doAction called with invalid action!!!!!"); return; } } this.debug("myURL="+myURL); // Check if autologon is to be done if (this.Prefs.getPrefType("autolog."+accountName) == this.Prefs.PREF_STRING) { this.debug("autolog is turned on, attempting to log in"); autolog=this.Prefs.getCharPref("autolog."+accountName); } else { this.debug("autolog is not turned on or no pref exists"); this.debug("this.Prefs.getPrefType('autolog."+accountName+"')="+this.Prefs.getPrefType("autolog."+accountName)); this.debug("this.Prefs.PR_STRING="+this.Prefs.PREF_STRING); autolog="false"; } if (!doneauto && autolog=="true") { // JMC - hack hack, bypass this ugly stuff for now if (action == 'read') { this.autoLogin(accountName,myService,action,aExtra); return; } // Do autologin only if needed this.debug("autolog is true, testing URL"); // Determine "needauto" RegExp var needAuto; if (myService.needlogin) { needAuto = new RegExp(myService.needlogin,"gi"); } else { needAuto = new RegExp("(login again)|(expired)|(login page)","gi"); } this.debug("needAuto="+needAuto.source); // Try to access the URL var req = new XMLHttpRequest(); try { req.open("POST",myService.autologurl,true); } catch (ex) { this.debug("error in open POST"); this.debug(ex); } req.onreadystatechange = function() { res = null; if (req.readyState != 4) { webmail.debug("Ready State = "+req.readyState); return; } if ( req.status && (req.status / 100) == 2) res = req.responseText; else if (req.status && req.status == 405) { // Protocol not supported - use GET req2 = new XMLHttpRequest(); try { req2.open("GET",myService.autologurl,true); } catch (ex) { webmail.debug("error in open GET"); webmail.debug(ex); } req2.onreadystatechange = function() { if (req2.readyState != 4) { webmail.debug("Ready State = "+req2.readyState); return; } if ( req2.status && (req2.status / 100) == 2) res = req2.responseText; if (res) { var matchedNeedlogin=res.match(needAuto); if (matchedNeedlogin) { // Auto login webmail.debug("got a match for need login"); webmail.debug("attempting auto log in"); webmail.debug("match = "+matchedNeedlogin); webmail.autoLogin(accountName,myService,action,aExtra); return; } else { webmail.debug("Failed to match needlogin"); webmail.debug("Assuming that the URL loads fine"); // TODO MSD: DO NOT CHECK THIS IN WITH FOLLOWING LINE UNCOMMENTED //this.debug("res="+res); } } else { webmail.debug("res is not defined, req.status="+req.status); webmail.debug("proceeding with autologin"); webmail.autoLogin(accountName,myService,action,aExtra); return; } if (action=="mailto") { if (myService && myService.composefields) { webmail.finishHandleURI(myURL,aExtra,myService.composefields); } else { webmail.finishHandleURI(myURL,aExtra); } } else { loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null); } } //req2.onreadystatechange try { req2.send(""); } catch (ex) { webmail.debug("error in req2.send"); webmail.debug(ex); webmail.autoLogin(accountName,myService,action,aExtra); } return; } // 405 status (wrong protocol) if (res) { var matchedNeedlogin=res.match(needAuto); if (matchedNeedlogin) { // Auto login webmail.debug("got a match for need login"); webmail.debug("attempting auto log in"); webmail.debug("match = "+matchedNeedlogin); webmail.autoLogin(accountName,myService,action,aExtra); return; } else { webmail.debug("Failed to match needlogin"); webmail.debug("Assuming that the URL loads fine"); // TODO MSD: DO NOT CHECK THIS IN WITH FOLLOWING LINE UNCOMMENTED // this.debug("res="+res); } } else { webmail.debug("res is not defined, req.status="+req.status); webmail.debug("proceeding with autologin"); webmail.autoLogin(accountName,myService,action,aExtra); return; } if (action=="mailto") { if (myService && myService.composefields) { webmail.finishHandleURI(myURL,aExtra,myService.composefields); } else { webmail.finishHandleURI(myURL,aExtra); } } else { loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null); } } // req.onreadystatechange() try { req.send(""); } catch (ex) { this.debug("error in req.send"); this.debug(ex); this.autoLogin(accountName,myService,action,aExtra); } return; } // if (!doneauto && autolog=="true") if (action=="mailto") { if (myService && myService.composefields) { this.finishHandleURI(myURL,aExtra,myService.composefields); } else { this.finishHandleURI(myURL,aExtra); } } else { loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null); } }, read : function(accountName) { this.doAction(accountName,"read"); }, write : function(accountName) { this.doAction(accountName,"write"); }, address : function(accountName) { this.doAction(accountName,"address"); }, finishAction : function(aAccountName,aAction,aExtra) { setTimeout("webmail.doAction('"+aAccountName+"','continue_"+aAction+"','"+aExtra+"');",1); }, handleURI : function (aURI) { // aHref: URI object // load "write" URL of default and then fill in form // from the uri // Is this really a mailto: uri? this.debug("RECEIVED A MAILTO URI!!!!!"); this.debug("***********************\n"+aURI+"\n***********************"); if (aURI.scheme != "mailto:"){ // TODO: If not - pass it away or something???? } // Check Prefs var doMailto=false; if (this.Prefs.getPrefType("mailto")==this.Prefs.PREF_BOOL) { doMailto=this.Prefs.getBoolPref("mailto"); } if (!doMailto) { // TODO: Pass to other services or drop on floor?????? } if (this.Prefs.getPrefType("default") != this.Prefs.PREF_STRING) { this.debug("No default set!! Unable to process mailto: HREF."); var x=new Error(); x.message="No default webmail account defined. Unable to process HREF's"; throw x; } var accountName=this.Prefs.getCharPref("default"); // Remainder of processing happens in finishHandleURI() this.doAction(accountName,"mailto",aURI); }, handleURIEndLoad : function (aRequest,aStatus,aWebProgress) { webmail.debug("in handleURIEndLoad"); webmail.debug("this.mAddress = "+this.mAddress); const nsIChannel = Components.interfaces.nsIChannel; var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec; if (urlStr.indexOf(this.mFinalURL)>=0){ webmail.debug("reached "+this.mFinalURL+", proceeding to fill in To: information."); var myinputs=aWebProgress.DOMWindow.document.getElementsByTagName("input"); var toNames, subjectNames; if (this.mComposeFields) { if (this.mComposeFields.match(/to=([^;]+)/i)) { toNames = [ RegExp.$1 ]; } if (this.mComposeFields.match(/subject=([^;]+)/i)) { subjectNames = [ RegExp.$1 ]; } } if (!toNames) { var toNames=[ "mailTo", "to_compose", "to", "msg_to", "tofield", "send_to" ]; } if (!subjectNames) { var subjectNames=[ "msg_subject", "subject", "mailSubject", "Subj" ]; } var myTo, mySubj, myPossibleTo, myPossibleSubj; for (var i=0;i<myinputs.length;i++){ webmail.debug("checking "+myinputs[i].name+" against list of To: fields"); for (var j=0;j<toNames.length;j++) { if (myinputs[i].name && myinputs[i].name==toNames[j]) { myTo=myinputs[i]; } } if (!myTo && myinputs[i].name && myinputs[i].name.match(/to/i)) { myPossibleTo=myinputs[i]; } for (var j=0;j<subjectNames.length;j++) { if (myinputs[i].name && myinputs[i].name==subjectNames[j]) { mySubj=myinputs[i]; } } if (!mySubj && myinputs[i].name && myinputs[i].name.match(/subj/i)) { myPossibleSubj=myinputs[i]; } } if (!myTo && myPossibleTo) myTo=myPossibleTo; if (myTo && this.mAddress) { myTo.value=this.mAddress; } if (!mySubj && myPossibleSubj) mySubj=myPossibleSubj; if(mySubj && this.mSubject) { mySubj.value=this.mSubject; } this.mBrowser.removeProgressListener(this); } else { webmail.debug("failed to find "+this.mFinalURL+" in "+urlStr); } }, finishHandleURI : function (aWriteURL,aMailtoURI,aComposeFields) { // I should be able to navigate to aWriteURL and fill in the form using aMailtoURI var myAddress; if (aMailtoURI.match(/mailto:([^?&]+)/)) { myAddress=RegExp.$1; } var mySubject; if (aMailtoURI.match(/mailto:[^?&]+[?&]subject=([^?&]+)/)) { mySubject=RegExp.$1; } this.debug("aMailtoURI="+aMailtoURI); this.debug("myAddress="+myAddress); this.debug("mySubject="+mySubject); myEndLoad=new WebmailEndLoadListener(aWriteURL,true); myEndLoad.mAddress=myAddress; myEndLoad.mSubject=mySubject; myEndLoad.mFinalURL=aWriteURL; myEndLoad.mComposeFields=aComposeFields; myEndLoad.endDocumentLoad=this.handleURIEndLoad; myEndLoad.openIt(); }, placeItemRelative : function(newItem, toolbar, currentSet, index, maxIterations) { // Look for toolbar buttons that are progressively further away in // the currentSet // JMC - Special case, index = 0 if (index == 0) { var nextItem = toolbar.firstChild; if (nextItem) { toolbar.insertBefore(newItem, nextItem); } else { toolbar.appendChild(newItem); } return true; } var j = 1; var placed = false; if (!maxIterations) maxIterations = 10; while (!placed && (j < maxIterations)) { // First try placing it AFTER the previous item var nextItem; if (index >= j) { // this doesnt work for spacers and other anonymous elements var prevItem = document.getElementById(currentSet[index-j]); if (!prevItem) { // Count the number of these special elements which occur in the toolbarset // BEFORE this point, and then get the xth of them var specialCountLimit = 0; for (var i=0; i < index; i++) { if (currentSet[i] == currentSet[index-j]) specialCountLimit++; } var paletteItem = toolbar.firstChild; var specialCount =0; while (paletteItem) { var paletteId = paletteItem.id; var stringLen = currentSet[index-j].length; var aId = currentSet[index-j]; if (paletteId.substring(0,stringLen) == aId) { specialCount++; if (specialCount >= specialCountLimit) { prevItem = paletteItem; break; } } paletteItem = paletteItem.nextSibling; } } if (prevItem) { nextItem = prevItem.nextSibling; if (prevItem.nextSibling) { toolbar.insertBefore(newItem, prevItem.nextSibling); this.debug(' placed after '+currentSet[index-j]+'!'); placed = true; } else { toolbar.appendChild(newItem); placed = true; } } } if (!placed && (index < currentSet.length-j)) { // That didn't work, so try placing it BEFORE the next item nextItem = document.getElementById(currentSet[index+1]); if (!nextItem) { // Count the number of these special elements which occur in the toolbarset // BEFORE this point, and then get the xth of them var specialCountLimit = 0; for (var i=index; i > 0; i--) { if (currentSet[i] == currentSet[index+1]) specialCountLimit++; } var paletteItem = toolbar.lastChild; var specialCount =0; while (paletteItem) { var paletteId = paletteItem.id; var stringLen = currentSet[index+1].length; var aId = currentSet[index+1]; if (paletteId.substring(0,stringLen) == aId) { specialCount++; if (specialCount >= specialCountLimit) { nextItem = paletteItem; break; } } paletteItem = paletteItem.previousSibling; } } if (nextItem) { toolbar.insertBefore(newItem, nextItem); this.debug(' placed before '+currentSet[index+1]+'!'); placed = true; } } j++; } return placed; }, } function sort_services(first, second) { if (first.id == "webmail:feed:netscape") { return -1; } if (second.id == "webmail:feed:netscape") { return 1; } if (first.name < second.name) { return -1; } else { return 1; } } function checkNewWebmail(accountName) { // Confirm that the account wants updates webmail.debug("checkNewWebmail("+accountName+") called"); var checkUpdates; var notify; var oldNum=0; var numNew=0; var changed=false; if (webmail.Prefs.getPrefType("checkUpdates."+accountName) == webmail.Prefs.PREF_STRING) { checkUpdates=webmail.Prefs.getCharPref("checkUpdates."+accountName); } else { checkUpdates="false"; } if (!checkUpdates || checkUpdates == "false") return; // Check for last update and compare to current time var now = (new Date()).getTime(); webmail.debug("now="+now); var then = 0; if (webmail.Prefs.getPrefType("lastCheck."+accountName) == webmail.Prefs.PREF_STRING) { var lastCheck = webmail.Prefs.getCharPref("lastCheck."+accountName); //then=new Date(lastCheck); then = lastCheck; } webmail.debug("then="+then); var interval = 0; if (webmail.Prefs.getPrefType("emailfreq."+accountName)) { var sInterval = webmail.Prefs.getCharPref("emailfreq."+accountName); interval = 60000 * sInterval; } var diff = now - then; webmail.debug("Time since last check = "+diff); webmail.debug("interval = "+interval); if (diff > interval) { webmail.Prefs.setCharPref("lastCheck."+accountName,now); } else { setTimeout("checkNewWebmail('"+accountName+"');",interval); return; } try { // Determine the value to put into the acceltext var doesExist=webmail.Prefs.getPrefType("provider."+accountName); if (doesExist) { var provider=webmail.Prefs.getCharPref("provider."+accountName); } if (!provider || provider=="") return; var myService=webmail.getServiceById(provider); if (!myService) return; var notify=myService.notify; if (!notify || notify=="") return; webmail.debug("notify="+notify); var params=notify.match(/[^;]+/g); if (!params || params.length < 1) return; webmail.debug('found '+params.length+' params'); if (params[0].substr(0,7) == "scrape=") { webmail.debug('processing scrape'); var nURL=params[0].substr(7); var nPre=null; var nPost=null; var nDoAuto=true; // autologin is default var nGetStr=null; var isPost=false; for (var i=1;i<params.length;i++) { if (params[i].substr(0,4) == "pre=") nPre=params[i].substr(4); else if (params[i].substr(0,5) =="post=") nPost=params[i].substr(5); else if (params[i] == "neverauto") nDoAuto=false; else if (params[i].substr(0,8) == "httpget=") { nGetStr=params[i].substr(8); } else if (params[i].substr(0,9) == "httppost=") { nGetStr=params[i].substr(9); isPost=true; } } if (!nPre || !nPost) { webmail.debug("pre or post info missing for scrape"); return; } if (nGetStr) { webmail.debug('processing get-string'); nGetStr=nGetStr.replace(/\|/g,"&"); if ((nGetStr.indexOf("!password") > -1) || (nGetStr.indexOf("!userid") > -1)) { // Get userId and password and do replacement var myUserid = null; var myPassword = null; var fHost={ value: "" } var fUser={ value: "" } var fPassword={ value: "" } var mKey="webmail:"+accountName; // MERC - JCH: Get passcard info var domain = myService.passcarddomain; var pc = GetWebmailPasscard(domain, mKey); if (pc) { webmail.debug('Found a passcard for this account, un/pw = '+pc.user+'/'+pc.password); myUserid = pc.user; myPassword = pc.password; } else { webmail.debug('\nWEBMAIL ERROR: Did not find passcard for mKey = '+mKey+'\n'); return; } if (!myUserid && !myPassword) { webmail.debug("userID or Password not found, but needed"); return; } if (nGetStr.indexOf("!password") > -1) nGetStr = nGetStr.replace(/\!password/g,myPassword); if (nGetStr.indexOf("!userid") > -1) nGetStr = nGetStr.replace(/\!userid/g,myUserid); } webmail.debug("URI string: "+nGetStr); //nGetStr=encodeURI(nGetStr); if (!isPost) { // nURL=nURL+"?"+nGetStr; webmail.debug("Query string: "+nGetStr); nURL=nURL+"?"+encodeURI(nGetStr); } } //if (nDoAuto) { // webmail.autoLogin(accountName,myService); //} webmail.debug("myX should be "+nPre+"\\d+"+nPost); var myX= new RegExp(nPre+"\\d+"+nPost,""); webmail.debug("myX="+myX.source); var proto="GET"; if (isPost) { proto="POST"; } var req = new XMLHttpRequest(); try { req.open(proto,nURL,true); } catch (ex) { webmail.debug("error in "+proto); webmail.debug(ex); } webmail.debug("done open()"); req.onerror = function(ex) { dump("WEBMAIL REQUEST: req.onerror called\n"); dump(ex); } req.onprogress = function (ex) { dump("WEBMAIL REQUEST: req.progress called\n"); } req.onreadystatechange = function () { dump("WEBMAIL REQUEST: req.onreadystatechange called\n"); if (req.readyState==4) { // put all post processing here var res = null; if ( req.status && (req.status / 100) == 2) { res = req.responseText; } else { webmail.debug("req.status="+req.status); } if (!res){ return; } var ans=res.match(myX); webmail.debug("res.match(myX)="+ans); if (ans) { var myText=ans[0]; var preX=new RegExp(nPre,""); var temp=myText.substr(myText.match(preX)[0].length); numNew=temp.match(/\d+/)[0]; } else { webmail.debug("no match for myX in: \n"+res); return; } //oldNum=webmail.getChecked(accountName); webmail.setChecked(accountName,numNew); //var netNew=numNew-oldNum; var netNew = numNew; if (netNew < 0) netNew=0; // Get the list of elements which need to be updated var updateElements = null; try { updateElements = document.getElementsByAttribute("webmailAccel",accountName); } catch (ex) {} if (updateElements && updateElements.length > 0) { for (var i=0;i<updateElements.length;i++) { // Update the elements with the new values or remove the // acceltext. if (updateElements[i].localName == "toolbarbutton") { webmail.debug("~~~~~~~ Toolbarbutton mail notification "+updateElements[i].localName+" ~~~~~~~~~~"); // toolbarbuttons don't accept acceltext - must change the label and // tooltiptext if (checkUpdates == "true" && netNew > 0) { webmail.debug("updating element: "+updateElements[i].id + " type: "+updateElements[i].localName); updateElements[i].setAttribute("label",updateElements[i].getAttribute("baselabel") + " " +netNew); updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages"); } else if (numNew) { updateElements[i].setAttribute("label",updateElements[i].getAttribute("baselabel")); updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages"); } else { updateElements[i].setAttribute("label",updateElements[i].getAttribute("baselabel")); updateElements[i].setAttribute("tooltiptext",accountName + " webmail account"); } } else if (updateElements[i].localName == "description") { webmail.debug("~~~~~~~ Description mail notification "+updateElements[i].localName+" ~~~~~~~~~~"); if (checkUpdates == "true" && netNew > 0) { webmail.debug("updating element: "+updateElements[i].id + " type: "+updateElements[i].localName); updateElements[i].setAttribute("value",updateElements[i].getAttribute("baselabel") + " " +netNew); } else { updateElements[i].setAttribute("value",updateElements[i].getAttribute("baselabel")); } } else { webmail.debug("~~~~~~~ Undefined mail notification "+updateElements[i].localName+" ~~~~~~~~~~"); if (checkUpdates == "true" && netNew > 0) { webmail.debug("updating element: "+updateElements[i].id + " type: "+updateElements[i].localName); updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages"); updateElements[i].setAttribute("acceltext",netNew); } else { updateElements[i].setAttribute("tooltiptext",accountName + " webmail account"); updateElements[i].removeAttribute("acceltext"); } if (checkUpdates == "true") { updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages"); } else { updateElements[i].setAttribute("tooltiptext",accountName + " webmail account"); } } } } // Notify the user of new e-mail, if requested and different. try { notify = webmail.Prefs.getCharPref("notification."+accountName); } catch (ex) { notify = "None"; } var myProvider; try { myProvider = webmail.Prefs.getCharPref("provider."+accountName); } catch (ex) { myProvider = "webmail:feed:netscape"; } var myService = webmail.getServiceById(myProvider); var myImage; if (myService) { myImage = myService.icon; } else { myImage = "chrome://browser/skin/throbber16-single.gif"; } var notifyObserver = { onAlertFinished : function (aAlertCookie) {}, myAccount : new String(), onAlertClickCallback : function (aAlertCookie) { webmail.read(this.myAccount); } } notifyObserver.myAccount=accountName; webmail.debug("Notification for account ("+accountName+") is "+notify); if (checkUpdates=="true" && netNew> 0) { var message="You have "+netNew+" new e-mails in your "+ accountName+" webmail account"; if (notify == "Toaster") { webmail.debug("attempting Toaster notification"); var alerts = Components.classes["@mozilla.org/alerts-service;1"] .getService(Components.interfaces.nsIAlertsService); alerts.showAlertNotification(myImage, "New Email", message, true, "", notifyObserver); } else if (notify == "Info-Bar") { webmail.debug("attempting Info-Bar notification"); var extraData = new Array(); extraData.push(myImage); extraData.push(message); displayNotificationBar("webmail", extraData); } } } else { webmail.debug("req state = "+req.readyState); } } try { if (isPost) { req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); req.send(nGetStr); } else { req.send(""); } } catch (ex) { webmail.debug("error in req.send"); webmail.debug(ex); } webmail.debug("done send()"); } } catch (ex) { webmail.debug("checkNewWebmail failed oddly"); webmail.debug(ex); } // submit the next update if (checkUpdates=="true") { var nTime; try { nTime = webmail.Prefs.getCharPref("emailfreq."+accountName); } catch (ex) {} if (nTime && nTime > 0) { setTimeout("checkNewWebmail('"+accountName+"');",60000*nTime); } } } function WebmailEndLoadListener(aURL,aSelectBrowser) { this.mURL = aURL; this.mSelectBrowser = aSelectBrowser; } WebmailEndLoadListener.prototype = { mURL : null, mBrowser : null, mSelectBrowser : null, mFinalURL : null, mAddress : null, mSubject : null, mLastChange : null, openIt : function () { if (this.mSelectBrowser) { gBrowser.selectedTab=gBrowser.addTabAt("about:blank"); this.mBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab); } else { this.mBrowser = gBrowser.getBrowserForTab(gBrowser.addTabAt("about:blank")); } this.mBrowser.loadURI("about:blank"); this.mBrowser.addProgressListener(this); this.mBrowser.webNavigation.browserEngine = 'Gecko'; this.mBrowser.webNavigation.loadURI(this.mURL,Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE,null,null,null); this.mLastChange = new Date(); }, onProgressChange : function (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) { this.mLastChange = new Date(); webmail.debug ("onPregressChange Called"); const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIChannel = Components.interfaces.nsIChannel; if (aRequest) { try { var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec; } catch(ex) {urlStr="undefined!";} } else { urlStr="undefined"; } webmail.debug("urlStr="+urlStr); }, onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) { this.mLastChange = new Date(); webmail.debug ("onStateChange Called"); const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener; const nsIChannel = Components.interfaces.nsIChannel; if (aRequest) { try { var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec; } catch(ex) {urlStr="undefined!";} } else { urlStr="undefined"; } webmail.debug("urlStr="+urlStr); if (aStateFlags & nsIWebProgressListener.STATE_STOP) { webmail.debug("State is Stop"); if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) { webmail.debug("State is network"); if (aRequest) { webmail.debug("running endDocumentLoad function in Progress Listener"); webmail.debug("browser engine string=" + this.mBrowser.webNavigation.browserEngine ); this.endDocumentLoad(aRequest, aStatus, aWebProgress); } } } }, onLocationChange : function(aWebProgress, aRequest, aLocation) { webmail.debug ("onLocationChange Called"); if (aLocation) { var urlStr = aLocation.spec; } else { urlStr="undefined"; } webmail.debug("urlStr="+urlStr); this.mLastChange = new Date(); }, onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage) { this.mLastChange = new Date(); }, onSecurityChange : function(aWebProgress, aRequest, aState) { this.mLastChange = new Date(); }, QueryInterface : function(aIID) { if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports)) return this; throw Components.results.NS_NOINTERFACE; }, endDocumentLoad : function(aRequest, aStatus, aWebProgress) { webmail.debug("Running the default endDocumentLoad function"); } }