Changeset 509348 for modules/vI_identityData.js
- Timestamp:
- Nov 3, 2014, 12:35:40 PM (8 years ago)
- Branches:
- ng_0.9
- Children:
- 7204cb
- Parents:
- 3c9c29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/vI_identityData.js
r3c9c29 r509348 45 45 46 46 function identityData(email, fullName, id, smtp, extras, sideDescription, existingID) { 47 this._email = email?email:""; 48 this._emailParsed = false; 49 this._fullName = fullName?fullName:""; 50 this.id = new idObj(id); 51 this.smtp = new smtpObj(smtp); 52 if (extras) this.extras = extras; 53 else this.extras = new identityDataExtras(); 54 this.comp = { // holds the results of the last comparison for later creation of a compareMatrix 55 compareID : null, 56 equals : { fullName : {}, email : {}, smtp : {}, id : {}, extras : {} } 57 } 58 if (sideDescription) this.sideDescription = sideDescription; 59 if (existingID) this.existingID = existingID; 60 else if (this.id.value) this.sideDescription = " - " + this.id.value; 61 this.stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"] 62 .getService(Components.interfaces.nsIStringBundleService) 63 .createBundle("chrome://v_identity/locale/v_identity.properties"); 47 this._email = email ? email : ""; 48 this._emailParsed = false; 49 this._fullName = fullName ? fullName : ""; 50 this.id = new idObj(id); 51 this.smtp = new smtpObj(smtp); 52 if (extras) this.extras = extras; 53 else this.extras = new identityDataExtras(); 54 this.comp = { // holds the results of the last comparison for later creation of a compareMatrix 55 compareID: null, 56 equals: { 57 fullName: {}, 58 email: {}, 59 smtp: {}, 60 id: {}, 61 extras: {} 62 } 63 } 64 if (sideDescription) this.sideDescription = sideDescription; 65 if (existingID) this.existingID = existingID; 66 else if (this.id.value) this.sideDescription = " - " + this.id.value; 67 this.stringBundle = Components.classes["@mozilla.org/intl/stringbundle;1"] 68 .getService(Components.interfaces.nsIStringBundleService) 69 .createBundle("chrome://v_identity/locale/v_identity.properties"); 64 70 } 65 71 identityData.prototype = { 66 _email : null, // internal email-field might contain combinedName (until first queried via email) 67 _fullName : null, 68 _emailParsed : null, 69 id : null, 70 smtp : null, 71 extras : null, 72 sideDescription : null, 73 existingID : null, // indicates that this is a pre-defined Identity, which might handled slightly differently 74 75 stringBundle : null, 76 comp : null, 77 78 parseEmail : function() { 79 if (this._emailParsed) return; 80 // parse email and move any additional parts to fullName 81 if (this._email.match(/<\s*[^>\s]*@[^>\s]*\s*>/) || this._email.match(/<?\s*[^>\s]*@[^>\s]*\s*>?/) || this._email.match(/$/)) { 82 this._fullName += RegExp.leftContext + RegExp.rightContext; 83 this._email = RegExp.lastMatch; 84 // Log.debug("parseEmail _fullName = '" + this._fullName + "'"); 85 // Log.debug("parseEmail _email = '" + this._email + "'"); 86 } 87 this._emailParsed = true; 88 }, 89 get email() { 90 this.parseEmail(); 91 return (this._email?this._email.replace(/\s+|<|>/g,""):""); 92 }, 93 set email(email) { this._email = email; this._emailParsed = false; }, 94 95 cleanName : function(fullName) { 96 // Log.debug("cleanName init '" + fullName + "'"); 97 var _fullName = fullName.replace(/^\s+|\s+$/g,""); 98 if (_fullName.search(/^\".+\"$|^'.+'$/g) != -1) { 99 _fullName = this.cleanName(_fullName.replace(/^\"(.+)\"$|^'(.+)'$/g,"$1$2")); 100 } 101 // Log.debug("cleanName done '" + _fullName + "'"); 102 return _fullName; 103 }, 104 105 get fullName() { 106 this.parseEmail(); 107 return (this._fullName?this.cleanName(this._fullName):"") 108 }, 109 set fullName(fullName) { this._fullName = fullName; }, 110 111 get combinedName() { 112 var fullName = this.fullName; var email = this.email; 113 return fullName?fullName+(email?" <"+email+">":""):email 114 }, 115 set combinedName(combinedName) { this._email = combinedName; this._fullName = ""; this._emailParsed = false; }, 116 117 __makeHtml : function (string) { return string?string.replace(/>/g,">").replace(/</g,"<"):"" }, 118 get idHtml() { return this.__makeHtml(this.id.value); }, 119 get smtpHtml() { return this.__makeHtml(this.smtp.value); }, 120 get fullNameHtml() { return this.__makeHtml(this.fullName); }, 121 get emailHtml() { return this.__makeHtml(this.email); }, 122 get combinedNameHtml() { return this.__makeHtml(this.combinedName); }, 123 124 get idLabel() { return this.stringBundle.GetStringFromName("vident.identityData.baseID") }, 125 get smtpLabel() { return this.stringBundle.GetStringFromName("vident.identityData.SMTP") }, 126 get fullNameLabel() { return this.stringBundle.GetStringFromName("vident.identityData.Name") }, 127 get emailLabel() { return this.stringBundle.GetStringFromName("vident.identityData.Address") }, 128 129 // creates an Duplicate of the current IdentityData, cause usually we are working with a pointer 130 getDuplicate : function() { 131 return new identityData(this.email, this.fullName, this.id.key, this.smtp.key, this.extras?this.extras.getDuplicate():null, this.sideDescription, this.existingID); 132 }, 133 134 // copys all values of an identity. This way we can create a new object with a different document-context 135 copy : function(identityData) { 136 this.email = identityData.email; 137 this.fullName = identityData.fullName; 138 this.id.key = identityData.id.key; 139 this.smtp.key = identityData.smtp.key; 140 this.sideDescription = identityData.sideDescription; 141 if (this.extras) this.extras.copy(identityData.extras); 142 }, 143 144 // dependent on MsgComposeCommands, should/will only be called in ComposeDialog 145 isExistingIdentity : function(ignoreFullNameWhileComparing) { 146 Log.debug("isExistingIdentity: ignoreFullNameWhileComparing='" + ignoreFullNameWhileComparing + "'"); 147 // Log.debug("base: fullName.toLowerCase()='" + this.fullName + "' email.toLowerCase()='" + this.email + "' smtp='" + this.smtp.key + "'"); 148 149 var ignoreFullNameMatchKey = null; 150 var accounts = getAccountsArray(); 151 for (let acc = 0; acc < accounts.length; acc++) { 152 let account = accounts[acc]; 153 try { prefroot.getBoolPref("mail.account."+account.key+".vIdentity"); continue; } catch (e) { }; 154 let identities = getIdentitiesArray(account); 155 for (let i = 0; i < identities.length; i++) { 156 let identity = identities[i]; 157 // Log.debug("comp: fullName.toLowerCase()='" + identity.fullName.toLowerCase() + "' email.toLowerCase()='" + identity.email.toLowerCase() + "' smtp='" + identity.smtpServerKey + "'"); 158 var email = this.email?this.email:""; // might be null if no identity is set 159 var idEmail = identity.email?identity.email:""; // might be null if no identity is set 160 if ( (email.toLowerCase() == idEmail.toLowerCase()) && 161 this.smtp.equal(new smtpObj(identity.smtpServerKey)) ) { 162 // if fullName matches, than this is a final match 163 if ( this.fullName.toLowerCase() == identity.fullName.toLowerCase() ) { 164 Log.debug("isExistingIdentity: " + this.combinedName + " found, id='" + identity.key + "'"); 165 return identity.key; // return key and stop searching 166 } 167 // if fullNames don't match, remember the key but continue to search for full match 168 else if (!ignoreFullNameMatchKey) ignoreFullNameMatchKey = identity.key; 169 } 170 } 171 } 172 173 if ( ignoreFullNameWhileComparing && ignoreFullNameMatchKey ) { 174 Log.debug("isExistingIdentity: " + this.combinedName + " found, id='" + ignoreFullNameMatchKey + "'"); 175 return ignoreFullNameMatchKey; 176 } 177 178 Log.debug("isExistingIdentity: " + this.combinedName + " not found"); 179 return null; 180 }, 181 182 // dependent on MsgComposeCommands, should/will only be called in ComposeDialog 183 hasMatchingDomainIdentity : function() { 184 Log.debug("hasMatchingDomainIdentity"); 185 186 var domainArray = this.email.match(/@[^@]+$/); 187 if (!domainArray) { 188 Log.debug("hasMatchingDomainIdentity found no domain for email " + this.email); 189 return; 190 } 191 Log.debug("hasMatchingDomainIdentity searching for domain " + domainArray[0]); 192 193 var accounts = getAccountsArray(); 194 for (let acc = 0; acc < accounts.length; acc++) { 195 let account = accounts[acc]; 196 try { prefroot.getBoolPref("mail.account."+account.key+".vIdentity"); continue; } catch (e) { }; 197 let identities = getIdentitiesArray(account); 198 for (let i = 0; i < identities.length; i++) { 199 let identity = identities[i]; 200 var idDomainArray = identity.email.match(/@[^@]+$/); 201 if (!idDomainArray) continue; 202 // Log.debug("comp: domain.toLowerCase()='" + domainArray[0].toLowerCase() + "' idDomain.toLowerCase()='" + idDomainArray[0].toLowerCase() + "'"); 203 if (domainArray[0].toLowerCase() == idDomainArray[0].toLowerCase()) { 204 // if domain matches, everything is perfect! 205 Log.debug("hasMatchingDomainIdentity: found matching id for domain '" + domainArray[0] + "'"); 206 return identity.key; // return key and stop searching 207 } 208 } 209 } 210 Log.debug("hasMatchingDomainIdentity: '" + domainArray[0] + "' not found"); 211 return null; 212 }, 213 214 equals : function(compareIdentityData) { 215 this.comp.compareID = compareIdentityData; 216 217 this.comp.equals.fullName = (((this.fullName)?this.fullName.toLowerCase():null) == ((compareIdentityData.fullName)?compareIdentityData.fullName.toLowerCase():null)); 218 if (!this.comp.equals.fullName) { 219 // Log.debug("fullName not equal ('" + ((this.fullName)?this.fullName.toLowerCase():null) + "' != '" + ((compareIdentityData.fullName)?compareIdentityData.fullName.toLowerCase():null) + "')"); 220 } 221 this.comp.equals.email = (((this.email)?this.email.toLowerCase():null) == ((compareIdentityData.email)?compareIdentityData.email.toLowerCase():null)); 72 _email: null, // internal email-field might contain combinedName (until first queried via email) 73 _fullName: null, 74 _emailParsed: null, 75 id: null, 76 smtp: null, 77 extras: null, 78 sideDescription: null, 79 existingID: null, // indicates that this is a pre-defined Identity, which might handled slightly differently 80 81 stringBundle: null, 82 comp: null, 83 84 parseEmail: function () { 85 if (this._emailParsed) return; 86 // parse email and move any additional parts to fullName 87 if (this._email.match(/<\s*[^>\s]*@[^>\s]*\s*>/) || this._email.match(/<?\s*[^>\s]*@[^>\s]*\s*>?/) || this._email.match(/$/)) { 88 this._fullName += RegExp.leftContext + RegExp.rightContext; 89 this._email = RegExp.lastMatch; 90 // Log.debug("parseEmail _fullName = '" + this._fullName + "'"); 91 // Log.debug("parseEmail _email = '" + this._email + "'"); 92 } 93 this._emailParsed = true; 94 }, 95 get email() { 96 this.parseEmail(); 97 return (this._email ? this._email.replace(/\s+|<|>/g, "") : ""); 98 }, 99 set email(email) { 100 this._email = email; 101 this._emailParsed = false; 102 }, 103 104 cleanName: function (fullName) { 105 // Log.debug("cleanName init '" + fullName + "'"); 106 var _fullName = fullName.replace(/^\s+|\s+$/g, ""); 107 if (_fullName.search(/^\".+\"$|^'.+'$/g) != -1) { 108 _fullName = this.cleanName(_fullName.replace(/^\"(.+)\"$|^'(.+)'$/g, "$1$2")); 109 } 110 // Log.debug("cleanName done '" + _fullName + "'"); 111 return _fullName; 112 }, 113 114 get fullName() { 115 this.parseEmail(); 116 return (this._fullName ? this.cleanName(this._fullName) : "") 117 }, 118 set fullName(fullName) { 119 this._fullName = fullName; 120 }, 121 122 get combinedName() { 123 var fullName = this.fullName; 124 var email = this.email; 125 return fullName ? fullName + (email ? " <" + email + ">" : "") : email 126 }, 127 set combinedName(combinedName) { 128 this._email = combinedName; 129 this._fullName = ""; 130 this._emailParsed = false; 131 }, 132 133 __makeHtml: function (string) { 134 return string ? string.replace(/>/g, ">").replace(/</g, "<") : "" 135 }, 136 get idHtml() { 137 return this.__makeHtml(this.id.value); 138 }, 139 get smtpHtml() { 140 return this.__makeHtml(this.smtp.value); 141 }, 142 get fullNameHtml() { 143 return this.__makeHtml(this.fullName); 144 }, 145 get emailHtml() { 146 return this.__makeHtml(this.email); 147 }, 148 get combinedNameHtml() { 149 return this.__makeHtml(this.combinedName); 150 }, 151 152 get idLabel() { 153 return this.stringBundle.GetStringFromName("vident.identityData.baseID") 154 }, 155 get smtpLabel() { 156 return this.stringBundle.GetStringFromName("vident.identityData.SMTP") 157 }, 158 get fullNameLabel() { 159 return this.stringBundle.GetStringFromName("vident.identityData.Name") 160 }, 161 get emailLabel() { 162 return this.stringBundle.GetStringFromName("vident.identityData.Address") 163 }, 164 165 // creates an Duplicate of the current IdentityData, cause usually we are working with a pointer 166 getDuplicate: function () { 167 return new identityData(this.email, this.fullName, this.id.key, this.smtp.key, this.extras ? this.extras.getDuplicate() : null, this.sideDescription, this.existingID); 168 }, 169 170 // copys all values of an identity. This way we can create a new object with a different document-context 171 copy: function (identityData) { 172 this.email = identityData.email; 173 this.fullName = identityData.fullName; 174 this.id.key = identityData.id.key; 175 this.smtp.key = identityData.smtp.key; 176 this.sideDescription = identityData.sideDescription; 177 if (this.extras) this.extras.copy(identityData.extras); 178 }, 179 180 // dependent on MsgComposeCommands, should/will only be called in ComposeDialog 181 isExistingIdentity: function (ignoreFullNameWhileComparing) { 182 Log.debug("isExistingIdentity: ignoreFullNameWhileComparing='" + ignoreFullNameWhileComparing + "'"); 183 // Log.debug("base: fullName.toLowerCase()='" + this.fullName + "' email.toLowerCase()='" + this.email + "' smtp='" + this.smtp.key + "'"); 184 185 var ignoreFullNameMatchKey = null; 186 var accounts = getAccountsArray(); 187 for (let acc = 0; acc < accounts.length; acc++) { 188 let account = accounts[acc]; 189 try { 190 prefroot.getBoolPref("mail.account." + account.key + ".vIdentity"); 191 continue; 192 } catch (e) {}; 193 let identities = getIdentitiesArray(account); 194 for (let i = 0; i < identities.length; i++) { 195 let identity = identities[i]; 196 // Log.debug("comp: fullName.toLowerCase()='" + identity.fullName.toLowerCase() + "' email.toLowerCase()='" + identity.email.toLowerCase() + "' smtp='" + identity.smtpServerKey + "'"); 197 var email = this.email ? this.email : ""; // might be null if no identity is set 198 var idEmail = identity.email ? identity.email : ""; // might be null if no identity is set 199 if ((email.toLowerCase() == idEmail.toLowerCase()) && 200 this.smtp.equal(new smtpObj(identity.smtpServerKey))) { 201 // if fullName matches, than this is a final match 202 if (this.fullName.toLowerCase() == identity.fullName.toLowerCase()) { 203 Log.debug("isExistingIdentity: " + this.combinedName + " found, id='" + identity.key + "'"); 204 return identity.key; // return key and stop searching 205 } 206 // if fullNames don't match, remember the key but continue to search for full match 207 else if (!ignoreFullNameMatchKey) ignoreFullNameMatchKey = identity.key; 208 } 209 } 210 } 211 212 if (ignoreFullNameWhileComparing && ignoreFullNameMatchKey) { 213 Log.debug("isExistingIdentity: " + this.combinedName + " found, id='" + ignoreFullNameMatchKey + "'"); 214 return ignoreFullNameMatchKey; 215 } 216 217 Log.debug("isExistingIdentity: " + this.combinedName + " not found"); 218 return null; 219 }, 220 221 // dependent on MsgComposeCommands, should/will only be called in ComposeDialog 222 hasMatchingDomainIdentity: function () { 223 Log.debug("hasMatchingDomainIdentity"); 224 225 var domainArray = this.email.match(/@[^@]+$/); 226 if (!domainArray) { 227 Log.debug("hasMatchingDomainIdentity found no domain for email " + this.email); 228 return; 229 } 230 Log.debug("hasMatchingDomainIdentity searching for domain " + domainArray[0]); 231 232 var accounts = getAccountsArray(); 233 for (let acc = 0; acc < accounts.length; acc++) { 234 let account = accounts[acc]; 235 try { 236 prefroot.getBoolPref("mail.account." + account.key + ".vIdentity"); 237 continue; 238 } catch (e) {}; 239 let identities = getIdentitiesArray(account); 240 for (let i = 0; i < identities.length; i++) { 241 let identity = identities[i]; 242 var idDomainArray = identity.email.match(/@[^@]+$/); 243 if (!idDomainArray) continue; 244 // Log.debug("comp: domain.toLowerCase()='" + domainArray[0].toLowerCase() + "' idDomain.toLowerCase()='" + idDomainArray[0].toLowerCase() + "'"); 245 if (domainArray[0].toLowerCase() == idDomainArray[0].toLowerCase()) { 246 // if domain matches, everything is perfect! 247 Log.debug("hasMatchingDomainIdentity: found matching id for domain '" + domainArray[0] + "'"); 248 return identity.key; // return key and stop searching 249 } 250 } 251 } 252 Log.debug("hasMatchingDomainIdentity: '" + domainArray[0] + "' not found"); 253 return null; 254 }, 255 256 equals: function (compareIdentityData) { 257 this.comp.compareID = compareIdentityData; 258 259 this.comp.equals.fullName = (((this.fullName) ? this.fullName.toLowerCase() : null) == ((compareIdentityData.fullName) ? compareIdentityData.fullName.toLowerCase() : null)); 260 if (!this.comp.equals.fullName) { 261 // Log.debug("fullName not equal ('" + ((this.fullName)?this.fullName.toLowerCase():null) + "' != '" + ((compareIdentityData.fullName)?compareIdentityData.fullName.toLowerCase():null) + "')"); 262 } 263 this.comp.equals.email = (((this.email) ? this.email.toLowerCase() : null) == ((compareIdentityData.email) ? compareIdentityData.email.toLowerCase() : null)); 222 264 if (!this.comp.equals.email) { 223 // Log.debug("email not equal ('" + ((this.email)?this.email.toLowerCase():null) + "' != '" + ((compareIdentityData.email)?compareIdentityData.email.toLowerCase():null) + "')"); 224 } 225 226 this.comp.equals.smtp = this.smtp.equal(compareIdentityData.smtp); 227 this.comp.equals.id = this.id.equal(compareIdentityData.id); 228 this.comp.equals.extras = this.extras?this.extras.equal(compareIdentityData.extras):true; 229 230 return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals.smtp && this.comp.equals.id && this.comp.equals.extras); 231 }, 232 233 equalsIdentity : function(compareIdentityData, getCompareMatrix) { 234 var equal = this.equals(compareIdentityData); 235 var compareMatrix = null; 236 // generate CompareMatrix only if asked and non-equal 237 if (getCompareMatrix && !equal) compareMatrix = this.getCompareMatrix(); 238 return { equal : equal, compareMatrix : compareMatrix }; 239 }, 240 241 getCompareMatrix : function() { 242 const Items = Array("fullName", "email", "smtp", "id"); 243 var string = ""; 244 var saveBaseId = vIprefs.get("storage_store_base_id"); 245 var saveSMTP = vIprefs.get("storage_store_SMTP"); 246 for each (let item in Items) { 247 var classEqual = (this.comp.equals[item])?"equal":"unequal"; 248 var classIgnore = (((!saveBaseId) && (item == "id")) || ((!saveSMTP) && (item == "smtp")))?" ignoreValues":"" 249 string += "<tr>" + 250 "<td class='col1 " + classEqual + "'>" + this[item+"Label"] + "</td>" + 251 "<td class='col2 " + classEqual + classIgnore + "'>" + this.comp.compareID[item+"Html"] + "</td>" + 252 "<td class='col3 " + classEqual + classIgnore + "'>" + this[item+"Html"] + "</td>" + 253 "</tr>" 254 } 255 string += this.extras?this.extras.getCompareMatrix():""; 256 return string; 257 }, 258 259 getMatrix : function() { 260 const Items = Array("smtp", "id"); 261 var string = ""; 262 for each (var item in Items) if (this[item+"Html"]) 263 string += "<tr><td class='col1'>" + this[item+"Label"] + ":</td>" + 264 "<td class='col2'>" + this[item+"Html"] + "</td></tr>" 265 string += this.extras?this.extras.getMatrix():""; 266 return string; 267 } 265 // Log.debug("email not equal ('" + ((this.email)?this.email.toLowerCase():null) + "' != '" + ((compareIdentityData.email)?compareIdentityData.email.toLowerCase():null) + "')"); 266 } 267 268 this.comp.equals.smtp = this.smtp.equal(compareIdentityData.smtp); 269 this.comp.equals.id = this.id.equal(compareIdentityData.id); 270 this.comp.equals.extras = this.extras ? this.extras.equal(compareIdentityData.extras) : true; 271 272 return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals.smtp && this.comp.equals.id && this.comp.equals.extras); 273 }, 274 275 equalsIdentity: function (compareIdentityData, getCompareMatrix) { 276 var equal = this.equals(compareIdentityData); 277 var compareMatrix = null; 278 // generate CompareMatrix only if asked and non-equal 279 if (getCompareMatrix && !equal) compareMatrix = this.getCompareMatrix(); 280 return { 281 equal: equal, 282 compareMatrix: compareMatrix 283 }; 284 }, 285 286 getCompareMatrix: function () { 287 const Items = Array("fullName", "email", "smtp", "id"); 288 var string = ""; 289 var saveBaseId = vIprefs.get("storage_store_base_id"); 290 var saveSMTP = vIprefs.get("storage_store_SMTP"); 291 for each(let item in Items) { 292 var classEqual = (this.comp.equals[item]) ? "equal" : "unequal"; 293 var classIgnore = (((!saveBaseId) && (item == "id")) || ((!saveSMTP) && (item == "smtp"))) ? " ignoreValues" : "" 294 string += "<tr>" + 295 "<td class='col1 " + classEqual + "'>" + this[item + "Label"] + "</td>" + 296 "<td class='col2 " + classEqual + classIgnore + "'>" + this.comp.compareID[item + "Html"] + "</td>" + 297 "<td class='col3 " + classEqual + classIgnore + "'>" + this[item + "Html"] + "</td>" + 298 "</tr>" 299 } 300 string += this.extras ? this.extras.getCompareMatrix() : ""; 301 return string; 302 }, 303 304 getMatrix: function () { 305 const Items = Array("smtp", "id"); 306 var string = ""; 307 for each(var item in Items) if (this[item + "Html"]) 308 string += "<tr><td class='col1'>" + this[item + "Label"] + ":</td>" + 309 "<td class='col2'>" + this[item + "Html"] + "</td></tr>" 310 string += this.extras ? this.extras.getMatrix() : ""; 311 return string; 312 } 268 313 } 269 314 270 315 function identityCollection() { 271 this.number = 0; 272 this.identityDataCollection = {}; 273 this.menuItems = {}; 274 } 275 identityCollection.prototype = 276 { 277 number : null, 278 identityDataCollection : null, 279 menuItems : null, 280 281 mergeWithoutDuplicates : function(addIdentityCollection) { 282 for (var index = 0; index < addIdentityCollection.number; index++) 283 this.addWithoutDuplicates(addIdentityCollection.identityDataCollection[index]) 284 }, 285 286 dropIdentity : function(index) { 287 Log.debug("dropping address from inputList: " + this.identityDataCollection[index].combinedName); 288 while (index < (this.number - 1)) { this.identityDataCollection[index] = this.identityDataCollection[++index]; }; 289 this.identityDataCollection[--this.number] = null; 290 }, 291 292 addWithoutDuplicates : function(identityData) { 293 if (!identityData) return; 294 for (var index = 0; index < this.number; index++) { 295 if (this.identityDataCollection[index].email == identityData.email && 296 (!this.identityDataCollection[index].id.key || !identityData.id.key || 297 (this.identityDataCollection[index].id.key == identityData.id.key && 298 this.identityDataCollection[index].smtp.key == identityData.smtp.key))) { 299 // found, so check if we can use the Name of the new field 300 if (this.identityDataCollection[index].fullName == "" && identityData.fullName != "") { 301 this.identityDataCollection[index].fullName = identityData.fullName; 302 Log.debug("added fullName '" + identityData.fullName 303 + "' to stored email '" + this.identityDataCollection[index].email + "'") 304 } 305 // check if id_key, smtp_key or extras can be used 306 // only try this once, for the first Identity where id is set) 307 if (!this.identityDataCollection[index].id.key && identityData.id.key) { 308 this.identityDataCollection[index].id.key = identityData.id.key; 309 this.identityDataCollection[index].smtp.key = identityData.smtp.key; 310 this.identityDataCollection[index].extras = identityData.extras; 311 Log.debug("added id '" + identityData.id.value 312 + "' smtp '" + identityData.smtp.value + "' (+extras) to stored email '" + this.identityDataCollection[index].email + "'") 313 } 314 return; 315 } 316 } 317 Log.debug("add new address to result: " + identityData.combinedName) 318 this.identityDataCollection[index] = identityData; 319 this.number = index + 1; 320 }, 321 322 // this is used to completely use the conten of another identityCollection, but without changing all pointers 323 // see for instance vI.smartIdentity.__filterAddresses 324 takeOver : function(newIdentityCollection) { 325 this.number = newIdentityCollection.number 326 this.identityDataCollection = newIdentityCollection.identityDataCollection 327 } 316 this.number = 0; 317 this.identityDataCollection = {}; 318 this.menuItems = {}; 319 } 320 identityCollection.prototype = { 321 number: null, 322 identityDataCollection: null, 323 menuItems: null, 324 325 mergeWithoutDuplicates: function (addIdentityCollection) { 326 for (var index = 0; index < addIdentityCollection.number; index++) 327 this.addWithoutDuplicates(addIdentityCollection.identityDataCollection[index]) 328 }, 329 330 dropIdentity: function (index) { 331 Log.debug("dropping address from inputList: " + this.identityDataCollection[index].combinedName); 332 while (index < (this.number - 1)) { 333 this.identityDataCollection[index] = this.identityDataCollection[++index]; 334 }; 335 this.identityDataCollection[--this.number] = null; 336 }, 337 338 addWithoutDuplicates: function (identityData) { 339 if (!identityData) return; 340 for (var index = 0; index < this.number; index++) { 341 if (this.identityDataCollection[index].email == identityData.email && 342 (!this.identityDataCollection[index].id.key || !identityData.id.key || 343 (this.identityDataCollection[index].id.key == identityData.id.key && 344 this.identityDataCollection[index].smtp.key == identityData.smtp.key))) { 345 // found, so check if we can use the Name of the new field 346 if (this.identityDataCollection[index].fullName == "" && identityData.fullName != "") { 347 this.identityDataCollection[index].fullName = identityData.fullName; 348 Log.debug("added fullName '" + identityData.fullName + "' to stored email '" + this.identityDataCollection[index].email + "'") 349 } 350 // check if id_key, smtp_key or extras can be used 351 // only try this once, for the first Identity where id is set) 352 if (!this.identityDataCollection[index].id.key && identityData.id.key) { 353 this.identityDataCollection[index].id.key = identityData.id.key; 354 this.identityDataCollection[index].smtp.key = identityData.smtp.key; 355 this.identityDataCollection[index].extras = identityData.extras; 356 Log.debug("added id '" + identityData.id.value + "' smtp '" + identityData.smtp.value + "' (+extras) to stored email '" + this.identityDataCollection[index].email + "'") 357 } 358 return; 359 } 360 } 361 Log.debug("add new address to result: " + identityData.combinedName) 362 this.identityDataCollection[index] = identityData; 363 this.number = index + 1; 364 }, 365 366 // this is used to completely use the conten of another identityCollection, but without changing all pointers 367 // see for instance vI.smartIdentity.__filterAddresses 368 takeOver: function (newIdentityCollection) { 369 this.number = newIdentityCollection.number 370 this.identityDataCollection = newIdentityCollection.identityDataCollection 371 } 328 372 }; 329 373 330 374 function smtpObj(key) { 331 332 this.DEFAULT_TAG =Components.classes["@mozilla.org/intl/stringbundle;1"]333 334 335 375 this._key = key; 376 this.DEFAULT_TAG = Components.classes["@mozilla.org/intl/stringbundle;1"] 377 .getService(Components.interfaces.nsIStringBundleService) 378 .createBundle("chrome://messenger/locale/messenger.properties"). 379 GetStringFromName("defaultServerTag"); 336 380 } 337 381 smtpObj.prototype = { 338 DEFAULT_TAG : null, 339 _key : null, 340 _value : null, 341 342 set key(key) { this._key = key; this._value = null; }, 343 get key() { 344 var dummy = this.value; // just to be sure key is adapted if SMTP is not available 345 return this._key 346 }, 347 get keyNice() { // the same as key but with "" for DEFAULT_SMTP_TAG 348 if (this.key == DEFAULT_SMTP_TAG) return ""; // this is the key used for default server 349 return this.key 350 }, 351 get value() { 352 if (this._value == null) { 353 this._value = ""; 354 if (this._key == null || this._key == "") this._key = DEFAULT_SMTP_TAG; 355 if (this._key == DEFAULT_SMTP_TAG) this._value = this.DEFAULT_TAG; 356 else if (!this._key) this._value = null; 357 else if (this._key) { 358 var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"] 359 .getService(Components.interfaces.nsISmtpService); 360 // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService 361 if (typeof(smtpService.servers) == "object") servers = smtpService.servers; 362 else servers = smtpService.smtpServers; 363 364 while (servers && servers.hasMoreElements()) { 365 var server = servers.getNext(); 366 if (server instanceof Components.interfaces.nsISmtpServer && 367 !server.redirectorType && this._key == server.key) { 368 this._value = server.description?server.description:server.hostname; 369 break; 370 } 371 } 372 } 373 } 374 if (!this._value) this._key = NO_SMTP_TAG; // if non-existant SMTP handle like non available 375 return this._value; 376 }, 377 equal : function(compareSmtpObj) { 378 if (this.key == NO_SMTP_TAG || compareSmtpObj.key == NO_SMTP_TAG) return true; 382 DEFAULT_TAG: null, 383 _key: null, 384 _value: null, 385 386 set key(key) { 387 this._key = key; 388 this._value = null; 389 }, 390 get key() { 391 var dummy = this.value; // just to be sure key is adapted if SMTP is not available 392 return this._key 393 }, 394 get keyNice() { // the same as key but with "" for DEFAULT_SMTP_TAG 395 if (this.key == DEFAULT_SMTP_TAG) return ""; // this is the key used for default server 396 return this.key 397 }, 398 get value() { 399 if (this._value == null) { 400 this._value = ""; 401 if (this._key == null || this._key == "") this._key = DEFAULT_SMTP_TAG; 402 if (this._key == DEFAULT_SMTP_TAG) this._value = this.DEFAULT_TAG; 403 else if (!this._key) this._value = null; 404 else if (this._key) { 405 var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"] 406 .getService(Components.interfaces.nsISmtpService); 407 // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService 408 if (typeof (smtpService.servers) == "object") servers = smtpService.servers; 409 else servers = smtpService.smtpServers; 410 411 while (servers && servers.hasMoreElements()) { 412 var server = servers.getNext(); 413 if (server instanceof Components.interfaces.nsISmtpServer && 414 !server.redirectorType && this._key == server.key) { 415 this._value = server.description ? server.description : server.hostname; 416 break; 417 } 418 } 419 } 420 } 421 if (!this._value) this._key = NO_SMTP_TAG; // if non-existant SMTP handle like non available 422 return this._value; 423 }, 424 equal: function (compareSmtpObj) { 425 if (this.key == NO_SMTP_TAG || compareSmtpObj.key == NO_SMTP_TAG) return true; 379 426 if (this.keyNice != compareSmtpObj.keyNice) { 380 // Log.debug("smtp not equal ('" + this.keyNice + "' != '" + compareSmtpObj.keyNice + "')"); 381 } 382 return (this.keyNice == compareSmtpObj.keyNice); 383 }, 384 hasNoDefinedSMTP : function() { 385 return (this.key == NO_SMTP_TAG); 386 } 387 } 388 389 function idObj(key) { this._key = key; } 427 // Log.debug("smtp not equal ('" + this.keyNice + "' != '" + compareSmtpObj.keyNice + "')"); 428 } 429 return (this.keyNice == compareSmtpObj.keyNice); 430 }, 431 hasNoDefinedSMTP: function () { 432 return (this.key == NO_SMTP_TAG); 433 } 434 } 435 436 function idObj(key) { 437 this._key = key; 438 } 390 439 idObj.prototype = { 391 _key : null, 392 _value : null, 393 394 set key(key) { this._key = key; this._value = null; }, 395 get key() { if (this._value == null) var dummy = this.value; return this._key }, 396 get value() { 397 if (this._value == null) { 398 this._value = ""; 399 // if this worked we are having at least seamonkey 1.17 400 let accounts = getAccountsArray(); 401 for (let acc = 0; acc < accounts.length; acc++) { 402 let account = accounts[acc]; 403 let identities = getIdentitiesArray(account); 404 if (identities.length == 0) 405 continue; 406 for (let i = 0; i < identities.length; i++) { 407 let identity = identities[i]; 408 if (this._key == identity.key) { 409 this._value = identity.identityName; 410 break; 411 } 412 } 413 } 414 if (!this._value) this._key = null; 415 } 416 return this._value; 417 }, 418 equal : function(compareIdObj) { 419 if (!this.key || !compareIdObj.key) return true; 440 _key: null, 441 _value: null, 442 443 set key(key) { 444 this._key = key; 445 this._value = null; 446 }, 447 get key() { 448 if (this._value == null) var dummy = this.value; 449 return this._key 450 }, 451 get value() { 452 if (this._value == null) { 453 this._value = ""; 454 // if this worked we are having at least seamonkey 1.17 455 let accounts = getAccountsArray(); 456 for (let acc = 0; acc < accounts.length; acc++) { 457 let account = accounts[acc]; 458 let identities = getIdentitiesArray(account); 459 if (identities.length == 0) 460 continue; 461 for (let i = 0; i < identities.length; i++) { 462 let identity = identities[i]; 463 if (this._key == identity.key) { 464 this._value = identity.identityName; 465 break; 466 } 467 } 468 } 469 if (!this._value) this._key = null; 470 } 471 return this._value; 472 }, 473 equal: function (compareIdObj) { 474 if (!this.key || !compareIdObj.key) return true; 420 475 if (this.key != compareIdObj.key) { 421 // Log.debug("id not equal ('" + this.key + "' != '" + compareIdObj.key + "')");422 } 423 424 425 } 476 // Log.debug("id not equal ('" + this.key + "' != '" + compareIdObj.key + "')"); 477 } 478 return (this.key == compareIdObj.key); 479 } 480 }
Note: See TracChangeset
for help on using the changeset viewer.