home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 July & August / PCWorld_2005-07-08_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / browser.jar / content / browser / webmail.js < prev   
Text File  |  2005-05-12  |  79KB  |  2,251 lines

  1. var gWebMailObv;
  2. var webmail = {
  3.     WEBMAIL_DEBUG : true,
  4.     services : Array(),
  5.     Prefs : null,
  6.     WEBMAIL_NS : "http://netscape.com/spui/components/email/services/1.0#",
  7.     WEBMAIL_RES_NAME : null,
  8.     WEBMAIL_RES_INBOX : null,
  9.     WEBMAIL_RES_PCDOMAIN : null,
  10.     WEBMAIL_RES_PCUSERNAME : null,
  11.     WEBMAIL_RES_PCPASSWORD : null,
  12.     WEBMAIL_RES_WRITE : null,
  13.     WEBMAIL_RES_ADDRESS : null,
  14.     WEBMAIL_RES_NOTIFY : null,
  15.     WEBMAIL_RES_USERNAME : null,
  16.     WEBMAIL_RES_ICON : null,
  17.     WEBMAIL_RES_AUTOLOGURL : null,
  18.     WEBMAIL_RES_NEEDLOGIN : null,
  19.     WEBMAIL_RES_URLCAPTURE : null,
  20.     WEBMAIL_RES_DEFAULTURL : null,
  21.     WEBMAIL_RES_COMPOSEFIELDS : null,
  22.     RDFService : null,
  23.     RDFDataSource : null,
  24.     RDFLoadObserver : null,
  25.     CheckedNumbers : Array(),
  26.     CapturedData : Array(),
  27.     AutologObservers : Array(),
  28.     mDefaultAccount : null,
  29.     mCustomAccountsArray: Array(),
  30.  
  31.     Init : function () {
  32.         // Initialize the webmail preferences branch object
  33.         this.debug("webmail.Init() called");
  34.         if (!this.Prefs) {
  35.             this.Prefs=gPrefService.getBranch("browser.webmail.");
  36.         }
  37.         if (!this.RDFService) {
  38.             this.RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  39.                                         .getService(Components.interfaces.nsIRDFService);
  40.             this.WEBMAIL_RES_NAME = this.RDFService.GetResource(this.WEBMAIL_NS+'name');
  41.             this.WEBMAIL_RES_INBOX = this.RDFService.GetResource(this.WEBMAIL_NS+'inboxuri');
  42.             this.WEBMAIL_RES_PCDOMAIN = this.RDFService.GetResource(this.WEBMAIL_NS+'passcarddomain');
  43.             this.WEBMAIL_RES_PCUSERNAME = this.RDFService.GetResource(this.WEBMAIL_NS+'passcardusername');
  44.             this.WEBMAIL_RES_PCPASSWORD = this.RDFService.GetResource(this.WEBMAIL_NS+'passcardpassword');
  45.             this.WEBMAIL_RES_WRITE = this.RDFService.GetResource(this.WEBMAIL_NS+'newemailuri');
  46.             this.WEBMAIL_RES_ADDRESS = this.RDFService.GetResource(this.WEBMAIL_NS+'addressbookuri');
  47.             this.WEBMAIL_RES_NOTIFY = this.RDFService.GetResource(this.WEBMAIL_NS+'notify');
  48.             this.WEBMAIL_RES_USERNAME = this.RDFService.GetResource(this.WEBMAIL_NS+'usernametext');
  49.             this.WEBMAIL_RES_ICON = this.RDFService.GetResource(this.WEBMAIL_NS+'icon');
  50.             this.WEBMAIL_RES_AUTOLOGURL = this.RDFService.GetResource(this.WEBMAIL_NS+'autologurl');
  51.             this.WEBMAIL_RES_NEEDLOGIN = this.RDFService.GetResource(this.WEBMAIL_NS+'needlogin');
  52.             this.WEBMAIL_RES_URLCAPTURE = this.RDFService.GetResource(this.WEBMAIL_NS+'urlcapture');
  53.             this.WEBMAIL_RES_DEFAULTURL = this.RDFService.GetResource(this.WEBMAIL_NS+'defaulturl');
  54.             this.WEBMAIL_RES_COMPOSEFIELDS = this.RDFService.GetResource(this.WEBMAIL_NS+'composefields');
  55.             this.RDFDataSource = null;
  56.             this.mCustomAccountsArray = new Array();
  57.         }
  58.         if (!this.RDFLoadObserver) {
  59.             this.RDFLoadObserver = {
  60.                 onBeginLoad : function(sink){},
  61.                 onInterrupt : function(sink){},
  62.                 onResume : function(sink){},
  63.                 onError : function(sink,status,msg){},
  64.                 onEndLoad : function(sink) {
  65.                     RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  66.                                            .getService(Components.interfaces.nsIRDFService);
  67.                     sink.removeXMLSinkObserver(this);
  68.                     sink.QueryInterface(Components.interfaces.nsIRDFDataSource);
  69.                     this.parent.debug('Loaded datasource: '+sink.URI);
  70.                     resources = sink.GetAllResources();
  71.                     while (resources.hasMoreElements()) {
  72.                         res = resources.getNext();
  73.                         res.QueryInterface(Components.interfaces.nsIRDFResource);
  74.                         this.parent.HandleResource(sink, res);
  75.                         RDFService.UnregisterResource(res);
  76.                     }
  77.                     RDFService.UnregisterDataSource(sink);
  78.                     this.parent.services.sort(sort_services);
  79.                     for (var i=0;i<this.parent.services.length;i++) {
  80.                         this.parent.debug("services["+i+"]="+this.parent.services[i].name);
  81.                     }
  82.                     this.parent.fixMenus();
  83.                     webmail.fixCustomAccountMenus();
  84.                 },
  85.             };
  86.             this.RDFLoadObserver.parent = this;
  87.         }
  88.         // Get pref value for URL to grab supported components from
  89.         var WEBMAIL_SUPPORTED_SERVICES = gPrefService.getCharPref("browser.webmail.services");
  90.  
  91.         // Start loading RDF file of supported components
  92.         this.RDFDataSource = this.RDFService.GetDataSource(WEBMAIL_SUPPORTED_SERVICES);
  93.  
  94.         // Register a listener to pick things up when the file is done
  95.         // loading.  (Control will go to the onEndLoad function...)
  96.         this.RDFDataSource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
  97.         this.RDFDataSource.addXMLSinkObserver(this.RDFLoadObserver);
  98.     },
  99.  
  100.     readDefault : function () {
  101.         if (this.mDefaultAccount) {
  102.             this.read(this.mDefaultAccount);
  103.         } else {
  104.             this.openManage(null);
  105.         }
  106.     },
  107.  
  108.     writeDefault : function () {
  109.         if (this.mDefaultAccount) {
  110.             this.write(this.mDefaultAccount);
  111.         } else {
  112.             this.openManage(null);
  113.         }
  114.     },
  115.  
  116.     addressDefault : function () {
  117.         if (this.mDefaultAccount) {
  118.             this.address(this.mDefaultAccount);
  119.         } else {
  120.             this.openManage(null);
  121.         }
  122.     },
  123.  
  124.     getServiceByName : function (wantname) {
  125.         // Return a service by name
  126.         for (var i = 0;i<this.services.length;i++) {
  127.             if (wantname == this.services[i].name) {
  128.                 return this.services[i];
  129.             }
  130.         }
  131.         return null;
  132.     },
  133.  
  134.     setChecked : function (accountName,num) {
  135.           for (var i=0;i<this.CheckedNumbers.length;i++){
  136.               if (this.CheckedNumbers[i].name == accountName) {
  137.                   this.CheckedNumbers[i].value=num;
  138.                   return;
  139.               }
  140.           }
  141.           var last=this.CheckedNumbers.length;
  142.           this.CheckedNumbers[last] = new Object();
  143.           this.CheckedNumbers[last].name = new String(accountName);
  144.           this.CheckedNumbers[last].value = new Number(num);
  145.     },
  146.  
  147.     getChecked : function (accountName) {
  148.           for (var i=0;i<this.CheckedNumbers.length;i++){
  149.               if (this.CheckedNumbers[i].name == accountName) {
  150.                   return this.CheckedNumbers[i].value;
  151.               }
  152.           }
  153.           return 0;
  154.     },
  155.  
  156.     getServiceById : function (wantid) {
  157.         // Return a service by id
  158.         for (var i=0;i<this.services.length;i++) {
  159.             if (wantid == this.services[i].id) {
  160.                 return this.services[i];
  161.             }
  162.         }
  163.         return null;
  164.     },
  165.  
  166.     dumpMenu : function (menuId) {
  167.         try {
  168.             var temp = document.getElementById(menuId).firstChild;
  169.               this.debug("Menu: "+menuId+" dump:");
  170.               while(temp) {
  171.                   this.debug("\tItem ("+temp.id+")"+temp.label);
  172.                   temp = temp.nextSibling;
  173.               }
  174.         } catch (ex) {
  175.             this.debug("can't dump menu: "+menuId);
  176.             this.debug(ex);
  177.         }
  178.     },
  179.  
  180.  
  181.     // MERC - JCH: Get all custom accounts and set their icons if possible
  182.     fixCustomAccountMenus: function () {
  183.  
  184.         // Get all webmail accounts stored as prefs
  185.         var count = {value:0};
  186.         var prefAccounts;
  187.         try {
  188.             prefAccounts = this.Prefs.getChildList("provider.", count);
  189.         } catch (ex) {
  190.             return;
  191.         }
  192.  
  193.         var arrayCount = 0;
  194.         mCustomAccountsArray = new Array();
  195.         for (var i=0; i<prefAccounts.length; i++) {
  196.  
  197.             // Get the name of the account's provider
  198.             if (this.Prefs.prefHasUserValue(prefAccounts[i]) && 
  199.                (this.Prefs.getPrefType(prefAccounts[i]) == this.Prefs.PREF_STRING)) {
  200.  
  201.                 // If it is not a custom account, go to next provider
  202.                 if (this.Prefs.getCharPref(prefAccounts[i]) != "webmail:other") {
  203.                     continue;
  204.                 }
  205.  
  206.                 mCustomAccountsArray[arrayCount] = new Object();
  207.                 
  208.                 // Custom provider found, record name
  209.                 var accountName = prefAccounts[i].substr(9);
  210.                 mCustomAccountsArray[arrayCount].name = prefAccounts[i].substr(9);
  211.  
  212.  
  213.                 // Record the inbox url for account
  214.                 var inboxPrefName = "InboxURL."+accountName;
  215.                 var inboxUrl = "";
  216.                 if (this.Prefs.prefHasUserValue(inboxPrefName) && 
  217.                    (this.Prefs.getPrefType(inboxPrefName) == this.Prefs.PREF_STRING)) {    
  218.                    inboxUrl = this.Prefs.getCharPref(inboxPrefName);
  219.                    mCustomAccountsArray[arrayCount].url = this.Prefs.getCharPref(inboxPrefName);
  220.                 }
  221.  
  222.                 arrayCount++;
  223.                 
  224.                 var hostName;
  225.                 var protocol;
  226.                 var endDomain;    
  227.                 
  228.                 // Check if inbox url is basically valid
  229.                 var start = inboxUrl.indexOf("://");
  230.  
  231.                 // If some scheme was provided and length is valid.
  232.                 // Note: assuming that a valid protocol has at least four letters.
  233.                 if ((start > 3) && ((start + 3) <= (inboxUrl.length -1))) {
  234.                     start = start + 3;
  235.                     protocol = inboxUrl.substring(0, start);
  236.                     var tempstr = inboxUrl.substring(start);
  237.                     endDomain = tempstr.indexOf("/");
  238.  
  239.                     // If there is a slash after '://', set defaults.
  240.                     // Otherwise, assume a valid domain is defined.
  241.                     if (endDomain != 0) {
  242.                         // Construct hostname => "http://bla.bla.bla"
  243.                         if (endDomain != -1) {
  244.                             hostName = protocol + inboxUrl.substring(start, endDomain);
  245.                         } else {
  246.                             hostName = protocol + inboxUrl.substring(start, inboxUrl.length);
  247.                         }
  248.  
  249.                         // Retrieve favicons from site using a short delay before execution
  250.                         setTimeout("webmail.connectToRemoteSite('" + inboxUrl + "', '" + hostName + "')", 50);
  251.                         continue;
  252.                     }
  253.                 }
  254.  
  255.                 // If we get here, assume that inbox url is garbage and set defaults
  256.                 this.setCustomAccountIcons(inboxUrl);
  257.  
  258.             } // End if
  259.         } // End for
  260.     },
  261.  
  262.     // MERC - JCH: Set custom account(s) menu item favicon
  263.     setCustomAccountIcons : function(aUri, faviconUri) {
  264.  
  265.         // If no input favicons, set default icons
  266.         if (!faviconUri)
  267.             faviconUri = "chrome://browser/skin/icons/mail_sm.png";
  268.  
  269.         var accountName;
  270.         for (var i=0; i<mCustomAccountsArray.length; i++) {
  271.             if (mCustomAccountsArray[i].url == aUri) {
  272.                 accountName = mCustomAccountsArray[i].name;
  273.                 document.getElementById(accountName).setAttribute("image", faviconUri);
  274.                 document.getElementById(accountName).setAttribute("class", "menu-iconic");
  275.  
  276.                 // If this webmail account is the default account, set the toolbar button icon as well
  277.                 if (accountName == this.mDefaultAccount) {
  278.                     document.getElementById("webmail-menu-image").setAttribute("image", faviconUri);
  279.                      document.getElementById("webmail-menu-image").setAttribute("tooltiptext", "Webmail");
  280.                      document.getElementById("webmail-toolbarbutton").setAttribute("tooltiptext", "Webmail");
  281.                      document.getElementById("webmail-readmenuitem").setAttribute("src", faviconUri);
  282.                 }
  283.             }
  284.         }
  285.     },
  286.  
  287.  
  288.     connectToRemoteSite: function(aUri, hostName) {
  289.  
  290.         var xmlhttp = new XMLHttpRequest();
  291.         xmlhttp.onload = function(event) { webmail.myCallBackFunc(event, hostName, aUri); }
  292.         //xmlhttp.onload = this.myCallBackFunc;
  293.         xmlhttp.overrideMimeType("text/xml"); // And override content-type to avoid breakage
  294.  
  295.         xmlhttp.open("GET", aUri, true, null, null);
  296.  
  297.         xmlhttp.url=aUri;
  298.         xmlhttp.send('');
  299.     },
  300.  
  301.  
  302.     myCallBackFunc: function(event, hostName, myURL) {
  303.  
  304.         var httpRequest = event.target;
  305.         var response;
  306.  
  307.         //Make sure we received a valid response
  308.         switch(httpRequest.readyState) {
  309.         case 1,2,3:
  310.             debug('Bad Ready State: '+ httpRequest.status);
  311.             this.setCustomAccountIcons(myURL);
  312.             return false;
  313.             break;
  314.         case 4:
  315.             if(httpRequest.status !=200) {
  316.                 debug('The server respond with a bad status code: '+httpRequest.status);
  317.                 this.setCustomAccountIcons(myURL);
  318.                 return false;
  319.             } else {
  320.                 response = httpRequest.responseText;
  321.             }
  322.             break;
  323.         }
  324.  
  325.         // MERC (rpaul) string mangling.. for now doesn't appear we can get valid
  326.         // xml back from html pages... will look into this later, dom manipulations
  327.         // would be alot cleaner
  328.  
  329.         // loop through the document looking for <link tags
  330.         var currIndex = 0;
  331.         var linkTagStartPos;
  332.         var linkTagEndPos;
  333.         var linkTag;
  334.         var favicon = "";
  335.         var faviconUri = "";
  336.  
  337.         while (currIndex != -1) {
  338.             var validXmlTag = true;
  339.             linkTagStartPos = response.indexOf("<link", currIndex);
  340.             linkTagEndPos = response.indexOf("/>", linkTagStartPos);
  341.             if (linkTagEndPos == -1) {
  342.                 linkTagEndPos = response.indexOf(">", linkTagStartPos);
  343.                 validXmlTag = false;
  344.             }
  345.             linkTag = response.substring(linkTagStartPos, linkTagEndPos+1);
  346.  
  347.             // make the extracted tag valid if needed by appending a "/>" to close the tag
  348.             if (!validXmlTag) {
  349.                 var validTag = linkTag.substring(0, linkTag.length - 1) + "/>";
  350.             }
  351.  
  352.             parser = new DOMParser();
  353.  
  354.             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';
  355.  
  356.               //this.debug(xmlDocString);
  357.               var doc = parser.parseFromString(xmlDocString, "text/xml");
  358.               var linkTags = doc.getElementsByTagName('link');
  359.  
  360.               // sanity check
  361.               if (linkTags.length) {
  362.                   if (linkTags[0].getAttribute("rel") == "icon" ||
  363.                       linkTags[0].getAttribute("rel") == "shortcut icon")
  364.                   {
  365.                       // found the favicon tag, so break out of loop
  366.                       favicon = linkTags[0].getAttribute("href");
  367.                       break;
  368.                   }
  369.               } else {
  370.                   break;
  371.               }
  372.  
  373.               currIndex = linkTagEndPos+1;
  374.  
  375.         } // end while
  376.  
  377.         // if we can't get the favicon from the xmlhttp request, try to get it off the root of the server
  378.         if (favicon == "") {
  379.             // check to see if <hostname>/favicon.ico exists, otherwise set the icon as
  380.             // the default netscape
  381.             xmlhttp = new XMLHttpRequest();
  382.             xmlhttp.open("GET", hostName + "/favicon.ico",true);
  383.             xmlhttp.onreadystatechange=function() {
  384.                   if (xmlhttp.readyState==4) {
  385.                       faviconUri = hostName + "/favicon.ico";
  386.                   } else {
  387.                       faviconUri = "chrome://browser/skin/icons/mail_sm.png";
  388.                   }
  389.             }
  390.             xmlhttp.send(null)
  391.         } else {
  392.             faviconUri = hostName + "/" + favicon;
  393.         }
  394.  
  395.         // Iterate through the custom accounts array and set favicons for matching urls
  396.         this.setCustomAccountIcons(myURL, faviconUri);
  397.         
  398.     },
  399.  
  400.     getEmailAddress: function (accountName, defaultService, defaultProvider) {
  401.  
  402.         if (defaultProvider != "webmail:other") {
  403.             var providerParts = defaultProvider.split(':');
  404.             var domain = providerParts[providerParts.length-1];
  405.         } else {
  406.             // for other webmail accounts set the tooltip text to "webmail"
  407.             // since a username is not provided
  408.             return "Webmail";
  409.         }
  410.         var myUserid;
  411.         var myPassword;
  412.         var fHost={ value: "" }
  413.         var fUser={ value: "" }
  414.         var fPassword={ value: "" }
  415.         var mKey="webmail:"+accountName;
  416.         var passwordManagerInternal =
  417.         Components.classes["@mozilla.org/passwordmanager;1"].getService(Components.interfaces.nsIPasswordManagerInternal);
  418.         try {
  419.             passwordManagerInternal.findPasswordEntry(mKey,"","",fHost,fUser,fPassword);
  420.             if (mKey==fHost.value) {
  421.                 webmail.debug("found userid and password");
  422.                 myUserid=fUser.value;
  423.                 myPassword=fPassword.value;
  424.             }
  425.         } catch (ex) {}
  426.  
  427.         // couldn't get a valid key entry
  428.         if (!myUserid && !myPassword) {
  429.             webmail.debug("userID or Password not found, but needed");
  430.             return;
  431.         }
  432.         // if the sign in name is the email address, return it
  433.         if (defaultService.username == "Email Address" || defaultService.username == "E-mail Address") {
  434.             return myUserid;
  435.         }
  436.  
  437.         //otherwise construct the email address
  438.         // provider is split up by ':' we can get the domain for the account here
  439.         var emailAddress = myUserid + '@' + domain + '.com';
  440.  
  441.         return emailAddress;
  442.     },
  443.  
  444.  
  445.     fixMenus : function () {
  446.         this.debug('fixMenus()');
  447.  
  448.         // Initialize the webmail menu and create any necessary mini-webmail menus
  449.         // look for default account
  450.         this.dumpMenu("webmail-menu");
  451.         var defaultWebmail;
  452.         var defaultProvider;
  453.         var haveNetscape=false;
  454.         var checkUpdates;
  455.         var numCustomAccounts = 0;
  456.  
  457.         if (this.Prefs.prefHasUserValue("default") && 
  458.            (this.Prefs.getPrefType("default") == this.Prefs.PREF_STRING)) {
  459.             defaultWebmail = this.Prefs.getCharPref("default");
  460.         } else {
  461.             this.debug("No Default Webmail provider set");
  462.             return;
  463.         }
  464.  
  465.         if (defaultWebmail == "") {
  466.             return;
  467.         }
  468.  
  469.         // verify that default is valid
  470.         try {
  471.             defaultProvider = this.Prefs.getCharPref("provider."+defaultWebmail);
  472.             this.debug("Default Provider information found");
  473.         } catch(ex) {
  474.             this.debug("No provider listed for default account");
  475.             return;
  476.         }
  477.  
  478.         // MERC - JCH: Set the 'global' default account name variable here
  479.         this.mDefaultAccount = defaultWebmail;
  480.  
  481.         var defaultService = this.getServiceById(defaultProvider);
  482.  
  483.  
  484.         if (defaultService) {
  485.             try {
  486.                 // setting default service images
  487.                 document.getElementById("webmail-menu-image").setAttribute("image", defaultService.icon);
  488.                 document.getElementById("webmail-menu-image").setAttribute("tooltiptext", "Webmail");
  489.                 document.getElementById("webmail-toolbarbutton").setAttribute("tooltiptext", "Webmail");
  490.                 document.getElementById("webmail-readmenuitem").setAttribute("src", defaultService.icon);
  491.             } catch (ex) {
  492.                 this.debug('Unable to set tooltips and icon srcs');
  493.             }
  494.         } 
  495.  
  496.         // modify top of webmail menu as per prefs
  497.         // set the name
  498.         // set the inbox
  499.         // set the write
  500.         // set the addressbook
  501.         try {
  502.             checkUpdates=this.Prefs.getCharPref("checkUpdates."+defaultWebmail);
  503.         } catch (ex) {
  504.             checkUpdates="false";
  505.         }
  506.         if (document.getElementById('webmail-button')) {
  507.             //document.getElementById("webmail-menu-label").setAttribute("webmailAccel",defaultWebmail);
  508.             document.getElementById("webmail-readmenuitem").setAttribute("webmailAccel",defaultWebmail);
  509.             document.getElementById("webmail-toolbarbutton").setAttribute("webmailAccel",defaultWebmail);
  510.             if (checkUpdates && checkUpdates=="true") {
  511.                   this.debug("submitting checkNewWebmail("+defaultWebmail+")");
  512.                   setTimeout("checkNewWebmail('"+defaultWebmail+"');",5000);
  513.                   this.debug("returned.");
  514.               }
  515.             document.getElementById("webmail-readmenuitem").label="Read "+defaultWebmail;
  516.  
  517. // MERC - JCH: Don't dynamically set the menu item command. No idea why, but it fails. Just use readDefault(), as defined in browser.xul
  518. //            document.getElementById("webmail-readmenuitem").setAttribute("oncommand","webmail.read('"+defaultWebmail+"');");
  519.  
  520.     
  521.              if (defaultService && defaultService.writeurl.length > 0)
  522.              {
  523.                  document.getElementById("webmail-writemenuitem").setAttribute("oncommand","webmail.write('"+defaultWebmail+"');");
  524.                  document.getElementById("webmail-writemenuitem").removeAttribute("disabled");
  525.                  document.getElementById("webmail-writemenuitem").removeAttribute("hidden");
  526.              } else {
  527.                  document.getElementById("webmail-writemenuitem").setAttribute("hidden", "true");             
  528.              }
  529.              
  530.              if (defaultService && defaultService.addressurl.length > 0)
  531.              {
  532.                  document.getElementById("webmail-addressmenuitem").setAttribute("oncommand","webmail.address('"+defaultWebmail+"');");
  533.                  document.getElementById("webmail-addressmenuitem").removeAttribute("disabled");
  534.                  document.getElementById("webmail-addressmenuitem").removeAttribute("hidden");         
  535.              } else {
  536.                  document.getElementById("webmail-addressmenuitem").setAttribute("hidden", "true");
  537.              }
  538.         }
  539.  
  540.         // get list of all accounts
  541.         var childcount = new Object;
  542.         try {
  543.             var myprefs=this.Prefs.getChildList("provider.",childcount);
  544.         } catch (ex) {
  545.             myprefs=new Array();
  546.         }
  547.         myprefs.sort();
  548.         var i;
  549.         var accountName;
  550.         var first=true;
  551.         var newpopup;
  552.         var newitem;
  553.         var newmenu;
  554.         var temp;
  555.         var nextMenu;
  556.         var myService;
  557.         var addrMenu = document.getElementById("webmail-addressmenuitem");
  558.         var curMenu;
  559.         if (addrMenu) {
  560.             curMenu = document.getElementById("webmail-addressmenuitem").nextSibling;
  561.             while (curMenu && curMenu.id != "webmail-menu-mainsep") {
  562.                 nextMenu=curMenu.nextSibling;
  563.                 try {
  564.                     this.debug("removing child: ("+curMenu.id+") "+curMenu.label);
  565.                     delete document.getElementById("webmail-menu").removeChild(curMenu);
  566.                 } catch (ex) {
  567.                     this.debug("Error removing child:\n"+ex);
  568.                 }
  569.                 curMenu = nextMenu;
  570.             }
  571.         }
  572.         if (curMenu) {
  573.             this.debug("curMenu.id ="+curMenu.id);
  574.         }
  575.         this.debug("Finished deleting, starting rebuild");
  576.         this.dumpMenu("webmail-menu");
  577.  
  578.         for (i=0; i<myprefs.length; i++) {
  579.             this.debug("webmail pref ("+myprefs[i]+") found");
  580.             // ignore default account
  581.             accountName=myprefs[i].substr(9);
  582.             //          if (accountName == defaultWebmail) {
  583.             //              continue;
  584.             //          }
  585.             var temp=null;
  586.             try {
  587.                 temp = this.Prefs.getCharPref(myprefs[i]);
  588.             } catch (ex){}
  589.             if (!temp || temp == "") continue;
  590.  
  591.             if (temp == "webmail:feed:netscape") haveNetscape=true;
  592.  
  593.             this.debug("making menu item, provider="+temp);
  594.             myService=this.getServiceById(temp);
  595.             // build up sub-menu for each account
  596.             if (first){
  597.                 var newsep = document.createElement("menuseparator");
  598.                 newsep.setAttribute("id","webmail-menu-altsep");
  599.                 var webmailMenu = document.getElementById("webmail-menu");
  600.                 if (webmailMenu)
  601.                     webmailMenu.insertBefore(newsep,document.getElementById("webmail-menu-mainsep"));
  602.                 first = false;
  603.             }
  604.             newpopup=document.createElement("menupopup");
  605.             newpopup.setAttribute("label","mpop "+accountName);
  606.             
  607.             newitem = document.createElement("menuitem");
  608.             newitem.setAttribute("label","Read "+accountName);
  609.             newitem.setAttribute("tooltiptext","Go to inbox for "+accountName);
  610.             newitem.setAttribute("webmailAccel",accountName);
  611.             newitem.setAttribute("oncommand","webmail.read('"+accountName+"');");
  612.             newpopup.appendChild(newitem);
  613.             
  614.             if (myService && myService.writeurl.length > 0)
  615.             {
  616.                 newitem = document.createElement("menuitem");
  617.                 newitem.setAttribute("label","New Email");
  618.                 newitem.setAttribute("tooltiptext","Create a new Email using "+accountName);
  619.                 newitem.setAttribute("oncommand","webmail.write('"+accountName+"');");
  620.                 newpopup.appendChild(newitem);
  621.             }
  622.             
  623.             if (myService && myService.addressurl.length > 0)
  624.             {
  625.                 newitem = document.createElement("menuitem");
  626.                 newitem.setAttribute("tooltiptext","Go to the address book for "+accountName);
  627.                 newitem.setAttribute("label","Address Book");
  628.                 newitem.setAttribute("oncommand","webmail.address('"+accountName+"');");
  629.                 newpopup.appendChild(newitem);
  630.             }
  631.             
  632.             newmenu = document.createElement("menu");
  633.             newmenu.appendChild(newpopup);
  634.             
  635.             newmenu.setAttribute("label",accountName);
  636.             newmenu.setAttribute("tooltiptext",accountName+" webmail account");
  637.             if (accountName == defaultWebmail) {
  638.                 newmenu.setAttribute("style","font-weight:bold;");
  639.             }
  640.             newmenu.setAttribute("webmailAccel",accountName);
  641.  
  642.             if (myService) {
  643.                   newmenu.setAttribute("image",myService.icon);
  644.                   newmenu.setAttribute("class","menu-iconic");
  645.             } else {
  646.                 // Set a custom account id using its unique name
  647.                 newmenu.setAttribute("id", accountName);
  648.             }
  649.  
  650.             var webmailMenu = document.getElementById("webmail-menu");
  651.             if (webmailMenu)
  652.                 webmailMenu.insertBefore(newmenu,document.getElementById("webmail-menu-mainsep"));
  653.             //create mini-webmail menu if needed.
  654.             try {
  655.                 // MERC - JCH: Display webmail account as a separate button if pref set
  656.                 this.displayAccountButton(accountName);
  657.             } catch (ex) {
  658.                 this.debug("Display Separately Failed");
  659.                 this.debug(ex);
  660.             }
  661.               try {
  662.                   checkUpdates=this.Prefs.getCharPref("checkUpdates."+accountName);
  663.               } catch (ex) {
  664.                   checkUpdates="false";
  665.               }
  666.             if (checkUpdates && checkUpdates=="true") {
  667.                   this.debug("submitting checkNewWebmail("+accountName+")");
  668.                   setTimeout("checkNewWebmail('"+accountName+"');",5000);
  669.             }
  670.         }
  671.  
  672.         try {
  673.             this.dumpMenu("webmail-menu");
  674.             // MERC (rpaul) if the user creates a webmail account, then set the label to "Webmail"
  675.             document.getElementById('webmail-toolbarbutton').setAttribute('label', 'Webmail');
  676.         } catch (ex) { }
  677.     },
  678.  
  679.     // MERC - JCH: Display webmail account as a separate button if 'dispSep' pref set to 'true' and 
  680.     // button doesn't exist.
  681.     displayAccountButton : function(accountName) {
  682.  
  683.         this.debug(" ~~~~~~ displayAccountButton() ~~~~~~~~ \n"); 
  684.  
  685.         // Construct the pref name
  686.         var prefName = "dispSep."+accountName;
  687.         if (this.Prefs.prefHasUserValue(prefName) && 
  688.            (this.Prefs.getPrefType(prefName) == this.Prefs.PREF_STRING)) {
  689.  
  690.             // Get the pref value for the display separately property
  691.             var dispSep = this.Prefs.getCharPref(prefName);
  692.             if (dispSep == "true") {
  693.                 // Determine where to place the button IF it is okay to add it to 
  694.                 // the toolbar...it might be on the palette
  695.                 var webmailBtn = document.getElementById('webmail-button');
  696.                 var toolbar = webmailBtn.parentNode;
  697.                 while ((toolbar) &&
  698.                        (toolbar.localName != 'toolbar') &&
  699.                        (toolbar.localName != 'multibartray'))
  700.                 {
  701.                     toolbar = toolbar.parentNode;
  702.                 }
  703.                 
  704.                 if (!toolbar) {
  705.                     throw "No toolbar found for webmail-button";
  706.                 }
  707.                 
  708.                 var newId = 'webmail-toolbaritem-'+accountName;
  709.  
  710.                 // Check if button is in the currentSet for the toolbar.
  711.                 // This will prevent removing it from the palette if it's there.
  712.                 var currentSet = toolbar.currentSet.split(',');
  713.                 var found = false;
  714.                 for (var i = 0; i < currentSet.length; i++) {
  715.                     dump(" ~~~~~~ displayAccountButton() currentset item: " +currentSet[i]+ " ~~~\n");
  716.                     if (currentSet[i] == newId) {
  717.                         found = true;
  718.                         break;
  719.                     }
  720.                 }
  721.  
  722.                 // Button is in the current set, so don't add it
  723.                 if (found)
  724.                     return;
  725.  
  726.                 // If it's not in the current set, add it
  727.                 found = false;
  728.                 for (var i = 0; i < currentSet.length; i++) {
  729.                     if (currentSet[i] == 'webmail-button') {
  730.                         currentSet[i] = 'webmail-button,'+newId;
  731.                         found = true;
  732.                         break;
  733.                     }
  734.                 }
  735.                 if (!found) {
  736.                     dump(' - adding item to END of toolbar\n');
  737.                     var lastItem = currentSet[currentSet.length-1];
  738.                     currentSet[currentSet.length] = lastItem+','+newId;
  739.                 }
  740.                 var newCurrentSet = currentSet.join(',');
  741.                 //toolbar.currentSetAtLoadTime = newCurrentSet;
  742.  
  743.                 this.debug("~~~~~~~~~~~~~ displayAccountButton() : " +accountName+ " BUTTON NOT IN CURRENT SET ~~~~~~~~~~~~\n");
  744.  
  745.                 // If the button has been added, call returns false
  746.                 var alreadyAddedButton = this.addEmailButton(accountName);
  747.                 if (webmailBtn.nextSibling && !alreadyAddedButton) {
  748.                     toolbar.insertItem(newId, webmailBtn.nextSibling, null, false);
  749.                     toolbar.currentSetAtLoadTime = toolbar.currentSet;
  750.                 }
  751.             }
  752.         }
  753.     },
  754.  
  755.     openManage : function (accountName) {
  756.         this.debug("opening dialog, accountName="+accountName);
  757.         if (accountName) {
  758.             window.openDialog('chrome://browser/content/manageEmailDialog.xul',
  759.             'manageEmailDialog','modal=yes',accountName);
  760.         } else {
  761.             window.openDialog('chrome://browser/content/manageEmailDialog.xul',
  762.             'manageEmailDialog','modal=yes');
  763.         }
  764.         this.debug("done dialog, accountName="+accountName);
  765.     },
  766.  
  767.     /**
  768.      * Parse the description for a particular resource
  769.      **/
  770.     HandleResource : function(datasource, res) {
  771.         // See if this resource specifies an actual webmail component
  772.         //this.debug("Attempting to handle resource: "+res.Value);
  773.  
  774.         if (datasource.hasArcOut(res, webmail.WEBMAIL_RES_NAME) &&
  775.             datasource.hasArcOut(res, this.WEBMAIL_RES_INBOX) &&
  776.             datasource.hasArcOut(res, this.WEBMAIL_RES_WRITE) &&
  777.             datasource.hasArcOut(res, this.WEBMAIL_RES_ADDRESS) &&
  778.             datasource.hasArcOut(res, this.WEBMAIL_RES_NOTIFY))
  779.         {
  780.             var new_service = this.services.length;
  781.             this.services[new_service] = new Object();
  782.             this.debug("new service is #"+new_service);
  783.             var info = datasource.GetTarget(res, this.WEBMAIL_RES_NAME, true);
  784.             info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  785.             this.services[new_service].name = new String(info.Value);
  786.             info = datasource.GetTarget(res, this.WEBMAIL_RES_INBOX, true);
  787.             info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  788.             this.services[new_service].inboxurl = new String(info.Value);
  789.             if (datasource.hasArcOut(res, this.WEBMAIL_RES_PCDOMAIN)) {
  790.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_PCDOMAIN, true);
  791.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  792.                 this.services[new_service].passcarddomain = new String(info.Value);
  793.             } else {
  794.                 var host = this.services[new_service].inboxurl;
  795.                 host = host.replace(/.*:\/\/(.*)/,"$1"); // Remove http:// = mail.yahoo.com/help/test.php?test=yes
  796.                 if (host.indexOf("/") > 0)
  797.                     host = host.substring(0,host.indexOf("/")); // Remove /help/test.php?test=yes = mail.yahoo.com
  798.                 var domain = host.replace(/.*\.+(\w+\.\w+)$/,"$1"); // Remove mail. = yahoo.com
  799.                 this.services[new_service].passcarddomain = new String(domain);
  800.             }
  801.             if (datasource.hasArcOut(res, this.WEBMAIL_RES_PCUSERNAME)) {
  802.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_PCUSERNAME, true);
  803.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  804.                 this.services[new_service].passcardusername = new String(info.Value);
  805.             }
  806.             if (datasource.hasArcOut(res, this.WEBMAIL_RES_PCPASSWORD)) {
  807.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_PCPASSWORD, true);
  808.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  809.                 this.services[new_service].passcardpassword = new String(info.Value);
  810.             }
  811.             info = datasource.GetTarget(res, this.WEBMAIL_RES_WRITE, true);
  812.             info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  813.             this.services[new_service].writeurl = new String(info.Value);
  814.             info = datasource.GetTarget(res, this.WEBMAIL_RES_ADDRESS, true);
  815.             info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  816.             this.services[new_service].addressurl = new String(info.Value);
  817.             info = datasource.GetTarget(res, this.WEBMAIL_RES_NOTIFY, true);
  818.             info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  819.             this.services[new_service].notify = new String(info.Value);
  820.             this.services[new_service].id = new String(res.Value);
  821.  
  822.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_USERNAME)) {
  823.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_USERNAME, true);
  824.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  825.                 this.services[new_service].username = new String(info.Value);
  826.             } else this.services[new_service].username = new String("User Name");
  827.  
  828.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_ICON)) {
  829.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_ICON, true);
  830.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  831.                 this.services[new_service].icon = new String(info.Value);
  832.             } else this.services[new_service].icon = new String("chrome://browser/skin/icons/mail_sm.png");
  833.  
  834.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_AUTOLOGURL)) {
  835.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_AUTOLOGURL, true);
  836.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  837.                 this.services[new_service].autologurl = new String(info.Value);
  838.                 this.services[new_service].autologurl = this.services[new_service].autologurl.replace(/;/g,"&");
  839.             } else this.services[new_service].autologurl = this.services[new_service].inboxurl;
  840.  
  841.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_NEEDLOGIN)) {
  842.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_NEEDLOGIN, true);
  843.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  844.                 this.services[new_service].needlogin = new String(info.Value);
  845.             } else this.services[new_service].needlogin = null;
  846.  
  847.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_URLCAPTURE)) {
  848.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_URLCAPTURE, true);
  849.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  850.                 this.services[new_service].urlcapture = new String(info.Value);
  851.             } else this.services[new_service].urlcapture = null;
  852.  
  853.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_DEFAULTURL)) {
  854.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_DEFAULTURL, true);
  855.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  856.                 this.services[new_service].defaulturl = new String(info.Value);
  857.             } else this.services[new_service].defaulturl = null;
  858.  
  859.             if (datasource.hasArcOut(res,this.WEBMAIL_RES_COMPOSEFIELDS)) {
  860.                 info = datasource.GetTarget(res, this.WEBMAIL_RES_COMPOSEFIELDS, true);
  861.                 info.QueryInterface(Components.interfaces.nsIRDFLiteral);
  862.                 this.services[new_service].composefields = new String(info.Value);
  863.             } else this.services[new_service].composefields = null;
  864.  
  865.             this.debug("Webmail service, "+res.Value+", added to list with usernametext="+this.services[new_service].username);
  866.             this.debug("   icon="+this.services[new_service].icon);
  867.             this.debug("   defaulturl="+this.services[new_service].defaulturl);
  868.             this.debug("   urlcapture="+this.services[new_service].urlcapture);
  869.             this.debug("   needlogin="+this.services[new_service].needlogin);
  870.             this.debug("   composefields="+this.services[new_service].composefields);
  871.         }
  872.     },
  873.  
  874.  
  875.     debug : function(msg) {
  876.         if (gPrefService.getPrefType("webmail.debug") && gPrefService.getBoolPref("webmail.debug"))
  877.             dump('WEBMAIL: '+msg+'\n');
  878.     },
  879.  
  880.  
  881.     addEmailButton : function(accountName) {
  882.         this.debug('addEmailButton('+accountName+')');
  883.  
  884.         var mItem;
  885.         var mPopup;
  886.         var tbButton;
  887.         var tbItem=null;
  888.         var stack;
  889.         var vbox;
  890.         var previewBox;
  891.         var draggableBox;
  892.         var myID="webmail-toolbaritem-"+accountName;
  893.         var myService;
  894.         var myProvider;
  895.         var mSpacer;
  896.         var spacer2,spacer3,hbox,vbox2;
  897.         var toolbox = document.getElementById('navigator-toolbox');
  898.         var palette = toolbox.palette;
  899.  
  900.         // Check if button already exists - if it does, assume that it is OK
  901.         try {
  902.             tbItem=document.getElementById(myID);
  903.         } catch (ex) {}
  904.  
  905.         if (tbItem) {
  906.             return false;
  907.         }
  908.  
  909.         // MERC - JCH: Check if account is already in palette so as not to create duplicates
  910.         var isItem = palette.getElementsByAttribute("id", myID);
  911.  
  912.         dump(" ~~~~~~~~~~ addEmailButton() number of " +accountName+ " accounts on palette: " +isItem.length+ " \n");
  913.         if (isItem.length > 0)
  914.             return false;
  915.  
  916.         try {
  917.             myProvider=this.Prefs.getCharPref("provider."+accountName);
  918.         } catch (ex) {}
  919.         if (myProvider && myProvider != "") {
  920.             myService=this.getServiceById(myProvider);
  921.         }
  922.  
  923.         // Construction of the menupopup
  924.         mPopup=document.createElement("menupopup");
  925.         mItem=document.createElement("menuitem");
  926.         mItem.setAttribute("label","Read "+accountName);
  927.         if (myService) {
  928.             mItem.setAttribute("image",myService.icon);
  929.             mItem.setAttribute("class","menuitem-iconic");
  930.         }
  931.         mItem.setAttribute("webmailAccel",accountName);
  932.         mItem.setAttribute("tooltiptext","Go to inbox for "+accountName);
  933.         mItem.setAttribute("oncommand","webmail.read('"+accountName+"');");
  934.         mPopup.appendChild(mItem);
  935.         
  936.         // JMC - If we don't have a valid compose page, don't show the button
  937.         if (myService && myService.writeurl.length > 0)
  938.         {
  939.             mItem=document.createElement("menuitem");
  940.             mItem.setAttribute("label","Write Mail");
  941.             mItem.setAttribute("tooltiptext","Create a new Email using "+accountName);
  942.             mItem.setAttribute("oncommand","webmail.write('"+accountName+"');");
  943.             mPopup.appendChild(mItem);
  944.         }
  945.         
  946.         // JMC - If we don't have a valid addressbook page, don't show the button
  947.         if (myService && myService.addressurl.length > 0)
  948.         {
  949.             mItem=document.createElement("menuitem");
  950.             mItem.setAttribute("label","Address Book");
  951.             mItem.setAttribute("tooltiptext","Go to the address book for "+accountName);
  952.             mItem.setAttribute("oncommand","webmail.address('"+accountName+"');");
  953.             mPopup.appendChild(mItem);
  954.         }
  955.         
  956.         mItem=document.createElement("menuseparator");
  957.         mPopup.appendChild(mItem);
  958.         mItem=document.createElement("menuitem");
  959.         mItem.setAttribute("label","Manage Email Account...");
  960.         mItem.setAttribute("tooltiptext","Manage "+accountName+" webmail account information");
  961.         mItem.setAttribute("oncommand","this.parentNode.hidePopup();webmail.openManage('"+accountName+"');");
  962.         mPopup.appendChild(mItem);
  963.         mPopup.setAttribute("position","at_pointer");
  964.         mPopup.setAttribute("label","NewEmailButton");
  965.         mPopup.setAttribute("id","webmail-menu-"+accountName);
  966.  
  967.         var popupSet = document.createElement("popupset");
  968.         popupSet.appendChild(mPopup);
  969.  
  970.         // construct fancy looking button
  971.         var imageLeft=document.createElement("image");
  972.         imageLeft.setAttribute("id","webmail-button-left-edge");
  973.         spacer=document.createElement("spacer");
  974.         spacer.setAttribute("id","webmail-button-slice");
  975.         spacer.setAttribute("flex","1");
  976.         var imageRight=document.createElement("image");
  977.         imageRight.setAttribute("id","webmail-button-right-edge");
  978.         hbox=document.createElement("hbox");
  979.         hbox.appendChild(imageLeft);
  980.         hbox.appendChild(spacer);
  981.         hbox.appendChild(imageRight);
  982.         hbox.setAttribute("align","center");
  983.         hbox.setAttribute("pack","end");
  984.         hbox.setAttribute("style","width: 80px;");
  985.         hbox.setAttribute("id","webmailClickStyleTarget-"+accountName);
  986.         var clickStyleTarget = hbox;
  987.  
  988.         spacer=document.createElement("spacer");
  989.         spacer.setAttribute("style","height: 1px;");
  990.         vbox=document.createElement("vbox");
  991.         vbox.appendChild(spacer);
  992.         //vbox.appendChild(hbox);
  993.  
  994.         var box=document.createElement("box");
  995.         box.setAttribute("flex","1");
  996.         box.setAttribute("id","webmailPopupTarget-"+accountName);
  997.         box.setAttribute("style","margin-top: 1px;");
  998.         hbox=document.createElement("hbox");
  999.         hbox.appendChild(box);
  1000.         hbox.setAttribute("style","width: 80px;");
  1001.         hbox.setAttribute("align","stretch");
  1002.  
  1003.         spacer=document.createElement("spacer");
  1004.         spacer.setAttribute("flex","1");
  1005.         spacer.setAttribute("style","min-width: 6px;");
  1006.         image2=document.createElement("image");
  1007.         if (myService) {
  1008.             image2.setAttribute("src",myService.icon);
  1009.         } else {
  1010.             image2.setAttribute("src","chrome://browser/skin/icons/mail_sm.png");
  1011.         }
  1012.         image2.setAttribute("left","0");
  1013.         image2.setAttribute("top","0");
  1014.         image2.setAttribute("class","toolbarbutton-icon rolloverFlash");
  1015.         var imageButton = document.createElement('toolbarbutton');
  1016.         imageButton.setAttribute('image','chrome://browser/skin/icons/mail_sm.png');
  1017.         imageButton.setAttribute('tooltiptext','Webmail');
  1018.         imageButton.setAttribute('id','webmail-menu-image-'+accountName);
  1019.         spacer2=document.createElement("spacer");
  1020.         spacer2.setAttribute("flex","1");
  1021.         //construction of the toolbarbutton (visible)
  1022.         tbButton=document.createElement("toolbarbutton");
  1023. //        tbButton.setAttribute("type","menu-button");
  1024.         tbButton.setAttribute("oncommand","if (event.target==this) webmail.read('"+accountName+"');");
  1025.  
  1026.         tbButton.setAttribute("tooltiptext", this.getEmailAddress(accountName, myService, myProvider))
  1027.         tbButton.setAttribute("id","webmail-tb-button-"+accountName);
  1028.         tbButton.setAttribute("allowtransparency","true");
  1029.         tbButton.setAttribute("class","webmail-toolbarbutton");
  1030.         tbButton.setAttribute("allowTransparency","true");
  1031.         tbButton.setAttribute("label",accountName);
  1032.         tbButton.setAttribute("baselabel",accountName);
  1033.         tbButton.setAttribute("style","min-width: 60px !important;");
  1034.         // Make the button have acceltext when webmail checking is done.
  1035.         tbButton.setAttribute("webmailAccel",accountName);
  1036.         //tbButton.appendChild(mPopup);
  1037.         spacer3=document.createElement("spacer");
  1038.         spacer3.setAttribute("flex","1");
  1039.         spacer3.setAttribute("style","min-width: 4px !important;");
  1040.         var dropmarker = document.createElement('dropmarker');
  1041.         dropmarker.setAttribute('id','webmail-dropmarker-'+accountName);
  1042.         dropmarker.setAttribute('class','webmail-dropmarker');
  1043.         dropmarker.setAttribute('align','center');
  1044.         imageRight=document.createElement("image");
  1045.         //imageRight.setAttribute("style","list-style-image: inherit; margin-right: 6px;");
  1046.         dropmarker.setAttribute("onmousedown","document.getElementById('webmailClickStyleTarget-"+accountName+
  1047.             "').setAttribute('clickDown','true');");
  1048.         dropmarker.setAttribute("onmouseup","document.getElementById('webmailClickStyleTarget-"+accountName+
  1049.             "').removeAttribute('clickDown');");
  1050.         dropmarker.setAttribute("onmouseout","document.getElementById('webmailClickStyleTarget-"+accountName+
  1051.             "').removeAttribute('clickDown');");
  1052.  
  1053.         dropmarker.setAttribute("onclick","document.getElementById('webmail-menu-"+accountName+
  1054.                                 "').showPopup(document.getElementById('webmailPopupTarget-"+accountName+
  1055.                                 "'),-1,-1,'popup','bottomleft','bottomleft');");
  1056.  
  1057.         dropmarker.appendChild(imageRight);
  1058.         var hbox2=document.createElement("hbox");
  1059.         hbox2.appendChild(spacer);
  1060.         hbox2.appendChild(imageButton);
  1061.         hbox2.appendChild(spacer2);
  1062.         hbox2.appendChild(tbButton);
  1063.         hbox2.appendChild(spacer3);
  1064.         hbox2.appendChild(dropmarker);
  1065.         hbox2.setAttribute("tooltip",accountName+" Webmail Account");
  1066.         hbox2.setAttribute("align","center");
  1067.         hbox2.setAttribute("pack","end");
  1068.  
  1069.         var spacer4 = document.createElement("spacer");
  1070.         spacer4.setAttribute("style","height: 1px;");
  1071.         stack=document.createElement("stack");
  1072.         stack.appendChild(spacer4);
  1073.         stack.appendChild(clickStyleTarget);
  1074.         stack.appendChild(hbox);
  1075.         stack.appendChild(hbox2);
  1076.         stack.setAttribute("align","center");
  1077.         stack.setAttribute("pack","center");
  1078.         stack.setAttribute("id","webmail-button-container-"+accountName);
  1079.         stack.setAttribute("style","width: 80px;");
  1080.  
  1081.         spacer=document.createElement("spacer");
  1082.         spacer.setAttribute("style","width:4px !important");
  1083.         spacer2=document.createElement("spacer");
  1084.         spacer2.setAttribute("style","width:4px !important");
  1085.  
  1086.         hbox=document.createElement("hbox");
  1087.         hbox.appendChild(spacer);
  1088.         hbox.appendChild(stack);
  1089.         hbox.appendChild(spacer2);
  1090.  
  1091.         spacer=document.createElement("spacer");
  1092.         spacer.setAttribute("style","min-width:2px !important");
  1093.         spacer.setAttribute("flex","1");
  1094.         spacer2=document.createElement("spacer");
  1095.         spacer2.setAttribute("style","min-width:2px !important");
  1096.         spacer2.setAttribute("flex","1");
  1097.         spacer2.setAttribute("id","webmailPopupTarget-"+accountName);
  1098.  
  1099.         vbox=document.createElement("vbox");
  1100.         vbox.appendChild(spacer);
  1101.         vbox.appendChild(hbox);
  1102.         vbox.appendChild(spacer2);
  1103.         vbox.setAttribute("class","webmail-content");
  1104.  
  1105.         // construction of preview toolbarbutton
  1106.         previewBox=document.createElement("toolbarbutton");
  1107.         newImage=document.createElement("image");
  1108.         if (myService) {
  1109.             newImage.setAttribute("src",myService.icon);
  1110.         } else {
  1111.             newImage.setAttribute("src","chrome://browser/skin/icons/mail_sm.png");
  1112.         }
  1113.         previewBox.appendChild(newImage);
  1114.         previewBox.setAttribute("class","webmail-preview");
  1115.         previewBox.setAttribute("mousethrough","never");
  1116.         previewBox.setAttribute("label",accountName);
  1117.         previewBox.setAttribute("style","min-width: 60px !important;");
  1118.  
  1119.         // construction of draggable toolbarbutton
  1120.         draggableBox=document.createElement("toolbarbutton");
  1121.         draggableBox.setAttribute("class","webmail-draggable");
  1122.         draggableBox.setAttribute("mousethrough","never");
  1123.         draggableBox.setAttribute("label",accountName);
  1124.         draggableBox.setAttribute("style","min-width: 60px !important;");
  1125.  
  1126.         // construction of the toolbaritem
  1127.         tbItem=document.createElement("toolbaritem");
  1128.         tbItem.setAttribute("label",accountName);
  1129.         var myID="webmail-toolbaritem-"+accountName;
  1130.         tbItem.setAttribute("id",myID);
  1131.         tbItem.setAttribute("class","webmail-toolbaritem");
  1132.         tbItem.setAttribute("title",accountName);
  1133.         tbItem.setAttribute("toolgroup","personal");
  1134.         stack=document.createElement("stack");
  1135.         stack.appendChild(popupSet);
  1136.         stack.appendChild(vbox);
  1137.         stack.appendChild(previewBox);
  1138.         stack.appendChild(draggableBox);
  1139.         tbItem.appendChild(stack);
  1140.  
  1141.         var toolbar = toolbox.firstChild;
  1142.         var placed = false;
  1143.         while (toolbar) {
  1144.             if (toolbar.currentSetAtLoadTime) {
  1145.                 this.debug(' looking at toolbar: '+toolbar.id+', currentSet: '
  1146.                            +toolbar.currentSetAtLoadTime);
  1147.                 var currentSet = toolbar.currentSetAtLoadTime.split(',');
  1148.                 for (var i = 0; i < currentSet.length; i++) {
  1149.                     this.debug('  '+currentSet[i]);
  1150.                     if (currentSet[i] == myID) {
  1151.                         // Found it!
  1152.                         placed = this.placeItemRelative(tbItem, toolbar, currentSet, i,10);
  1153.                         if (!placed) {
  1154.                             // That didn't work, so just tack it on the end
  1155.                             toolbar.appendChild(tbItem);
  1156.                             this.debug('   placed at end of toolbar!');
  1157.                             placed = true;
  1158.                         }
  1159.                         break;
  1160.                     }
  1161.                 }
  1162.             }
  1163.             if (toolbar.localName == 'multibar')
  1164.                 toolbar = toolbar.firstChild;
  1165.             else if (toolbar.localName == 'multibartray' && (!toolbar.nextSibling)) {
  1166.                 toolbar = toolbar.parentNode.nextSibling;
  1167.             } else {
  1168.                 toolbar = toolbar.nextSibling;
  1169.             }
  1170.         }
  1171.         var paletteItem = tbItem;
  1172.         if (placed) {
  1173.             paletteItem = tbItem.cloneNode(true);
  1174.         }
  1175.         // Regardless of whether this component got placed on a toolbar, we still
  1176.         // need to put it in the tool palette as well, because that represents the
  1177.         // set of all available toolbar items.
  1178.         palette.appendChild(paletteItem);
  1179.         return placed;
  1180.     },
  1181.  
  1182.     removeMenus : function(accountName) {
  1183.         var myItem;
  1184.         var myItems;
  1185.         try {
  1186.             while (myItem=document.getElementById("webmail-toolbaritem-"+accountName)) {
  1187.                 delete myItem.parentNode.removeChild(myItem);
  1188.             }
  1189.             var toolbox = document.getElementById('navigator-toolbox');
  1190.             var palette = toolbox.palette;
  1191.             myItems=palette.getElementsByAttribute("id","webmail-toolbaritem-"+accountName);
  1192.             for (var i=0;i<myItems.length;i++) {
  1193.                 delete myItems[i].parentNode.removeChild(myItems[i]);
  1194.             }
  1195.         } catch (ex) {
  1196.             this.debug("error removing menus for: "+accountName);
  1197.             this.debug(ex);
  1198.         }
  1199.     },
  1200.  
  1201.  
  1202.     setAutoLoginPref : function (accountName, myService, autoLogFlag) {
  1203.         // Get a domain name from the mail service login URL
  1204.         var domain = myService.passcarddomain;
  1205.         if (!domain) {
  1206.             var host = myService.inboxurl.replace(/.*:\/\/(.*)/,"$1");    // Remove http://
  1207.             if (host.indexOf("/") > 0)
  1208.                 host = host.substring(0,host.indexOf("/"));            // Remove /help/test.php?test=yes = mail.yahoo.com
  1209.             var domain = host.replace(/.*\.+(\w+\.\w+)$/,"$1");        // Remove mail. = yahoo.com
  1210.             //domain = 'aol.com'; //hackety hack
  1211.         }
  1212.         this.debug(' - domain: '+domain);
  1213.  
  1214.         // Get the passcard for the mail service login site
  1215.         var webmailPasscard = GetWebmailPasscard(domain, "webmail:"+accountName);
  1216.         if (!webmailPasscard) return;
  1217.         
  1218.         var passcardFlag;
  1219.         if (autoLogFlag) 
  1220.             passcardFlag = '2';
  1221.         else
  1222.             passcardFlag = '0';
  1223.         
  1224.         // Ensure this passcard is set up properly for auto login
  1225.         //this.debug(' autologin used to be: '+webmailPasscard.autologin);
  1226.         //webmailPasscard.autologin = '2';  // fill & submit
  1227.         //this.debug(' autologin is now: '+webmailPasscard.autologin);
  1228.         var passcardMgr = Components.classes["@mozilla.org/passwordmanager;1"]
  1229.                                     .getService(Components.interfaces.nsIPasswordManager);
  1230.         passcardMgr.updateSignon(
  1231.             webmailPasscard.host, webmailPasscard.passcard, webmailPasscard.user,
  1232.             webmailPasscard.password, passcardFlag, webmailPasscard.protect,
  1233.             webmailPasscard.lastUsed, webmailPasscard.uniqueID, webmailPasscard.advancedFields);
  1234.         },
  1235.  
  1236.     autoLogin : function(accountName, myService, action, aExtra) {
  1237.         this.debug('autoLogin(accountName:'+accountName+')');
  1238.  
  1239.         
  1240.         // Open a new tab on the login URL
  1241.         this.debug(' - opening new tab...');
  1242.         var newTab = gBrowser.addTabAt("about:blank");
  1243.         this.mBrowser = gBrowser.getBrowserForTab(newTab);
  1244.         this.mBrowser.webNavigation.loadURI(
  1245.             myService.inboxurl,
  1246.             Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE,
  1247.             null, null, null);
  1248.         gBrowser.selectedTab = newTab;
  1249.     },
  1250.  
  1251.     getCaptureByAccount : function(aAccountName) {
  1252.         for (var i=0;i<this.CapturedData.length;i++) {
  1253.             if (this.CapturedData[i].account==aAccountName) {
  1254.                 return this.CapturedData[i].data;
  1255.             }
  1256.         }
  1257.         return null;
  1258.     },
  1259.  
  1260.     setCaptureData : function(aAccountName,aData) {
  1261.         for (var i=0;i<this.CapturedData.length;i++) {
  1262.             if(this.CapturedData[i].account==aAccountName) {
  1263.                 this.CapturedData[i].data = aData;
  1264.                 return;
  1265.             }
  1266.         }
  1267.         var nData=this.CapturedData.length;
  1268.         this.CapturedData[nData]=new Object();
  1269.         this.CapturedData[nData].data = new String(aData);
  1270.         this.CapturedData[nData].account = new String(aAccountName);
  1271.     },
  1272.  
  1273.     getActionURLFromPref: function(prefix, accountName) {
  1274.         var myURL;        
  1275.         if (this.Prefs.getPrefType(prefix+accountName))
  1276.         {
  1277.             myURL = this.Prefs.getCharPref(prefix+accountName);
  1278.         } else {
  1279.             switch (prefix) {
  1280.                 case "InboxURL.":
  1281.                     myURL=this.getServiceById("webmail:feed:netscape").inboxurl;
  1282.                 case "WriteURL.":
  1283.                     myURL=this.getServiceById("webmail:feed:netscape").writeurl;
  1284.                 case "AddressURL.":
  1285.                     myURL=this.getServiceById("webmail:feed:netscape").addressurl;
  1286.                 }
  1287.         }
  1288.         return myURL;
  1289.     },
  1290.  
  1291.     doAction : function(accountName, action, aExtra) {
  1292.         
  1293.         var myURL;
  1294.         var myProvider;
  1295.         // Determine the provider
  1296.         if (this.Prefs.getPrefType("provider."+accountName)) {
  1297.             myProvider=this.Prefs.getCharPref("provider."+accountName);
  1298.         }
  1299.         
  1300.         // Check that the provider is valid
  1301.         if (myProvider)     myService=this.getServiceById(myProvider);        
  1302.         if (this.Prefs.getPrefType("autolog."+accountName) && this.Prefs.getCharPref("autolog."+accountName)=="true")
  1303.         {
  1304.             this.setAutoLoginPref(accountName, myService, true);
  1305.         }
  1306.         
  1307.         switch (action) {
  1308.             case "read":
  1309.                 if (!myProvider || myProvider == "webmail:other") {
  1310.                     myURL = this.getActionURLFromPref("InboxURL.", accountName);
  1311.                 } else {    
  1312.                     myURL=myService.inboxurl;        
  1313.                 }            
  1314.                 break;
  1315.                 
  1316.             case "write":
  1317.             case "mailto":
  1318.                 if (!myProvider || myProvider == "webmail:other") {
  1319.                     myURL = this.getActionURLFromPref("WriteURL.", accountName);                    
  1320.                 } else {            
  1321.                     myURL=myService.writeurl;    
  1322.                 }
  1323.                 break;
  1324.                 
  1325.             case "address":
  1326.                 if (!myProvider || myProvider == "webmail:other") {
  1327.                     myURL = this.getActionURLFromPref("AddressURL.", accountName);                    
  1328.                 } else {
  1329.                     myURL=myService.addressurl;                
  1330.                 }
  1331.                 break;
  1332.             
  1333.         }
  1334.         loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null);
  1335.         
  1336.     },
  1337.  
  1338.     doActionOld : function(accountName,action,aExtra) {
  1339.         var myProvider;
  1340.         var myService;
  1341.         var myURL;
  1342.         this.debug("doAction ("+accountName+","+action+") called");
  1343.         var doneauto=false;
  1344.         if (action.substr(0,9)=="continue_") {
  1345.             action=action.substr(9);
  1346.             doneauto=true;
  1347.         }
  1348.         // Determine the provider
  1349.         try {
  1350.             myProvider=this.Prefs.getCharPref("provider."+accountName);
  1351.         } catch (ex) {
  1352.             this.debug("no provider for account: "+accountName);
  1353.         }
  1354.         // Check that the provider is valid
  1355.         if (myProvider) {
  1356.             myService=this.getServiceById(myProvider);
  1357.         }
  1358.         // Determine the URL to go to
  1359.         if (!myProvider ||(myProvider && myProvider == "webmail:other")) {
  1360.             var prefix;
  1361.             if (action == "read") {
  1362.                 prefix="InboxURL.";
  1363.             } else if (action == "write" || action == "mailto") {
  1364.                 prefix="WriteURL.";
  1365.             } else if (action == "address") {
  1366.                 prefix="AddressURL.";
  1367.             } else {
  1368.                 this.debug("doAction called with invalid action!!!!!");
  1369.                 return;
  1370.             }
  1371.             try {
  1372.                 myURL = this.Prefs.getCharPref(prefix+accountName);
  1373.             } catch (ex) {
  1374.                 myURL = this.getServiceById("webmail:feed:netscape").inboxurl;
  1375.             }
  1376.         } else if (myService) {
  1377.             if (action == "read") {
  1378.                 myURL=myService.inboxurl;
  1379.             } else if (action == "write" || action == "mailto") {
  1380.                 myURL=myService.writeurl;
  1381.             } else if (action == "address") {
  1382.                 myURL=myService.addressurl;
  1383.             } else {
  1384.                 this.debug("doAction called with invalid action!!!!!");
  1385.                 return;
  1386.             }
  1387.             // if this service has "urlcapture" data needed, it needs to have been
  1388.             // set for this account, otherwise the default applies.  If no url
  1389.             // capture data is needed, just use the standard read/write/address url
  1390.             if (myService.urlcapture) {
  1391.                 this.debug("There is urlcapture defined for this webmail provider.");
  1392.                 var myCapture=this.getCaptureByAccount(accountName);
  1393.                 if (myCapture) {
  1394.                     this.debug("Capture data is defined");
  1395.                     this.debug("Capture data is: "+myCapture);
  1396.                     varlist=myService.urlcapture.split(';');
  1397.                     valuelist=myCapture.split(';');
  1398.                     if (varlist.length != valuelist.length) {
  1399.                         webmail.debug("FATAL problem with urlcapture.  Reverting to defaulturl.");
  1400.                         if (myService.defaulturl) {
  1401.                             myURL=myService.defaulturl
  1402.                         } else {
  1403.                             this.debug("Bad situation: urlcapture specified with no defaulturl");
  1404.                             this.debug("Attempting to use url without replacement -- probable failure");
  1405.                         }
  1406.                     } else {
  1407.                         for (var i=0;i<varlist.length;i++) {
  1408.                             this.debug("var="+varlist[i]);
  1409.                             this.debug("value="+valuelist[i]);
  1410.                             if (varlist[i] == ":host:") {
  1411.                                 myURL=myURL.replace(/\/\/.+?\//,"//"+valuelist[i]+"/");
  1412.                             } else {
  1413.                                 var x=new RegExp("!"+varlist[i],"gi");
  1414.                                 myURL=myURL.replace(x,valuelist[i]);
  1415.                             }
  1416.                         }
  1417.                     }
  1418.                 } else if (myService.defaulturl) {
  1419.                     this.debug("No URLCapture information defined");
  1420.                     myURL=myService.defaulturl
  1421.                 } else {
  1422.                     this.debug("Bad situation: urlcapture specified with no defaulturl");
  1423.                     this.debug("Attempting to use url without replacement -- probable failure");
  1424.                 }
  1425.             }
  1426.         }
  1427.         if (!myURL || myURL=="") {
  1428.             if (action == "read") {
  1429.                 myURL=this.getServiceById("webmail:feed:netscape").inboxurl;
  1430.             } else if (action == "write" || action == "mailto") {
  1431.                 myURL=this.getServiceById("webmail:feed:netscape").writeurl;
  1432.             } else if (action == "address") {
  1433.                 myURL=this.getServiceById("webmail:feed:netscape").addressurl;
  1434.             } else {
  1435.                 this.debug("doAction called with invalid action!!!!!");
  1436.                 return;
  1437.             }
  1438.         }
  1439.         this.debug("myURL="+myURL);
  1440.         // Check if autologon is to be done
  1441.         if (this.Prefs.getPrefType("autolog."+accountName) == this.Prefs.PREF_STRING) {
  1442.             this.debug("autolog is turned on, attempting to log in");
  1443.             autolog=this.Prefs.getCharPref("autolog."+accountName);
  1444.         } else {
  1445.             this.debug("autolog is not turned on or no pref exists");
  1446.             this.debug("this.Prefs.getPrefType('autolog."+accountName+"')="+this.Prefs.getPrefType("autolog."+accountName));
  1447.             this.debug("this.Prefs.PR_STRING="+this.Prefs.PREF_STRING);
  1448.             autolog="false";
  1449.         }
  1450.         if (!doneauto && autolog=="true") {
  1451.             
  1452.             // JMC - hack hack, bypass this ugly stuff for now
  1453.             if (action == 'read') {
  1454.                 this.autoLogin(accountName,myService,action,aExtra);
  1455.                 return;
  1456.             }
  1457.             
  1458.             // Do autologin only if needed
  1459.             this.debug("autolog is true, testing URL");
  1460.             // Determine "needauto" RegExp
  1461.             var needAuto;
  1462.             if (myService.needlogin) {
  1463.                 needAuto = new RegExp(myService.needlogin,"gi");
  1464.             } else {
  1465.                 needAuto = new RegExp("(login again)|(expired)|(login page)","gi");
  1466.             }
  1467.             this.debug("needAuto="+needAuto.source);
  1468.             // Try to access the URL
  1469.             var req = new XMLHttpRequest();
  1470.             try {
  1471.                 req.open("POST",myService.autologurl,true);
  1472.             } catch (ex) {
  1473.                 this.debug("error in open POST");
  1474.                 this.debug(ex);
  1475.             }
  1476.             req.onreadystatechange = function() {
  1477.                 res = null;
  1478.                 if (req.readyState != 4) {
  1479.                     webmail.debug("Ready State = "+req.readyState);
  1480.                     return;
  1481.                 }
  1482.                 if ( req.status && (req.status / 100) == 2)
  1483.                     res = req.responseText;
  1484.                 else if (req.status && req.status == 405) {
  1485.                     // Protocol not supported - use GET
  1486.                     req2 = new XMLHttpRequest();
  1487.                     try {
  1488.                         req2.open("GET",myService.autologurl,true);
  1489.                     } catch (ex) {
  1490.                         webmail.debug("error in open GET");
  1491.                         webmail.debug(ex);
  1492.                     }
  1493.                     req2.onreadystatechange = function() {
  1494.                         if (req2.readyState != 4) {
  1495.                             webmail.debug("Ready State = "+req2.readyState);
  1496.                             return;
  1497.                         }
  1498.                         if ( req2.status && (req2.status / 100) == 2)
  1499.                             res = req2.responseText;
  1500.                         if (res) {
  1501.                             var matchedNeedlogin=res.match(needAuto);
  1502.                             if (matchedNeedlogin) {
  1503.                                 // Auto login
  1504.                                 webmail.debug("got a match for need login");
  1505.                                 webmail.debug("attempting auto log in");
  1506.                                 webmail.debug("match = "+matchedNeedlogin);
  1507.                                 webmail.autoLogin(accountName,myService,action,aExtra);
  1508.                                 return;
  1509.                             } else {
  1510.                                 webmail.debug("Failed to match needlogin");
  1511.                                 webmail.debug("Assuming that the URL loads fine");
  1512.  
  1513.                                 // TODO MSD: DO NOT CHECK THIS IN WITH FOLLOWING LINE UNCOMMENTED
  1514.                                 //this.debug("res="+res);
  1515.                             }
  1516.                         } else {
  1517.                             webmail.debug("res is not defined, req.status="+req.status);
  1518.                             webmail.debug("proceeding with autologin");
  1519.                             webmail.autoLogin(accountName,myService,action,aExtra);
  1520.                             return;
  1521.                         }
  1522.                         if (action=="mailto") {
  1523.                             if (myService && myService.composefields) {
  1524.                                 webmail.finishHandleURI(myURL,aExtra,myService.composefields);
  1525.                             } else {
  1526.                                 webmail.finishHandleURI(myURL,aExtra);
  1527.                             }
  1528.                         } else {
  1529.                             loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null);
  1530.                         }
  1531.                     } //req2.onreadystatechange
  1532.                     try {
  1533.                         req2.send("");
  1534.                     } catch (ex) {
  1535.                         webmail.debug("error in req2.send");
  1536.                         webmail.debug(ex);
  1537.                         webmail.autoLogin(accountName,myService,action,aExtra);
  1538.                     }
  1539.                     return;
  1540.                 } // 405 status (wrong protocol)
  1541.                 if (res) {
  1542.                     var matchedNeedlogin=res.match(needAuto);
  1543.                     if (matchedNeedlogin) {
  1544.                         // Auto login
  1545.                         webmail.debug("got a match for need login");
  1546.                         webmail.debug("attempting auto log in");
  1547.                         webmail.debug("match = "+matchedNeedlogin);
  1548.                         webmail.autoLogin(accountName,myService,action,aExtra);
  1549.                         return;
  1550.                     } else {
  1551.                         webmail.debug("Failed to match needlogin");
  1552.                         webmail.debug("Assuming that the URL loads fine");
  1553.  
  1554.                         // TODO MSD: DO NOT CHECK THIS IN WITH FOLLOWING LINE UNCOMMENTED
  1555.     //                    this.debug("res="+res);
  1556.                     }
  1557.                 } else {
  1558.                     webmail.debug("res is not defined, req.status="+req.status);
  1559.                     webmail.debug("proceeding with autologin");
  1560.                     webmail.autoLogin(accountName,myService,action,aExtra);
  1561.                     return;
  1562.                 }
  1563.                 if (action=="mailto") {
  1564.                     if (myService && myService.composefields) {
  1565.                         webmail.finishHandleURI(myURL,aExtra,myService.composefields);
  1566.                     } else {
  1567.                         webmail.finishHandleURI(myURL,aExtra);
  1568.                     }
  1569.                 } else {
  1570.                     loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null);
  1571.                 }
  1572.  
  1573.             } // req.onreadystatechange()
  1574.             try {
  1575.                 req.send("");
  1576.             } catch (ex) {
  1577.                 this.debug("error in req.send");
  1578.                 this.debug(ex);
  1579.                 this.autoLogin(accountName,myService,action,aExtra);
  1580.             }
  1581.             return;
  1582.         } // if (!doneauto && autolog=="true")
  1583.         if (action=="mailto") {
  1584.             if (myService && myService.composefields) {
  1585.                 this.finishHandleURI(myURL,aExtra,myService.composefields);
  1586.             } else {
  1587.                 this.finishHandleURI(myURL,aExtra);
  1588.             }
  1589.         } else {
  1590.             loadURIWithOpenPref(myURL,'browser.tabs.personaltoolbarbutton.open',null,null);
  1591.         }
  1592.     },
  1593.  
  1594.     read : function(accountName) {
  1595.         this.doAction(accountName,"read");
  1596.     },
  1597.  
  1598.     write : function(accountName) {
  1599.         this.doAction(accountName,"write");
  1600.     },
  1601.  
  1602.     address : function(accountName) {
  1603.         this.doAction(accountName,"address");
  1604.     },
  1605.  
  1606.     finishAction : function(aAccountName,aAction,aExtra) {
  1607.         setTimeout("webmail.doAction('"+aAccountName+"','continue_"+aAction+"','"+aExtra+"');",1);
  1608.     },
  1609.  
  1610.  
  1611.     handleURI : function (aURI) {
  1612.         // aHref: URI object
  1613.         // load "write" URL of default and then fill in form
  1614.         // from the uri
  1615.         // Is this really a mailto: uri?
  1616.         this.debug("RECEIVED A MAILTO URI!!!!!");
  1617.         this.debug("***********************\n"+aURI+"\n***********************");
  1618.         if (aURI.scheme != "mailto:"){
  1619.             // TODO: If not - pass it away or something????
  1620.         }
  1621.         // Check Prefs
  1622.         var doMailto=false;
  1623.         if (this.Prefs.getPrefType("mailto")==this.Prefs.PREF_BOOL) {
  1624.             doMailto=this.Prefs.getBoolPref("mailto");
  1625.         }
  1626.         if (!doMailto) {
  1627.             // TODO: Pass to other services or drop on floor??????
  1628.         }
  1629.         if (this.Prefs.getPrefType("default") != this.Prefs.PREF_STRING) {
  1630.             this.debug("No default set!! Unable to process mailto: HREF.");
  1631.             var x=new Error();
  1632.             x.message="No default webmail account defined.  Unable to process HREF's";
  1633.             throw x;
  1634.         }
  1635.         var accountName=this.Prefs.getCharPref("default");
  1636.  
  1637.         // Remainder of processing happens in finishHandleURI()
  1638.  
  1639.         this.doAction(accountName,"mailto",aURI);
  1640.     },
  1641.  
  1642.     handleURIEndLoad : function (aRequest,aStatus,aWebProgress) {
  1643.         webmail.debug("in handleURIEndLoad");
  1644.         webmail.debug("this.mAddress = "+this.mAddress);
  1645.         const nsIChannel = Components.interfaces.nsIChannel;
  1646.       var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec;
  1647.       if (urlStr.indexOf(this.mFinalURL)>=0){
  1648.           webmail.debug("reached "+this.mFinalURL+", proceeding to fill in To: information.");
  1649.             var myinputs=aWebProgress.DOMWindow.document.getElementsByTagName("input");
  1650.             var toNames, subjectNames;
  1651.             if (this.mComposeFields) {
  1652.                 if (this.mComposeFields.match(/to=([^;]+)/i)) {
  1653.                     toNames = [ RegExp.$1 ];
  1654.                 }
  1655.                 if (this.mComposeFields.match(/subject=([^;]+)/i)) {
  1656.                     subjectNames = [ RegExp.$1 ];
  1657.                 }
  1658.             }
  1659.             if (!toNames) {
  1660.                 var toNames=[ "mailTo", "to_compose", "to", "msg_to", "tofield", "send_to" ];
  1661.             }
  1662.             if (!subjectNames) {
  1663.                 var subjectNames=[ "msg_subject", "subject", "mailSubject", "Subj" ];
  1664.             }
  1665.             var myTo, mySubj, myPossibleTo, myPossibleSubj;
  1666.             for (var i=0;i<myinputs.length;i++){
  1667.                 webmail.debug("checking "+myinputs[i].name+" against list of To: fields");
  1668.                 for (var j=0;j<toNames.length;j++) {
  1669.                     if (myinputs[i].name && myinputs[i].name==toNames[j]) {
  1670.                         myTo=myinputs[i];
  1671.                     }
  1672.                 }
  1673.                 if (!myTo && myinputs[i].name && myinputs[i].name.match(/to/i)) {
  1674.                     myPossibleTo=myinputs[i];
  1675.                 }
  1676.                 for (var j=0;j<subjectNames.length;j++) {
  1677.                     if (myinputs[i].name && myinputs[i].name==subjectNames[j]) {
  1678.                         mySubj=myinputs[i];
  1679.                     }
  1680.                 }
  1681.                 if (!mySubj && myinputs[i].name && myinputs[i].name.match(/subj/i)) {
  1682.                     myPossibleSubj=myinputs[i];
  1683.                 }
  1684.             }
  1685.             if (!myTo && myPossibleTo) myTo=myPossibleTo;
  1686.             if (myTo && this.mAddress) {
  1687.                 myTo.value=this.mAddress;
  1688.             }
  1689.             if (!mySubj && myPossibleSubj) mySubj=myPossibleSubj;
  1690.             if(mySubj && this.mSubject) {
  1691.                 mySubj.value=this.mSubject;
  1692.             }
  1693.               this.mBrowser.removeProgressListener(this);
  1694.           } else {
  1695.               webmail.debug("failed to find "+this.mFinalURL+" in "+urlStr);
  1696.           }
  1697.     },
  1698.  
  1699.     finishHandleURI : function (aWriteURL,aMailtoURI,aComposeFields) {
  1700.         // I should be able to navigate to aWriteURL and fill in the form using aMailtoURI
  1701.         var myAddress;
  1702.         if (aMailtoURI.match(/mailto:([^?&]+)/)) {
  1703.             myAddress=RegExp.$1;
  1704.         }
  1705.         var mySubject;
  1706.         if (aMailtoURI.match(/mailto:[^?&]+[?&]subject=([^?&]+)/)) {
  1707.             mySubject=RegExp.$1;
  1708.         }
  1709.         this.debug("aMailtoURI="+aMailtoURI);
  1710.         this.debug("myAddress="+myAddress);
  1711.         this.debug("mySubject="+mySubject);
  1712.         myEndLoad=new WebmailEndLoadListener(aWriteURL,true);
  1713.         myEndLoad.mAddress=myAddress;
  1714.         myEndLoad.mSubject=mySubject;
  1715.         myEndLoad.mFinalURL=aWriteURL;
  1716.         myEndLoad.mComposeFields=aComposeFields;
  1717.         myEndLoad.endDocumentLoad=this.handleURIEndLoad;
  1718.         myEndLoad.openIt();
  1719.     },
  1720.  
  1721.  
  1722.     placeItemRelative : function(newItem, toolbar, currentSet, index, maxIterations) {
  1723.         // Look for toolbar buttons that are progressively further away in
  1724.         // the currentSet
  1725.  
  1726.         // JMC - Special case, index = 0
  1727.         if (index == 0) {
  1728.             var nextItem = toolbar.firstChild;
  1729.             if (nextItem) {
  1730.                 toolbar.insertBefore(newItem, nextItem);
  1731.             } else {
  1732.                 toolbar.appendChild(newItem);
  1733.             }
  1734.             return true;
  1735.         }
  1736.  
  1737.         var j = 1;
  1738.         var placed = false;
  1739.         if (!maxIterations) maxIterations = 10;
  1740.         while (!placed && (j < maxIterations)) {
  1741.             // First try placing it AFTER the previous item
  1742.             var nextItem;
  1743.             if (index >= j) {
  1744.                 // this doesnt work for spacers and other anonymous elements
  1745.                 var prevItem = document.getElementById(currentSet[index-j]);
  1746.                 if (!prevItem)
  1747.                 {
  1748.                     // Count the number of these special elements which occur in the toolbarset
  1749.                     // BEFORE this point, and then get the xth of them
  1750.                     var specialCountLimit = 0;
  1751.                     for (var i=0; i < index; i++) {
  1752.                         if (currentSet[i] == currentSet[index-j])
  1753.                             specialCountLimit++;
  1754.                     }
  1755.  
  1756.                     var paletteItem = toolbar.firstChild;
  1757.                     var specialCount =0;
  1758.  
  1759.                     while (paletteItem) {
  1760.                         var paletteId = paletteItem.id;
  1761.                         var stringLen = currentSet[index-j].length;
  1762.                         var aId = currentSet[index-j];
  1763.                         if (paletteId.substring(0,stringLen) == aId) {
  1764.                             specialCount++;
  1765.                             if (specialCount >= specialCountLimit) {
  1766.                                 prevItem = paletteItem;
  1767.                                 break;
  1768.                             }
  1769.                         }
  1770.                         paletteItem = paletteItem.nextSibling;
  1771.                     }
  1772.                 }
  1773.                 if (prevItem) {
  1774.                     nextItem = prevItem.nextSibling;
  1775.                     if (prevItem.nextSibling) {
  1776.                         toolbar.insertBefore(newItem, prevItem.nextSibling);
  1777.                         this.debug('   placed after '+currentSet[index-j]+'!');
  1778.                         placed = true;
  1779.                     } else {
  1780.                         toolbar.appendChild(newItem);
  1781.                         placed = true;
  1782.                     }
  1783.                 }
  1784.             }
  1785.             if (!placed && (index < currentSet.length-j)) {
  1786.                 // That didn't work, so try placing it BEFORE the next item
  1787.                 nextItem = document.getElementById(currentSet[index+1]);
  1788.                 if (!nextItem)
  1789.                 {
  1790.                     // Count the number of these special elements which occur in the toolbarset
  1791.                     // BEFORE this point, and then get the xth of them
  1792.                     var specialCountLimit = 0;
  1793.                     for (var i=index; i > 0; i--) {
  1794.                         if (currentSet[i] == currentSet[index+1])
  1795.                             specialCountLimit++;
  1796.                     }
  1797.  
  1798.                     var paletteItem = toolbar.lastChild;
  1799.                     var specialCount =0;
  1800.  
  1801.                     while (paletteItem) {
  1802.                         var paletteId = paletteItem.id;
  1803.                         var stringLen = currentSet[index+1].length;
  1804.                         var aId = currentSet[index+1];
  1805.                         if (paletteId.substring(0,stringLen) == aId) {
  1806.                             specialCount++;
  1807.                             if (specialCount >= specialCountLimit) {
  1808.                                 nextItem = paletteItem;
  1809.                                 break;
  1810.                             }
  1811.                         }
  1812.                         paletteItem = paletteItem.previousSibling;
  1813.                     }
  1814.                 }
  1815.                 if (nextItem) {
  1816.                     toolbar.insertBefore(newItem, nextItem);
  1817.                     this.debug('   placed before '+currentSet[index+1]+'!');
  1818.                     placed = true;
  1819.                 }
  1820.             }
  1821.             j++;
  1822.         }
  1823.         return placed;
  1824.     },
  1825.  
  1826. }
  1827.  
  1828. function sort_services(first, second) {
  1829.     if (first.id == "webmail:feed:netscape") {
  1830.         return -1;
  1831.     }
  1832.     if (second.id == "webmail:feed:netscape") {
  1833.         return 1;
  1834.     }
  1835.     if (first.name < second.name) {
  1836.         return -1;
  1837.     } else {
  1838.         return 1;
  1839.     }
  1840. }
  1841.  
  1842. function checkNewWebmail(accountName) {
  1843.     // Confirm that the account wants updates
  1844.     webmail.debug("checkNewWebmail("+accountName+") called");
  1845.     var checkUpdates;
  1846.     var notify;
  1847.     var oldNum=0;
  1848.     var numNew=0;
  1849.     var changed=false;
  1850.     if (webmail.Prefs.getPrefType("checkUpdates."+accountName) == webmail.Prefs.PREF_STRING) {
  1851.         checkUpdates=webmail.Prefs.getCharPref("checkUpdates."+accountName);
  1852.     } else {
  1853.         checkUpdates="false";
  1854.     }
  1855.     if (!checkUpdates || checkUpdates == "false") return;
  1856.     // Check for last update and compare to current time
  1857.     var now = (new Date()).getTime();
  1858.     webmail.debug("now="+now);
  1859.     var then = 0;
  1860.     if (webmail.Prefs.getPrefType("lastCheck."+accountName) == webmail.Prefs.PREF_STRING) {
  1861.         var lastCheck = webmail.Prefs.getCharPref("lastCheck."+accountName);
  1862.         //then=new Date(lastCheck);
  1863.         then = lastCheck;
  1864.     }
  1865.     webmail.debug("then="+then);
  1866.     var interval = 0;
  1867.     if (webmail.Prefs.getPrefType("emailfreq."+accountName)) {
  1868.         var sInterval = webmail.Prefs.getCharPref("emailfreq."+accountName);
  1869.         interval = 60000 * sInterval;
  1870.     }
  1871.     var diff = now - then;
  1872.     webmail.debug("Time since last check = "+diff);
  1873.     webmail.debug("interval = "+interval);
  1874.     if (diff > interval) {
  1875.         webmail.Prefs.setCharPref("lastCheck."+accountName,now);
  1876.     } else {
  1877.         setTimeout("checkNewWebmail('"+accountName+"');",interval);
  1878.         return;
  1879.     }
  1880.     try {
  1881.         // Determine the value to put into the acceltext
  1882.  
  1883.         var doesExist=webmail.Prefs.getPrefType("provider."+accountName);
  1884.         if (doesExist) {
  1885.             var provider=webmail.Prefs.getCharPref("provider."+accountName);
  1886.         }
  1887.         if (!provider || provider=="")
  1888.             return;
  1889.  
  1890.         var myService=webmail.getServiceById(provider);
  1891.         if (!myService)
  1892.             return;
  1893.  
  1894.         var notify=myService.notify;
  1895.         if (!notify || notify=="")
  1896.             return;
  1897.  
  1898.         webmail.debug("notify="+notify);
  1899.         var params=notify.match(/[^;]+/g);
  1900.         if (!params || params.length < 1)
  1901.             return;
  1902.         webmail.debug('found '+params.length+' params');
  1903.  
  1904.         if (params[0].substr(0,7) == "scrape=") {
  1905.             webmail.debug('processing scrape');
  1906.             var nURL=params[0].substr(7);
  1907.             var nPre=null;
  1908.             var nPost=null;
  1909.             var nDoAuto=true; // autologin is default
  1910.             var nGetStr=null;
  1911.             var isPost=false;
  1912.             for (var i=1;i<params.length;i++) {
  1913.                 if (params[i].substr(0,4) == "pre=") nPre=params[i].substr(4);
  1914.                 else if (params[i].substr(0,5) =="post=") nPost=params[i].substr(5);
  1915.                 else if (params[i] == "neverauto") nDoAuto=false;
  1916.                 else if (params[i].substr(0,8) == "httpget=") {
  1917.                     nGetStr=params[i].substr(8);
  1918.                 } else if (params[i].substr(0,9) == "httppost=") {
  1919.                     nGetStr=params[i].substr[9];
  1920.                     isPost=true;
  1921.                 }
  1922.             }
  1923.             if (!nPre || !nPost) {
  1924.                 webmail.debug("pre or post info missing for scrape");
  1925.                 return;
  1926.             }
  1927.             if (nGetStr) {
  1928.                 webmail.debug('processing get-string');
  1929.                 nGetStr=nGetStr.replace(/\|/g,"&");
  1930.                 if ((nGetStr.indexOf("!password") > -1) ||
  1931.                     (nGetStr.indexOf("!userid") > -1)) {
  1932.                     // Get userId and password and do replacement
  1933.                     var myUserid;
  1934.                     var myPassword;
  1935.                     var fHost={ value: "" }
  1936.                     var fUser={ value: "" }
  1937.                     var fPassword={ value: "" }
  1938.                     var mKey="webmail:"+accountName;
  1939.  
  1940.                     // MERC - JCH: Get passcard info
  1941.                     var domain = myService.passcarddomain;
  1942.                     var pc = GetWebmailPasscard(domain, mKey);
  1943.                     if (pc) {
  1944.                         webmail.debug('Found a passcard for this account, un/pw = '+pc.user+'/'+pc.password);
  1945.                         myUserid = pc.user;
  1946.                         myPassword = pc.password;
  1947.                     } else {
  1948.                         webmail.debug('\nWEBMAIL ERROR: Did not find passcard for mKey = '+mKey+'\n');
  1949.                         return;
  1950.                     }
  1951.  
  1952.                     if (!myUserid && !myPassword) {
  1953.                         webmail.debug("userID or Password not found, but needed");
  1954.                         return;
  1955.                     }
  1956.                     if (nGetStr.indexOf("!password") > -1)
  1957.                         nGetStr = nGetStr.replace(/\!password/g,myPassword);
  1958.                     if (nGetStr.indexOf("!userid") > -1)
  1959.                         nGetStr = nGetStr.replace(/\!userid/g,myUserid);
  1960.                 }
  1961.                 nGetStr=nGetStr.replace(/\|/g,"\&");
  1962.                 nGetStr=encodeURI(nGetStr);
  1963.                 if (!isPost) {
  1964.                     nURL=nURL+"?"+nGetStr;
  1965.                 }
  1966.             }
  1967.             //if (nDoAuto) {
  1968.             //    webmail.autoLogin(accountName,myService);
  1969.             //}
  1970.             webmail.debug("myX should be "+nPre+"\d+"+nPost);
  1971.             var myX= new RegExp(nPre+"\\d+"+nPost,"");
  1972.             webmail.debug("myX="+myX.source);
  1973.             var proto="GET";
  1974.             if (isPost) {
  1975.                 proto="POST";
  1976.             }
  1977.             var req = new XMLHttpRequest();
  1978.             try {
  1979.                 req.open(proto,nURL,true);
  1980.             } catch (ex) {
  1981.                 webmail.debug("error in "+proto);
  1982.                 webmail.debug(ex);
  1983.             }
  1984.             webmail.debug("done open()");
  1985.             req.onerror = function(ex) {
  1986.                 dump("WEBMAIL REQUEST: req.onerror called\n");
  1987.                 dump(ex);
  1988.             }
  1989.             req.onprogress = function (ex) {
  1990.                 dump("WEBMAIL REQUEST: req.progress called\n");
  1991.             }
  1992.             req.onreadystatechange = function () {
  1993.                 dump("WEBMAIL REQUEST: req.onreadystatechange called\n");
  1994.                 if (req.readyState==4) {
  1995.                     // put all post processing here
  1996.                     var res = null;
  1997.                     if ( req.status && (req.status / 100) == 2) {
  1998.                         res = req.responseText;
  1999.                     }    else {
  2000.                         webmail.debug("req.status="+req.status);
  2001.                     }
  2002.                     if (!res){
  2003.                         return;
  2004.                     }
  2005.                     var ans=res.match(myX);
  2006.                     webmail.debug("res.match(myX)="+ans);
  2007.                     if (ans) {
  2008.                         var myText=ans[0];
  2009.                         var preX=new RegExp(nPre,"");
  2010.                         var temp=myText.substr(myText.match(preX)[0].length);
  2011.                         numNew=temp.match(/\d+/)[0];
  2012.                     } else {
  2013.                         webmail.debug("no match for myX in: \n"+res);
  2014.                         return;
  2015.                     }
  2016.                     //oldNum=webmail.getChecked(accountName);
  2017.                     webmail.setChecked(accountName,numNew);
  2018.                     //var netNew=numNew-oldNum;
  2019.                     var netNew = numNew;
  2020.                     if (netNew < 0) netNew=0;
  2021.                     // Get the list of elements which need to be updated
  2022.                     var updateElements = null;
  2023.                     try {
  2024.                         updateElements = document.getElementsByAttribute("webmailAccel",accountName);
  2025.                     } catch (ex) {}
  2026.                     if (updateElements && updateElements.length > 0) {
  2027.                         for (var i=0;i<updateElements.length;i++) {
  2028.                           // Update the elements with the new values or remove the
  2029.                           // acceltext.
  2030.                           if (updateElements[i].localName == "toolbarbutton") {
  2031.                               // toolbarbuttons don't accept acceltext - must change the label and
  2032.                               // tooltiptext
  2033.                               if (checkUpdates == "true" && netNew > 0) {
  2034.                                   webmail.debug("updating element: "+updateElements[i].id + " type: "+updateElements[i].localName);
  2035.                                   updateElements[i].setAttribute("label",updateElements[i].getAttribute("baselabel") + "   " +netNew);
  2036.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages ("+numNew+" unread total)");
  2037.                               } else if (numNew) {
  2038.                                   updateElements[i].setAttribute("label",updateElements[i].getAttribute("baselabel"));
  2039.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages ("+numNew+" unread total)");
  2040.                               } else {
  2041.                                   updateElements[i].setAttribute("label",updateElements[i].getAttribute("baselabel"));
  2042.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account");
  2043.                               }
  2044.                           } else if (updateElements[i].localName == "description") {
  2045.                               if (checkUpdates == "true" && netNew > 0) {
  2046.                                   webmail.debug("updating element: "+updateElements[i].id + " type: "+updateElements[i].localName);
  2047.                                   updateElements[i].setAttribute("value",updateElements[i].getAttribute("baselabel") + "   " +netNew);
  2048.                               } else {
  2049.                                   updateElements[i].setAttribute("value",updateElements[i].getAttribute("baselabel"));
  2050.                               }
  2051.                           } else {
  2052.                               if (checkUpdates == "true" && netNew > 0) {
  2053.                                   webmail.debug("updating element: "+updateElements[i].id + " type: "+updateElements[i].localName);
  2054.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages ("+numNew+" unread total)");
  2055.                                   updateElements[i].setAttribute("acceltext",netNew);
  2056.                               } else {
  2057.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account");
  2058.                                   updateElements[i].removeAttribute("acceltext");
  2059.                               }
  2060.                               if (checkUpdates == "true") {
  2061.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account has " +netNew +" new messages ("+numNew+" unread total)");
  2062.                               } else {
  2063.                                   updateElements[i].setAttribute("tooltiptext",accountName + " webmail account");
  2064.                               }
  2065.                           }
  2066.                         }
  2067.                     }
  2068.                     // Notify the user of new e-mail, if requested and different.
  2069.                     try {
  2070.                         notify = webmail.Prefs.getCharPref("notification."+accountName);
  2071.                     } catch (ex) {
  2072.                         notify = "None";
  2073.                     }
  2074.                     var myProvider;
  2075.                     try {
  2076.                         myProvider = webmail.Prefs.getCharPref("provider."+accountName);
  2077.                     } catch (ex) {
  2078.                         myProvider = "webmail:feed:netscape";
  2079.                     }
  2080.                     var myService = webmail.getServiceById(myProvider);
  2081.                     var myImage;
  2082.                     if (myService) {
  2083.                         myImage = myService.icon;
  2084.                     } else {
  2085.                         myImage = "chrome://browser/skin/throbber16-single.gif";
  2086.                     }
  2087.                     var notifyObserver = {
  2088.                         onAlertFinished : function (aAlertCookie) {},
  2089.                         myAccount : new String(),
  2090.                         onAlertClickCallback : function (aAlertCookie) {
  2091.                             webmail.read(this.myAccount);
  2092.                         }
  2093.                     }
  2094.                     notifyObserver.myAccount=accountName;
  2095.                     webmail.debug("Notification for account ("+accountName+") is "+notify);
  2096.                     if (checkUpdates=="true" && netNew> 0) {
  2097.                         var message="You have "+netNew+" new e-mails in your "+
  2098.                                             accountName+" webmail account ("+numNew+" total unread)";
  2099.                         if (notify == "Toaster") {
  2100.                             webmail.debug("attempting Toaster notification");
  2101.                             var alerts = Components.classes["@mozilla.org/alerts-service;1"]
  2102.                                                     .getService(Components.interfaces.nsIAlertsService);
  2103.                             alerts.showAlertNotification(myImage,
  2104.                             "New Email", message, true, "", notifyObserver);
  2105.                         } else if (notify == "Info-Bar") {
  2106.                             webmail.debug("attempting Info-Bar notification");
  2107.                             var extraData = new Array();
  2108.                             extraData.push(myImage);
  2109.                             extraData.push(message);
  2110.                             displayNotificationBar("webmail", extraData);
  2111.                         }
  2112.                     }
  2113.                 } else {
  2114.                     webmail.debug("req state = "+req.readyState);
  2115.                 }
  2116.             }
  2117.             try {
  2118.                 if (isPost) {
  2119.                     req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  2120.                     req.send(nGetStr);
  2121.                 } else {
  2122.                     req.send("");
  2123.                 }
  2124.             } catch (ex) {
  2125.                 webmail.debug("error in req.send");
  2126.                 webmail.debug(ex);
  2127.             }
  2128.             webmail.debug("done send()");
  2129.         }
  2130.     } catch (ex) {
  2131.         webmail.debug("checkNewWebmail failed oddly");
  2132.         webmail.debug(ex);
  2133.     }
  2134.     // submit the next update
  2135.     if (checkUpdates=="true") {
  2136.         var nTime;
  2137.         try {
  2138.             nTime = webmail.Prefs.getCharPref("emailfreq."+accountName);
  2139.         } catch (ex) {}
  2140.         if (nTime && nTime > 0) {
  2141.             setTimeout("checkNewWebmail('"+accountName+"');",60000*nTime);
  2142.         }
  2143.     }
  2144. }
  2145.  
  2146. function WebmailEndLoadListener(aURL,aSelectBrowser) {
  2147.     this.mURL = aURL;
  2148.     this.mSelectBrowser = aSelectBrowser;
  2149. }
  2150.  
  2151. WebmailEndLoadListener.prototype = {
  2152.  
  2153.     mURL : null,
  2154.     mBrowser : null,
  2155.     mSelectBrowser : null,
  2156.     mFinalURL : null,
  2157.     mAddress : null,
  2158.     mSubject : null,
  2159.     mLastChange : null,
  2160.  
  2161.     openIt : function () {
  2162.         if (this.mSelectBrowser) {
  2163.             gBrowser.selectedTab=gBrowser.addTabAt("about:blank");
  2164.             this.mBrowser = gBrowser.getBrowserForTab(gBrowser.selectedTab);
  2165.         } else {
  2166.             this.mBrowser = gBrowser.getBrowserForTab(gBrowser.addTabAt("about:blank"));
  2167.         }
  2168.         this.mBrowser.loadURI("about:blank");
  2169.         this.mBrowser.addProgressListener(this);
  2170.         this.mBrowser.webNavigation.browserEngine = 'Gecko';
  2171.         this.mBrowser.webNavigation.loadURI(this.mURL,Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE,null,null,null);
  2172.         this.mLastChange = new Date();
  2173.     },
  2174.  
  2175.     onProgressChange : function (aWebProgress, aRequest,
  2176.                                     aCurSelfProgress, aMaxSelfProgress,
  2177.                                     aCurTotalProgress, aMaxTotalProgress) {
  2178.       this.mLastChange = new Date();
  2179.         webmail.debug ("onPregressChange Called");
  2180.         const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
  2181.         const nsIChannel = Components.interfaces.nsIChannel;
  2182.         if (aRequest) {
  2183.                 try {
  2184.                 var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec;
  2185.               } catch(ex) {urlStr="undefined!";}
  2186.           } else {
  2187.               urlStr="undefined";
  2188.           }
  2189.         webmail.debug("urlStr="+urlStr);
  2190.     },
  2191.  
  2192.     onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
  2193.     {
  2194.         this.mLastChange = new Date();
  2195.         webmail.debug ("onStateChange Called");
  2196.         const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
  2197.         const nsIChannel = Components.interfaces.nsIChannel;
  2198.         if (aRequest) {
  2199.                 try {
  2200.                 var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec;
  2201.               } catch(ex) {urlStr="undefined!";}
  2202.           } else {
  2203.               urlStr="undefined";
  2204.           }
  2205.         webmail.debug("urlStr="+urlStr);
  2206.         if (aStateFlags & nsIWebProgressListener.STATE_STOP) {
  2207.             webmail.debug("State is Stop");
  2208.           if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) {
  2209.               webmail.debug("State is network");
  2210.             if (aRequest) {
  2211.                 webmail.debug("running endDocumentLoad function in Progress Listener");
  2212.                 webmail.debug("browser engine string=" +    this.mBrowser.webNavigation.browserEngine );
  2213.               this.endDocumentLoad(aRequest, aStatus, aWebProgress);
  2214.                     }
  2215.           }
  2216.         }
  2217.     },
  2218.  
  2219.     onLocationChange : function(aWebProgress, aRequest, aLocation) {
  2220.         webmail.debug ("onLocationChange Called");
  2221.         if (aLocation) {
  2222.                 var urlStr = aLocation.spec;
  2223.             } else {
  2224.                 urlStr="undefined";
  2225.             }
  2226.         webmail.debug("urlStr="+urlStr);
  2227.         this.mLastChange = new Date();
  2228.     },
  2229.  
  2230.     onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage) {
  2231.         this.mLastChange = new Date();
  2232.     },
  2233.  
  2234.     onSecurityChange : function(aWebProgress, aRequest, aState) {
  2235.         this.mLastChange = new Date();
  2236.     },
  2237.  
  2238.     QueryInterface : function(aIID)
  2239.     {
  2240.         if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  2241.             aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  2242.             aIID.equals(Components.interfaces.nsISupports))
  2243.         return this;
  2244.         throw Components.results.NS_NOINTERFACE;
  2245.     },
  2246.  
  2247.     endDocumentLoad : function(aRequest, aStatus, aWebProgress) {
  2248.         webmail.debug("Running the default endDocumentLoad function");
  2249.     }
  2250. }
  2251.