Changeset 85fa10 for modules/vI_identityData.js
- Timestamp:
- Sep 9, 2018, 2:36:02 AM (4 years ago)
- Branches:
- ng_0.9
- Children:
- c5860f
- Parents:
- bc6c6b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/vI_identityData.js
rbc6c6b r85fa10 44 44 Components.utils.import("resource://v_identity/identityDataExtras/PGPMIME.js"); 45 45 46 function identityData(currentWindow, email, fullName, id, smtp, extras, sideDescription, existingID) { 46 ChromeUtils.import("resource:///modules/mailServices.js"); 47 48 function identityData(currentWindow, email, fullName, id, extras, sideDescription, existingID) { 47 49 this._currentWindow = currentWindow; 48 50 this._email = email ? email : ""; … … 50 52 this._fullName = fullName ? fullName : ""; 51 53 this.id = new idObj(id); 52 this.smtp = new smtpObj(smtp);53 54 if (extras) this.extras = extras; 54 55 else this.extras = new identityDataExtras(currentWindow); … … 58 59 fullName: {}, 59 60 email: {}, 60 smtp: {},61 61 id: {}, 62 62 extras: {} … … 76 76 _currentWindow: null, 77 77 id: null, 78 smtp: null,79 78 extras: null, 80 79 sideDescription: null, … … 139 138 return this.__makeHtml(this.id.value); 140 139 }, 141 get smtpHtml() {142 return this.__makeHtml(this.smtp.value);143 },144 140 get fullNameHtml() { 145 141 return this.__makeHtml(this.fullName); … … 155 151 return this.stringBundle.GetStringFromName("vident.identityData.baseID") 156 152 }, 157 get smtpLabel() {158 return this.stringBundle.GetStringFromName("vident.identityData.SMTP")159 },160 153 get fullNameLabel() { 161 154 return this.stringBundle.GetStringFromName("vident.identityData.Name") … … 167 160 // creates an Duplicate of the current IdentityData, cause usually we are working with a pointer 168 161 getDuplicate: function () { 169 return new identityData(this._currentWindow, this.email, this.fullName, this.id.key, this. smtp.key, this.extras ? this.extras.getDuplicate() : null,162 return new identityData(this._currentWindow, this.email, this.fullName, this.id.key, this.extras ? this.extras.getDuplicate() : null, 170 163 this.sideDescription, this.existingID); 171 164 }, … … 178 171 if (identityData.id.key) 179 172 this.id.key = identityData.id.key; 180 if (identityData.smtp.key)181 this.smtp.key = identityData.smtp.key;182 173 if (identityData.sideDescription) 183 174 this.sideDescription = identityData.sideDescription; … … 191 182 this.fullName = identityData.fullName; 192 183 this.id.key = identityData.id.key; 193 this.smtp.key = identityData.smtp.key;194 184 this.sideDescription = identityData.sideDescription; 195 185 if (this.extras) this.extras.copy(identityData.extras); … … 200 190 isExistingIdentity: function (ignoreFullNameWhileComparing) { 201 191 Log.debug("isExistingIdentity: ignoreFullNameWhileComparing='" + ignoreFullNameWhileComparing + "'"); 202 // Log.debug("base: fullName.toLowerCase()='" + this.fullName + "' email.toLowerCase()='" + this.email + "' smtp='" + this.smtp.key + "'");192 // Log.debug("base: fullName.toLowerCase()='" + this.fullName + "' email.toLowerCase()='" + this.email + "'"); 203 193 204 194 var ignoreFullNameMatchKey = null; … … 213 203 for (let i = 0; i < identities.length; i++) { 214 204 let identity = identities[i]; 215 // Log.debug("comp: fullName.toLowerCase()='" + identity.fullName.toLowerCase() + "' email.toLowerCase()='" + identity.email.toLowerCase() + "' smtp='" + identity.smtpServerKey + "'");205 // Log.debug("comp: fullName.toLowerCase()='" + identity.fullName.toLowerCase() + "' email.toLowerCase()='" + identity.email.toLowerCase() + "'"); 216 206 var email = this.email ? this.email : ""; // might be null if no identity is set 217 207 var idEmail = identity.email ? identity.email : ""; // might be null if no identity is set 218 if ((email.toLowerCase() == idEmail.toLowerCase()) && 219 this.smtp.equal(new smtpObj(identity.smtpServerKey))) { 208 if (email.toLowerCase() == idEmail.toLowerCase()) { 220 209 // if fullName matches, than this is a final match 221 210 if (this.fullName.toLowerCase() == identity.fullName.toLowerCase()) { … … 288 277 } 289 278 290 this.comp.equals.smtp = this.smtp.equal(compareIdentityData.smtp);291 279 this.comp.equals.id = this.id.equal(compareIdentityData.id); 292 280 this.comp.equals.extras = this.extras ? this.extras.equal(compareIdentityData.extras) : true; 293 281 294 return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals. smtp && this.comp.equals.id && this.comp.equals.extras);282 return (this.comp.equals.fullName && this.comp.equals.email && this.comp.equals.id && this.comp.equals.extras); 295 283 }, 296 284 … … 307 295 308 296 getCompareMatrix: function () { 309 const Items = Array("fullName", "email", " smtp", "id");297 const Items = Array("fullName", "email", "id"); 310 298 var string = ""; 311 299 var saveBaseId = vIprefs.get("storage_store_base_id"); 312 var saveSMTP = vIprefs.get("storage_store_SMTP");313 300 for (let item of Items) { 314 301 var classEqual = (this.comp.equals[item]) ? "equal" : "unequal"; 315 var classIgnore = (( (!saveBaseId) && (item == "id")) || ((!saveSMTP) && (item == "smtp"))) ? " ignoreValues" : ""302 var classIgnore = ((!saveBaseId) && (item == "id")) ? " ignoreValues" : "" 316 303 string += "<tr>" + 317 304 "<td class='col1 " + classEqual + "'>" + this[item + "Label"] + "</td>" + … … 325 312 326 313 getMatrix: function () { 327 const Items = Array("smtp", "id");328 314 var string = ""; 329 for (var item of Items) if (this[item + "Html"])330 string += "<tr><td class='col1'>" + this[item + "Label"] + ":</td>" +331 "<td class='col2'>" + this[ item + "Html"] + "</td></tr>"315 if (this["idHtml"]) 316 string = "<tr><td class='col1'>" + this["idLabel"] + ":</td>" + 317 "<td class='col2'>" + this["idHtml"] + "</td></tr>" 332 318 string += this.extras ? this.extras.getMatrix() : ""; 333 319 return string; … … 363 349 if (this.identityDataCollection[index].email == identityData.email && 364 350 (!this.identityDataCollection[index].id.key || !identityData.id.key || 365 (this.identityDataCollection[index].id.key == identityData.id.key && 366 this.identityDataCollection[index].smtp.key == identityData.smtp.key))) { 351 this.identityDataCollection[index].id.key == identityData.id.key)) { 367 352 // found, so check if we can use the Name of the new field 368 353 if (this.identityDataCollection[index].fullName == "" && identityData.fullName != "") { … … 370 355 Log.debug("added fullName '" + identityData.fullName + "' to stored email '" + this.identityDataCollection[index].email + "'") 371 356 } 372 // check if id_key , smtp_keyor extras can be used357 // check if id_key or extras can be used 373 358 // only try this once, for the first Identity where id is set) 374 359 if (!this.identityDataCollection[index].id.key && identityData.id.key) { 375 360 this.identityDataCollection[index].id.key = identityData.id.key; 376 this.identityDataCollection[index].smtp.key = identityData.smtp.key;377 361 this.identityDataCollection[index].extras = identityData.extras; 378 Log.debug("added id '" + identityData.id.value + "' smtp '" + identityData.smtp.value + "'(+extras) to stored email '" + this.identityDataCollection[index].email + "'")362 Log.debug("added id '" + identityData.id.value + "' (+extras) to stored email '" + this.identityDataCollection[index].email + "'") 379 363 } 380 364 return; … … 393 377 } 394 378 }; 395 396 function smtpObj(key) {397 this._key = key;398 this.DEFAULT_TAG = Components.classes["@mozilla.org/intl/stringbundle;1"]399 .getService(Components.interfaces.nsIStringBundleService)400 .createBundle("chrome://messenger/locale/messenger.properties").401 GetStringFromName("defaultServerTag");402 }403 smtpObj.prototype = {404 DEFAULT_TAG: null,405 _key: null,406 _value: null,407 408 set key(key) {409 this._key = key;410 this._value = null;411 },412 get key() {413 var dummy = this.value; // just to be sure key is adapted if SMTP is not available414 return this._key415 },416 get keyNice() { // the same as key but with "" for DEFAULT_SMTP_TAG417 if (this.key == DEFAULT_SMTP_TAG) return ""; // this is the key used for default server418 return this.key419 },420 get value() {421 if (this._value == null) {422 this._value = "";423 if (this._key == null || this._key == "") this._key = DEFAULT_SMTP_TAG;424 if (this._key == DEFAULT_SMTP_TAG) this._value = this.DEFAULT_TAG;425 else if (!this._key) this._value = null;426 else if (this._key) {427 var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]428 .getService(Components.interfaces.nsISmtpService);429 // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService430 if (typeof (smtpService.servers) == "object") servers = smtpService.servers;431 else servers = smtpService.smtpServers;432 433 while (servers && servers.hasMoreElements()) {434 var server = servers.getNext();435 if (server instanceof Components.interfaces.nsISmtpServer &&436 !server.redirectorType && this._key == server.key) {437 this._value = server.description ? server.description : server.hostname;438 break;439 }440 }441 }442 }443 if (!this._value) this._key = NO_SMTP_TAG; // if non-existant SMTP handle like non available444 return this._value;445 },446 equal: function (compareSmtpObj) {447 if (this.key == NO_SMTP_TAG || compareSmtpObj.key == NO_SMTP_TAG) return true;448 if (this.keyNice != compareSmtpObj.keyNice) {449 // Log.debug("smtp not equal ('" + this.keyNice + "' != '" + compareSmtpObj.keyNice + "')");450 }451 return (this.keyNice == compareSmtpObj.keyNice);452 },453 hasNoDefinedSMTP: function () {454 return (this.key == NO_SMTP_TAG);455 }456 }457 379 458 380 function idObj(key) { … … 502 424 return this._value; 503 425 }, 426 427 get smtpServerKey() { 428 if (!this.key) 429 return null; 430 var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"] 431 .getService(Components.interfaces.nsIMsgAccountManager); 432 433 var identity = AccountManager.getIdentity(this.key); 434 if (identity) { 435 if (identity.smtpServerKey) 436 return identity.smtpServerKey; 437 else 438 return MailServices.smtp.defaultServer.key 439 } 440 return null; 441 }, 442 443 get smtpServerName() { 444 if (!this.smtpServerKey) 445 return null; 446 var servers = MailServices.smtp.servers; 447 448 var smtpName; 449 while (servers && servers.hasMoreElements()) { 450 var server = servers.getNext(); 451 if (server instanceof Components.interfaces.nsISmtpServer && 452 !server.redirectorType && this.smtpServerKey == server.key) { 453 smtpName = server.description ? server.description : server.hostname; 454 break; 455 } 456 } 457 return smtpName; 458 }, 459 504 460 equal: function (compareIdObj) { 505 461 if (!this.key || !compareIdObj.key) return true;
Note: See TracChangeset
for help on using the changeset viewer.