Changeset 2bdd22
- Timestamp:
- Sep 11, 2018, 12:52:40 PM (4 years ago)
- Branches:
- ng_0.9
- Children:
- 668208
- Parents:
- 91994f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/vI_rdfDatasource.js
r91994f r2bdd22 67 67 }; 68 68 69 function rdfDatasource(currentWindow, rdfFileName, dontRegisterObserver ) {69 function rdfDatasource(currentWindow, rdfFileName, dontRegisterObserver, dontChange = false) { 70 70 this._currentWindow = currentWindow; 71 71 this._rdfFileName = rdfFileName; 72 72 this._dontRegisterObserver = dontRegisterObserver; 73 if (this._rdfFileName) this.init( );73 if (this._rdfFileName) this.init(dontChange); 74 74 if (!this._dontRegisterObserver) this.AccountManagerObserver.register(this); 75 75 this._extVersion = get3PaneWindow().virtualIdentityExtension.extensionVersion; … … 93 93 _rdfNSAccounts: "vIAccounts", 94 94 _rdfNSIdentities: "vIAccounts/id", 95 // required for import and update of 0.10/0.0.6 rdf 96 _rdfNSSMTPservers: "vIAccounts/smtp", 95 97 96 98 _virtualIdentityID: "{dddd428e-5ac8-4a81-9f78-276c734f75b8}", … … 111 113 112 114 _identityContainer: Components.classes["@mozilla.org/rdf/container;1"] 115 .createInstance(Components.interfaces.nsIRDFContainer), 116 117 // required for import and update of 0.10/0.0.6 rdf 118 _smtpContainer: Components.classes["@mozilla.org/rdf/container;1"] 113 119 .createInstance(Components.interfaces.nsIRDFContainer), 114 120 … … 125 131 case "identity": 126 132 return this._identityContainer; 133 // required for import and update of 0.10/0.0.6 rdf 134 case "smtp": 135 return this._smtpContainer; 127 136 } 128 137 return null; 129 138 }, 130 139 131 init: function ( ) {140 init: function (dontChange = false) { 132 141 // Log.debug("init."); 133 142 … … 135 144 if (!this._rdfDataSource) return; 136 145 this._initContainers(); 137 if (this.rdfUpgradeRequired()) this.rdfUpgrade(); 138 139 // store version everytime to recognize downgrades later 140 this.storeRDFVersion(); 146 if (!dontChange) { 147 if (this.rdfUpgradeRequired()) this.rdfUpgrade(); 148 149 // store version everytime to recognize downgrades later 150 this.storeRDFVersion(); 151 } 141 152 142 153 // this.refreshAccountInfo(); … … 185 196 .GetResource(this._rdfNS + this._rdfNSIdentities); 186 197 this._identityContainer.Init(this._rdfDataSource, storageRes); 198 storageRes = this._rdfService 199 .GetResource(this._rdfNS + this._rdfNSSMTPservers); 200 this._smtpContainer.Init(this._rdfDataSource, storageRes); 187 201 } catch (e) {}; 188 202 }, … … 256 270 var identityRes = this._rdfService 257 271 .GetResource(this._rdfNS + this._rdfNSIdentities); 258 272 var smtpRes = this._rdfService 273 .GetResource(this._rdfNS + this._rdfNSSMTPservers); 259 274 this._setRDFValue(accountRes, "name", "Accounts"); 260 275 this._setRDFValue(identityRes, "name", "Identities"); 276 this._setRDFValue(smtpRes, "name", "SMTP-Server"); 261 277 262 278 rdfContainerUtils.MakeBag(this._rdfDataSource, accountRes); 263 279 rdfContainerUtils.MakeBag(this._rdfDataSource, identityRes); 280 rdfContainerUtils.MakeBag(this._rdfDataSource, smtpRes); 264 281 265 282 var accountContainer = Components.classes["@mozilla.org/rdf/container;1"]. … … 270 287 // append all new containers to accountRes 271 288 if (accountContainer.IndexOf(identityRes) == -1) accountContainer.AppendElement(identityRes); 289 if (accountContainer.IndexOf(smtpRes) == -1) accountContainer.AppendElement(smtpRes); 272 290 273 291 this._initContainers(); … … 375 393 this._unsetRDFValue(resource, "email", this._getRDFValue(resource, "email")) 376 394 this._identityContainer.RemoveElement(resource, false); 395 } 396 397 enumerator = this._smtpContainer.GetElements(); 398 while (enumerator && enumerator.hasMoreElements()) { 399 var resource = enumerator.getNext(); 400 resource.QueryInterface(Components.interfaces.nsIRDFResource); 401 this._unsetRDFValue(resource, "label", this._getRDFValue(resource, "label")) 402 this._unsetRDFValue(resource, "hostname", this._getRDFValue(resource, "hostname")) 403 this._unsetRDFValue(resource, "username", this._getRDFValue(resource, "username")) 404 this._smtpContainer.RemoveElement(resource, false); 377 405 } 378 406 }, … … 447 475 448 476 repairMismatch: function (type, mismatchItems) { 449 // type might be 'id ' or 'smtpid' - dependent on trigger477 // type might be 'identity' or 'smtp' or 'smtpid' - dependent on trigger 450 478 for (var i = 0; i < mismatchItems.length; i++) { 451 Log.debug("repairAccountMismatch change " + mismatchItems[i].oldkey + " into " + mismatchItems[i].key); 479 if (mismatchItems[i].key) 480 Log.debug("repairAccountMismatch change " + mismatchItems[i].oldkey + " into " + mismatchItems[i].key); 481 else 482 Log.debug("repairAccountMismatch remove " + mismatchItems[i].oldkey); 452 483 // search relevant Identities 453 484 for (let treeType of Array("email", "maillist", "newsgroup", "filter")) { … … 456 487 var resource = enumerator.getNext(); 457 488 resource.QueryInterface(Components.interfaces.nsIRDFResource); 458 459 489 // old smtp (stored in pre-0.10 rdf) and id have to match, set new id 460 490 if (type == 'smtpid') { … … 462 492 var id = mismatchItems[i].oldkey.split("-")[1]; 463 493 if (this._getRDFValue(resource, 'id') == id && this._getRDFValue(resource, 'smtp') == smtp) { 464 if ( mismatchItems[i].key == "") this._unsetRDFValue(resource, 'id', id)494 if (!mismatchItems[i].key) this._unsetRDFValue(resource, 'id', id) 465 495 else this._setRDFValue(resource, 'id', mismatchItems[i].key) 466 496 } 467 497 } 468 // 'id' replacement 469 else if (this._getRDFValue(resource, 'id') == mismatchItems[i].oldkey) { 470 if (mismatchItems[i].key == "") this._unsetRDFValue(resource, 'id', mismatchItems[i].oldkey) 471 else this._setRDFValue(resource, 'id', mismatchItems[i].key) 498 // 'identity' replacement 499 else if (type == 'identity') { 500 if (this._getRDFValue(resource, 'id') == mismatchItems[i].oldkey) { 501 if (!mismatchItems[i].key) this._unsetRDFValue(resource, 'id', mismatchItems[i].oldkey) 502 else this._setRDFValue(resource, 'id', mismatchItems[i].key) 503 } 504 } 505 // 'smtp' replacement 506 else if (type == 'smtp') { 507 if (this._getRDFValue(resource, 'smtp') == mismatchItems[i].oldkey) { 508 if (!mismatchItems[i].key) this._unsetRDFValue(resource, 'smtp', mismatchItems[i].oldkey) 509 else this._setRDFValue(resource, 'smtp', mismatchItems[i].key) 510 } 472 511 } 473 512 } 474 513 } 514 } 515 }, 516 517 getRelevantSMTPs: function () { 518 var relevantSMTPs = new Object(); 519 // search relevant SMTPs 520 for (let treeType of Array("email", "maillist", "newsgroup", "filter")) { 521 var enumerator = this.getContainer(treeType).GetElements(); 522 while (enumerator && enumerator.hasMoreElements()) { 523 var resource = enumerator.getNext(); 524 resource.QueryInterface(Components.interfaces.nsIRDFResource); 525 var smtp = this._getRDFValue(resource, "smtp") 526 if (smtp && smtp != DEFAULT_SMTP_TAG) { 527 if (!relevantSMTPs[smtp]) relevantSMTPs[smtp] = 1; 528 else relevantSMTPs[smtp] += 1; 529 } 530 } 531 } 532 return relevantSMTPs; 533 }, 534 535 searchSmtpMismatch: function () { 536 Log.debug("searchSmtpMismatch"); 537 538 var relevantSMTPs = this.getRelevantSMTPs(); 539 var mismatchSMTPs = []; 540 541 for (var smtp in relevantSMTPs) { 542 var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"] 543 .getService(Components.interfaces.nsISmtpService); 544 // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService 545 if (typeof (smtpService.servers) == "object") servers = smtpService.servers; 546 else servers = smtpService.smtpServers; 547 548 var found = false; 549 while (servers && servers.hasMoreElements()) { 550 var server = servers.getNext(); 551 if (server instanceof Components.interfaces.nsISmtpServer && 552 !server.redirectorType && smtp == server.key) { 553 found = true; 554 break; 555 } 556 } 557 var resource = this._rdfService.GetResource(this._rdfNS + this._rdfNSSMTPservers + "/" + smtp); 558 var rdfSMTPlabel = this._getRDFValue(resource, "label"); 559 var rdfHostname = this._getRDFValue(resource, "hostname"); 560 var rdfUsername = this._getRDFValue(resource, "username") 561 if (!found || rdfSMTPlabel != (server.description ? server.description : server.hostname) && rdfHostname != server.hostname) 562 mismatchSMTPs.push({ 563 oldkey: smtp, 564 label: rdfSMTPlabel, 565 ext1: rdfHostname, 566 ext2: rdfUsername, 567 count: relevantSMTPs[smtp], 568 key: "" 569 }) 570 } 571 if (mismatchSMTPs.length > 0) { 572 Log.debug(" found mismatches on smtp(s)."); 573 get3PaneWindow().openDialog("chrome://v_identity/content/vI_rdfAccountMismatchDialog.xul", 0, 574 "chrome, dialog, modal, alwaysRaised, resizable=yes", "smtp", mismatchSMTPs, 575 /* callback: */ 576 this).focus(); 577 return true; 578 } else { 579 Log.debug(" found no mismatch"); 580 return false; 475 581 } 476 582 }, … … 490 596 this._setRDFValue(resource, "fullName", identity.fullName); 491 597 this._setRDFValue(resource, "email", identity.email); 598 if (identity.smtpServerKey) 599 this._setRDFValue(resource, "smtp", identity.smtpServerKey); 600 else 601 this._setRDFValue(resource, "smtp", virtualIdentityExtension.DEFAULT_SMTP_TAG); 492 602 493 603 var position = this._identityContainer.IndexOf(resource); // check for index in new recType … … 496 606 } 497 607 } 608 609 function storeSmtp(server, parent) { 610 // Log.debug("storeAccounts smtp store id " + server.key); 611 var resource = parent._rdfService.GetResource(parent._rdfNS + parent._rdfNSSMTPservers + "/" + server.key); 612 parent._setRDFValue(resource, "label", (server.description ? server.description : server.hostname)); 613 parent._setRDFValue(resource, "hostname", server.hostname); 614 parent._setRDFValue(resource, "username", server.username); 615 var position = parent._smtpContainer.IndexOf(resource); // check for index in new recType 616 if (position != -1) parent._smtpContainer.InsertElementAt(resource, position, false); 617 else parent._smtpContainer.AppendElement(resource); 618 } 619 620 var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"] 621 .getService(Components.interfaces.nsISmtpService); 622 // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService 623 if (typeof (smtpService.servers) == "object") servers = smtpService.servers; 624 else servers = smtpService.smtpServers; 625 626 while (servers && servers.hasMoreElements()) { 627 var server = servers.getNext(); 628 if (server instanceof Components.interfaces.nsISmtpServer && !server.redirectorType) storeSmtp(server, this); 629 } 630 631 // Log.debug("storeAccounts done"); 498 632 }, 499 633 … … 828 962 _uninstall: false, 829 963 observe: function (subject, topic, data) { 830 if (topic == "am- acceptChanges") {831 Log.debug("account/ identitychanges observed");964 if (topic == "am-smtpChanges" || topic == "am-acceptChanges") { 965 Log.debug("account/smtp changes observed"); 832 966 this.self.searchIdentityMismatch(); 833 967 this.self.refreshAccountInfo(); … … 839 973 var obsService = Components.classes["@mozilla.org/observer-service;1"]. 840 974 getService(Components.interfaces.nsIObserverService) 975 obsService.addObserver(this, "am-smtpChanges", false); 841 976 obsService.addObserver(this, "am-acceptChanges", false); 842 977 }, … … 846 981 getService(Components.interfaces.nsIObserverService) 847 982 try { 983 obsService.removeObserver(this, "am-smtpChanges"); 848 984 obsService.removeObserver(this, "am-acceptChanges"); 849 985 } catch (e) {}; … … 1028 1164 }, 1029 1165 1166 _getMatchingSMTP: function (label, hostname, username) { 1167 var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"] 1168 .getService(Components.interfaces.nsISmtpService); 1169 // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService 1170 if (typeof (smtpService.servers) == "object") servers = smtpService.servers; 1171 else servers = smtpService.smtpServers; 1172 1173 while (servers && servers.hasMoreElements()) { 1174 var server = servers.getNext(); 1175 if (server instanceof Components.interfaces.nsISmtpServer && !server.redirectorType) 1176 if (label == (server.description ? server.description : server.hostname) || (hostname == server.hostname && username == server.username)) 1177 return server.key; 1178 } 1179 return null; 1180 }, 1181 1030 1182 _translateRelevantIDs: function () { 1031 1183 var relevantIDs = this._rdfImportDataSource.getRelevantIDs(); … … 1067 1219 //-------------------------------------------------------------------------------------------------------- 1068 1220 //only required for update from pre 0.10 versions 1221 1222 _translateRelevantSMTPs: function () { 1223 var relevantSMTPs = this._rdfImportDataSource.getRelevantSMTPs(); 1224 for (var smtp in relevantSMTPs) { 1225 var resource = this._rdfService.GetResource(this._rdfImportDataSource._rdfNS + this._rdfImportDataSource._rdfNSSMTPservers + "/" + smtp); 1226 var values = { 1227 smtp: null, 1228 label: null, 1229 hostname: null, 1230 username: null 1231 } 1232 values.label = this._rdfImportDataSource._getRDFValue(resource, "label"); 1233 values.hostname = this._rdfImportDataSource._getRDFValue(resource, "hostname"); 1234 values.username = this._rdfImportDataSource._getRDFValue(resource, "username"); 1235 values.smtp = this._getMatchingSMTP(values.label, values.hostname, values.username); 1236 values.smtp = values.smtp ? values.smtp : "import_" + smtp; 1237 relevantSMTPs[smtp] = values; 1238 Log.debug("import: translate relevant SMTP from previous '" + smtp + "' to current '" + relevantSMTPs[smtp].smtp + "'"); 1239 } 1240 return relevantSMTPs; 1241 }, 1242 1243 _storeMappedSMTPs: function (relevantSMTPs) { 1244 for (var smtp in relevantSMTPs) { 1245 if (relevantSMTPs[smtp].smtp == "import_" + smtp) { 1246 var resource = this._rdfService 1247 .GetResource(this._rdfDataSource._rdfNS + this._rdfDataSource._rdfNSSMTPservers + "/" + relevantSMTPs[smtp].smtp); 1248 this._rdfDataSource._setRDFValue(resource, "label", relevantSMTPs[smtp].label); 1249 this._rdfDataSource._setRDFValue(resource, "hostname", relevantSMTPs[smtp].hostname); 1250 this._rdfDataSource._setRDFValue(resource, "username", relevantSMTPs[smtp].username); 1251 1252 var position = this._rdfDataSource._smtpContainer.IndexOf(resource); // check for index in new recType 1253 if (position != -1) this._rdfDataSource._smtpContainer.InsertElementAt(resource, position, false); 1254 else this._rdfDataSource._smtpContainer.AppendElement(resource); 1255 } 1256 } 1257 }, 1258 1069 1259 _rdfNSSMTPservers: "vIAccounts/smtp", 1070 1260 … … 1075 1265 // search relevant SMTPs 1076 1266 for (let treeType of Array("email", "maillist", "newsgroup", "filter")) { 1077 var enumerator = this._rdf ImportDataSource.getContainer(treeType).GetElements();1267 var enumerator = this._rdfDataSource.getContainer(treeType).GetElements(); 1078 1268 while (enumerator && enumerator.hasMoreElements()) { 1079 1269 var resource = enumerator.getNext(); 1080 1270 resource.QueryInterface(Components.interfaces.nsIRDFResource); 1081 var smtp = this._rdf ImportDataSource._getRDFValue(resource, "smtp")1271 var smtp = this._rdfDataSource._getRDFValue(resource, "smtp") 1082 1272 if (smtp) { 1083 var id = this._rdf ImportDataSource._getRDFValue(resource, "id")1273 var id = this._rdfDataSource._getRDFValue(resource, "id") 1084 1274 if (id) { 1085 1275 if (!SMTPIDCombinations[smtp + "-" + id]) SMTPIDCombinations[smtp + "-" + id] = 1; … … 1113 1303 break; 1114 1304 1115 var resource = this._rdf ImportDataSource._rdfService.GetResource(this._rdfImportDataSource._rdfNS + this._rdfNSSMTPservers + "/" + smtp);1116 var rdfSMTPlabel = this._rdf ImportDataSource._getRDFValue(resource, "label");1305 var resource = this._rdfDataSource._rdfService.GetResource(this._rdfDataSource._rdfNS + this._rdfNSSMTPservers + "/" + smtp); 1306 var rdfSMTPlabel = this._rdfDataSource._getRDFValue(resource, "label"); 1117 1307 1118 1308 var servers = MailServices.smtp.servers; … … 1130 1320 SMTPIDCombinations.push({ 1131 1321 oldkey: smtpid, 1132 label: rdfSMTPlabel + " / ",1322 label: rdfSMTPlabel, 1133 1323 ext1: AccountManager.getIdentity(id).identityName, 1134 ext2: "(" + smtpName + ")",1324 ext2: smtpName, 1135 1325 count: relevantSMTPs[smtpid], 1136 1326 key: "" … … 1142 1332 "chrome, dialog, modal, alwaysRaised, resizable=yes", "smtpid", SMTPIDCombinations, 1143 1333 /* callback: */ 1144 this._rdf ImportDataSource).focus();1334 this._rdfDataSource).focus(); 1145 1335 return true; 1146 1336 } else { 1147 1337 Log.debug(" found no mismatch"); 1148 1338 return false; 1339 } 1340 }, 1341 1342 _removeSMTPEntries: function () { 1343 // search and remove all smtp-entries 1344 for (let treeType of Array("email", "maillist", "newsgroup", "filter")) { 1345 var enumerator = this._rdfDataSource.getContainer(treeType).GetElements(); 1346 while (enumerator && enumerator.hasMoreElements()) { 1347 var resource = enumerator.getNext(); 1348 this._rdfDataSource._unsetRDFValue(resource, 'smtp', this._rdfDataSource._getRDFValue(resource, 'smtp')) 1349 } 1149 1350 } 1150 1351 }, … … 1195 1396 1196 1397 // init Datasources 1197 this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true );1398 this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true, true); 1198 1399 1199 1400 // search matching IDs for anyones used in import-file 1200 1401 var relevantIDs = this._translateRelevantIDs(); 1201 1202 // extension from version 0.10 on does not use any extra SMTP information anymore 1203 // and uses the SMTP-server from base identity instead. 1204 // check if any collisions between previously stored SMTP and base identity exists and solve this. 1205 Log.debug("import: search SMTP-ID mismatches"); 1206 this._searchSmtpIdMismatch(); 1402 var relevantSMTPs = this._translateRelevantSMTPs(); 1207 1403 1208 1404 Log.debug("import: preparation done."); … … 1210 1406 for (let treeType of Array("email", "maillist", "newsgroup", "filter")) { 1211 1407 // re-initialize importDataSource to point rdfService to the right Resources 1212 this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true );1408 this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true, true); 1213 1409 var container = this._rdfImportDataSource.getContainer(treeType) 1214 1410 if (container.GetCount() == 0) continue; … … 1227 1423 var fullName = this._rdfImportDataSource._getRDFValue(resource, "fullName") 1228 1424 var id = this._rdfImportDataSource._getRDFValue(resource, "id") 1425 1229 1426 id = id ? relevantIDs[id].id : null 1427 var smtp = this._rdfImportDataSource._getRDFValue(resource, "smtp") 1428 smtp = (smtp && smtp != DEFAULT_SMTP_TAG) ? relevantSMTPs[smtp].smtp : smtp 1429 1230 1430 var localIdentityData = new identityData(this._currentWindow, email, fullName, id, 1231 1431 new identityDataExtras(this._currentWindow, this._rdfImportDataSource, resource)) … … 1234 1434 var resource = this._rdfDataSource._getRDFResourceForVIdentity(name, treeType); 1235 1435 if (id) this._rdfDataSource._setRDFValue(resource, "id", id); // localIdentityData can only store valid id's, this one might be a temporary invalid id 1436 if (smtp) this._rdfDataSource._setRDFValue(resource, "smtp", smtp); // localIdentityData can only store valid smtp's, this one might be a temporary invalid smtp 1236 1437 } 1237 1438 } … … 1243 1444 1244 1445 Log.debug("import: cleaning ID storages:"); 1245 this._rdfDataSource = new rdfDatasource(this._currentWindow, this._rdfFileName, true);1246 1446 1247 1447 this._storeMappedIDs(relevantIDs); 1248 1448 this._rdfDataSource.searchIdentityMismatch(); 1449 this._storeMappedSMTPs(relevantSMTPs); 1450 this._rdfDataSource.searchSmtpMismatch(); 1451 1452 // extension from version 0.10 on does not use any extra SMTP information anymore 1453 // and uses the SMTP-server from base identity instead. 1454 // check if any collisions between previously stored SMTP and base identity exists and solve this. 1455 Log.debug("import: search SMTP-ID mismatches"); 1456 this._searchSmtpIdMismatch(); 1457 1458 this._removeSMTPEntries(); 1249 1459 1250 1460 this._rdfDataSource.refreshAccountInfo();
Note: See TracChangeset
for help on using the changeset viewer.