This is just some static backup of the original site, don't expect every link to work!

Ignore:
Timestamp:
Sep 9, 2018, 2:36:02 AM (4 years ago)
Author:
rene <rene@…>
Branches:
ng_0.9
Children:
c5860f
Parents:
bc6c6b
Message:

removed everything related to smtp-storage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/vI_rdfDatasource.js

    rbc6c6b r85fa10  
    3232Components.utils.import("resource://v_identity/vI_identityData.js");
    3333Components.utils.import("resource://gre/modules/Services.jsm");
     34
     35ChromeUtils.import("resource:///modules/mailServices.js");
    3436
    3537// if no 3pane-window found, return current window
     
    6870  this._currentWindow = currentWindow;
    6971  this._rdfFileName = rdfFileName;
     72  this._dontRegisterObserver = dontRegisterObserver;
    7073  if (this._rdfFileName) this.init();
    71   if (!dontRegisterObserver) this.AccountManagerObserver.register(this);
    72   try {
    73     this._extVersion = get3PaneWindow().virtualIdentityExtension.extensionVersion;
    74   } catch (e) {}
     74  if (!this._dontRegisterObserver) this.AccountManagerObserver.register(this);
     75  this._extVersion = get3PaneWindow().virtualIdentityExtension.extensionVersion;
     76  Log.debug("rdfDatasource: read ext. Version '" + this._extVersion + "'");
    7577}
    7678
     
    7880  _currentWindow: null,
    7981  _extVersion: null,
    80   _rdfVersion: "0.0.5",
     82  _rdfVersion: "0.0.6",
    8183  _rdfService: Components.classes["@mozilla.org/rdf/rdf-service;1"]
    8284    .getService(Components.interfaces.nsIRDFService),
     
    9193  _rdfNSAccounts: "vIAccounts",
    9294  _rdfNSIdentities: "vIAccounts/id",
    93   _rdfNSSMTPservers: "vIAccounts/smtp",
    9495
    9596  _virtualIdentityID: "{dddd428e-5ac8-4a81-9f78-276c734f75b8}",
    9697
     98  _dontRegisterObserver: false,
     99 
    97100  _emailContainer: Components.classes["@mozilla.org/rdf/container;1"]
    98101    .createInstance(Components.interfaces.nsIRDFContainer),
     
    108111
    109112  _identityContainer: Components.classes["@mozilla.org/rdf/container;1"]
    110     .createInstance(Components.interfaces.nsIRDFContainer),
    111 
    112   _smtpContainer: Components.classes["@mozilla.org/rdf/container;1"]
    113113    .createInstance(Components.interfaces.nsIRDFContainer),
    114114
     
    125125    case "identity":
    126126      return this._identityContainer;
    127     case "smtp":
    128       return this._smtpContainer;
    129127    }
    130128    return null;
     
    187185        .GetResource(this._rdfNS + this._rdfNSIdentities);
    188186      this._identityContainer.Init(this._rdfDataSource, storageRes);
    189       storageRes = this._rdfService
    190         .GetResource(this._rdfNS + this._rdfNSSMTPservers);
    191       this._smtpContainer.Init(this._rdfDataSource, storageRes);
    192187    } catch (e) {};
    193188  },
     
    216211    switch (currentVersion) {
    217212    case null:
    218     case "0.0.1":
    219     case "0.0.2":
    220213      this._createRDFContainers(); // no break
    221     case "0.0.3":
    222       this._tagDefaultSMTP();
    223     case "0.0.4":
    224214    default:
    225215      this._createAccountInfoContainers();
     
    256246    }
    257247  },
    258   // **************    RDF UPGRADE CODE    ****************************************************
    259   _tagDefaultSMTP: function () {
    260     Log.debug("upgrade: tagDefaultSMTP");
    261     for (let treeType of Array("email", "maillist", "newsgroup", "filter")) {
    262       var enumerator = this.getContainer(treeType).GetElements();
    263       while (enumerator && enumerator.hasMoreElements()) {
    264         var resource = enumerator.getNext();
    265         resource.QueryInterface(Components.interfaces.nsIRDFResource);
    266         var smtp = this._getRDFValue(resource, "smtp")
    267         if (!smtp || smtp == "") this._setRDFValue(resource, "smtp", DEFAULT_SMTP_TAG);
    268       }
    269     }
    270   },
    271   // **************    RDF UPGRADE CODE    ****************************************************
     248
    272249  _createAccountInfoContainers: function () {
    273250    Log.debug("upgrade: createAccountInfoContainers");
     
    279256    var identityRes = this._rdfService
    280257      .GetResource(this._rdfNS + this._rdfNSIdentities);
    281     var smtpRes = this._rdfService
    282       .GetResource(this._rdfNS + this._rdfNSSMTPservers);
     258
    283259    this._setRDFValue(accountRes, "name", "Accounts");
    284260    this._setRDFValue(identityRes, "name", "Identities");
    285     this._setRDFValue(smtpRes, "name", "SMTP-Server");
    286261
    287262    rdfContainerUtils.MakeBag(this._rdfDataSource, accountRes);
    288263    rdfContainerUtils.MakeBag(this._rdfDataSource, identityRes);
    289     rdfContainerUtils.MakeBag(this._rdfDataSource, smtpRes);
    290264
    291265    var accountContainer = Components.classes["@mozilla.org/rdf/container;1"].
     
    296270    // append all new containers to accountRes
    297271    if (accountContainer.IndexOf(identityRes) == -1) accountContainer.AppendElement(identityRes);
    298     if (accountContainer.IndexOf(smtpRes) == -1) accountContainer.AppendElement(smtpRes);
    299272
    300273    this._initContainers();
     
    371344
    372345  clean: function () {
    373     this.AccountManagerObserver.unregister();
     346    if (!this._dontRegisterObserver) this.AccountManagerObserver.unregister();
    374347    this._flush();
    375348  },
     
    401374      this._unsetRDFValue(resource, "email", this._getRDFValue(resource, "email"))
    402375      this._identityContainer.RemoveElement(resource, false);
    403     }
    404 
    405     enumerator = this._smtpContainer.GetElements();
    406     while (enumerator && enumerator.hasMoreElements()) {
    407       var resource = enumerator.getNext();
    408       resource.QueryInterface(Components.interfaces.nsIRDFResource);
    409       this._unsetRDFValue(resource, "label", this._getRDFValue(resource, "label"))
    410       this._unsetRDFValue(resource, "hostname", this._getRDFValue(resource, "hostname"))
    411       this._unsetRDFValue(resource, "username", this._getRDFValue(resource, "username"))
    412       this._smtpContainer.RemoveElement(resource, false);
    413376    }
    414377  },
     
    482445  },
    483446
    484   repairAccountMismatch: function (type, mismatchItems) {
    485     var keyField = (type == "identity") ? "id" : "smtp" // field to change is 'id' or 'smtp' dependent on type
     447  repairMismatch: function (type, mismatchItems) {
     448    // type might be 'id' or 'smtpid' - dependent on trigger
    486449    for (var i = 0; i < mismatchItems.length; i++) {
    487450      Log.debug("repairAccountMismatch change " + mismatchItems[i].oldkey + " into " + mismatchItems[i].key);
     
    492455          var resource = enumerator.getNext();
    493456          resource.QueryInterface(Components.interfaces.nsIRDFResource);
    494           if (this._getRDFValue(resource, keyField) == mismatchItems[i].oldkey) {
    495             if (mismatchItems[i].key == "") this._unsetRDFValue(resource, keyField, mismatchItems[i].oldkey)
    496             else this._setRDFValue(resource, keyField, mismatchItems[i].key)
     457         
     458          // old smtp (stored in pre-0.10 rdf) and id have to match, set new id
     459          if (type == 'smtpid') {
     460            var smtp = mismatchItems[i].oldkey.split("-")[0];
     461            var id = mismatchItems[i].oldkey.split("-")[1];
     462            if (this._getRDFValue(resource, 'id') == id && this._getRDFValue(resource, 'smtp') == smtp) {
     463              if (mismatchItems[i].key == "") this._unsetRDFValue(resource, 'id', id)
     464              else this._setRDFValue(resource, 'id', mismatchItems[i].key)
     465            }
     466          }
     467          // 'id' replacement
     468          else if (this._getRDFValue(resource, 'id') == mismatchItems[i].oldkey) {
     469            if (mismatchItems[i].key == "") this._unsetRDFValue(resource, 'id', mismatchItems[i].oldkey)
     470            else this._setRDFValue(resource, 'id', mismatchItems[i].key)
    497471          }
    498472        }
    499473      }
    500     }
    501   },
    502 
    503   getRelevantSMTPs: function () {
    504     var relevantSMTPs = new Object();
    505     // search relevant SMTPs
    506     for (let treeType of Array("email", "maillist", "newsgroup", "filter")) {
    507       var enumerator = this.getContainer(treeType).GetElements();
    508       while (enumerator && enumerator.hasMoreElements()) {
    509         var resource = enumerator.getNext();
    510         resource.QueryInterface(Components.interfaces.nsIRDFResource);
    511         var smtp = this._getRDFValue(resource, "smtp")
    512         if (smtp && smtp != DEFAULT_SMTP_TAG) {
    513           if (!relevantSMTPs[smtp]) relevantSMTPs[smtp] = 1;
    514           else relevantSMTPs[smtp] += 1;
    515         }
    516       }
    517     }
    518     return relevantSMTPs;
    519   },
    520 
    521   searchSmtpMismatch: function () {
    522     Log.debug("searchSmtpMismatch");
    523 
    524     var relevantSMTPs = this.getRelevantSMTPs();
    525     var mismatchSMTPs = [];
    526 
    527     for (var smtp in relevantSMTPs) {
    528       var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
    529         .getService(Components.interfaces.nsISmtpService);
    530       // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService
    531       if (typeof (smtpService.servers) == "object") servers = smtpService.servers;
    532       else servers = smtpService.smtpServers;
    533 
    534       var found = false;
    535       while (servers && servers.hasMoreElements()) {
    536         var server = servers.getNext();
    537         if (server instanceof Components.interfaces.nsISmtpServer &&
    538           !server.redirectorType && smtp == server.key) {
    539           found = true;
    540           break;
    541         }
    542       }
    543       var resource = this._rdfService.GetResource(this._rdfNS + this._rdfNSSMTPservers + "/" + smtp);
    544       var rdfSMTPlabel = this._getRDFValue(resource, "label");
    545       var rdfHostname = this._getRDFValue(resource, "hostname");
    546       var rdfUsername = this._getRDFValue(resource, "username")
    547       if (!found || rdfSMTPlabel != (server.description ? server.description : server.hostname) && rdfHostname != server.hostname)
    548         mismatchSMTPs.push({
    549           oldkey: smtp,
    550           label: rdfSMTPlabel,
    551           ext1: rdfHostname,
    552           ext2: rdfUsername,
    553           count: relevantSMTPs[smtp],
    554           key: ""
    555         })
    556     }
    557     if (mismatchSMTPs.length > 0) {
    558       Log.debug(" found mismatches on smtp(s).");
    559       get3PaneWindow().openDialog("chrome://v_identity/content/vI_rdfAccountMismatchDialog.xul", 0,
    560         "chrome, dialog, modal, alwaysRaised, resizable=yes", "smtp", mismatchSMTPs,
    561         /* callback: */
    562         this).focus();
    563       return true;
    564     } else {
    565       Log.debug(" found no mismatch");
    566       return false;
    567474    }
    568475  },
     
    588495      }
    589496    }
    590 
    591     function storeSmtp(server, parent) {
    592       //             Log.debug("storeAccounts smtp store id " + server.key);
    593       var resource = parent._rdfService.GetResource(parent._rdfNS + parent._rdfNSSMTPservers + "/" + server.key);
    594       parent._setRDFValue(resource, "label", (server.description ? server.description : server.hostname));
    595       parent._setRDFValue(resource, "hostname", server.hostname);
    596       parent._setRDFValue(resource, "username", server.username);
    597       var position = parent._smtpContainer.IndexOf(resource); // check for index in new recType
    598       if (position != -1) parent._smtpContainer.InsertElementAt(resource, position, false);
    599       else parent._smtpContainer.AppendElement(resource);
    600     }
    601 
    602     var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
    603       .getService(Components.interfaces.nsISmtpService);
    604     // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService
    605     if (typeof (smtpService.servers) == "object") servers = smtpService.servers;
    606     else servers = smtpService.smtpServers;
    607 
    608     while (servers && servers.hasMoreElements()) {
    609       var server = servers.getNext();
    610       if (server instanceof Components.interfaces.nsISmtpServer && !server.redirectorType) storeSmtp(server, this);
    611     }
    612 
    613     //         Log.debug("storeAccounts done");
    614497  },
    615498
     
    679562    this._unsetRDFValue(resource, "fullName", this._getRDFValue(resource, "fullName"))
    680563    this._unsetRDFValue(resource, "id", this._getRDFValue(resource, "id"))
    681     this._unsetRDFValue(resource, "smtp", this._getRDFValue(resource, "smtp"))
    682564    this._unsetRDFValue(resource, "name", this._getRDFValue(resource, "name"))
    683565
     
    714596      var fullName = this._getRDFValue(resource, "fullName")
    715597      var id = this._getRDFValue(resource, "id")
    716       var smtp = this._getRDFValue(resource, "smtp")
    717598      var used = this._getRDFValue(resource, "timeUsed")
    718599      var changed = this._getRDFValue(resource, "timeChanged")
    719       if (!smtp) smtp = NO_SMTP_TAG;
    720600      let self = this;
    721       var localIdentityData = new identityData(this._currentWindow, email, fullName, id, smtp,
     601      var localIdentityData = new identityData(this._currentWindow, email, fullName, id,
    722602        new identityDataExtras(this._currentWindow, self, resource))
    723603      addNewDatum(resource, name, localIdentityData, idData, used, changed)
     
    739619    } else {
    740620      Log.debug("__getDescriptionAndType: '" + recipient + "' is no MailList");
    741       var localIdentityData = new identityData(this._currentWindow, recipient, null, null, null, null, null, null);
     621      var localIdentityData = new identityData(this._currentWindow, recipient, null, null, null, null, null);
    742622      return {
    743623        recDesc: localIdentityData.combinedName,
     
    847727    var fullName = this._getRDFValue(resource, "fullName")
    848728    var id = this._getRDFValue(resource, "id")
    849     var smtp = this._getRDFValue(resource, "smtp")
    850     if (!smtp) smtp = NO_SMTP_TAG;
    851729
    852730    let _date = new Date();
     
    854732
    855733    Log.debug("email='" + email +
    856       "' fullName='" + fullName + "' id='" + id + "' smtp='" + smtp + "'");
     734      "' fullName='" + fullName + "' id='" + id + "'");
    857735
    858736    let self = this;
    859     var localIdentityData = new identityData(this._currentWindow, email, fullName, id, smtp,
     737    var localIdentityData = new identityData(this._currentWindow, email, fullName, id,
    860738      new identityDataExtras(this._currentWindow, self, resource))
    861739    return localIdentityData;
     
    874752    this.updateRDF(recipient.recDesc, recipient.recType, identityData,
    875753      vIprefs.get("storage_store_base_id"),
    876       vIprefs.get("storage_store_SMTP"),
    877754      null, null, false);
    878755  },
     
    885762  },
    886763
    887   updateRDF: function (recDescription, recType, localIdentityData, storeBaseID, storeSMTP, prevRecDescription, prevRecType, updateAllExtras) {
     764  updateRDF: function (recDescription, recType, localIdentityData, storeBaseID, prevRecDescription, prevRecType, updateAllExtras) {
    888765    //         Log.debug("(" + this._rdfNS + "): updateRDF recDescription=" + recDescription + " localIdentityData.email=" + localIdentityData.email);
    889766
     
    911788      this._setRDFValue(resource, "id", localIdentityData.id.key);
    912789    else this._unsetRDFValue(resource, "id", this._getRDFValue(resource, "id"))
    913     if (storeSMTP && localIdentityData.smtp.key != NO_SMTP_TAG)
    914       this._setRDFValue(resource, "smtp", localIdentityData.smtp.key);
    915     else this._unsetRDFValue(resource, "smtp", this._getRDFValue(resource, "smtp"))
    916790    this._setRDFValue(resource, "name", recDescription);
    917791
     
    953827    _uninstall: false,
    954828    observe: function (subject, topic, data) {
    955       if (topic == "am-smtpChanges" || topic == "am-acceptChanges") {
    956         Log.debug("account/smtp changes observed");
     829      if (topic == "am-acceptChanges") {
     830        Log.debug("account/identity changes observed");
    957831        this.self.searchIdentityMismatch();
    958         this.self.searchSmtpMismatch();
    959832        this.self.refreshAccountInfo();
    960833      }
     
    965838      var obsService = Components.classes["@mozilla.org/observer-service;1"].
    966839      getService(Components.interfaces.nsIObserverService)
    967       obsService.addObserver(this, "am-smtpChanges", false);
    968840      obsService.addObserver(this, "am-acceptChanges", false);
    969841    },
    970842    unregister: function () {
     843      Log.debug("unregister AccountManagerObserver");
    971844      var obsService = Components.classes["@mozilla.org/observer-service;1"].
    972845      getService(Components.interfaces.nsIObserverService)
    973846      try {
    974         obsService.removeObserver(this, "am-smtpChanges");
    975847        obsService.removeObserver(this, "am-acceptChanges");
    976848      } catch (e) {};
     
    982854function rdfDatasourceAccess(currentWindow) {
    983855  this._currentWindow = currentWindow;
    984   this._rdfDataSource = new rdfDatasource(this._currentWindow, "virtualIdentity.rdf", false);
     856  this._rdfDataSource = new rdfDatasource(this._currentWindow, "virtualIdentity_0.10.rdf", false);
    985857  this.stringBundle = Services.strings.createBundle("chrome://v_identity/locale/v_identity.properties");
    986858}
     
    11281000
    11291001// create with name of the file to import into
    1130 function rdfDatasourceImporter(currentWindow, rdfFileName) {
     1002function rdfDatasourceImporter(currentWindow, rdfFileName, importNow = true) {
    11311003  this._currentWindow = currentWindow;
    11321004  this._rdfFileName = rdfFileName;
    1133   if (this._rdfFileName) this.import();
     1005  if (importNow && this._rdfFileName) this.import();
    11341006}
    11351007
     
    11511023        if (name == identity.identityName || (fullName == identity.fullName && email == identity.email)) return identity.key;
    11521024      }
    1153     }
    1154     return null;
    1155   },
    1156 
    1157   _getMatchingSMTP: function (label, hostname, username) {
    1158     var servers, smtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
    1159       .getService(Components.interfaces.nsISmtpService);
    1160     // check for new https://hg.mozilla.org/comm-central/rev/fab9e5145cd4 smtpService
    1161     if (typeof (smtpService.servers) == "object") servers = smtpService.servers;
    1162     else servers = smtpService.smtpServers;
    1163 
    1164     while (servers && servers.hasMoreElements()) {
    1165       var server = servers.getNext();
    1166       if (server instanceof Components.interfaces.nsISmtpServer && !server.redirectorType)
    1167         if (label == (server.description ? server.description : server.hostname) || (hostname == server.hostname && username == server.username))
    1168           return server.key;
    11691025    }
    11701026    return null;
     
    12081064  },
    12091065
    1210   _translateRelevantSMTPs: function () {
    1211     var relevantSMTPs = this._rdfImportDataSource.getRelevantSMTPs();
    1212     for (var smtp in relevantSMTPs) {
    1213       var resource = this._rdfService.GetResource(this._rdfImportDataSource._rdfNS + this._rdfImportDataSource._rdfNSSMTPservers + "/" + smtp);
    1214       var values = {
    1215         smtp: null,
    1216         label: null,
    1217         hostname: null,
    1218         username: null
    1219       }
    1220       values.label = this._rdfImportDataSource._getRDFValue(resource, "label");
    1221       values.hostname = this._rdfImportDataSource._getRDFValue(resource, "hostname");
    1222       values.username = this._rdfImportDataSource._getRDFValue(resource, "username");
    1223       values.smtp = this._getMatchingSMTP(values.label, values.hostname, values.username);
    1224       values.smtp = values.smtp ? values.smtp : "import_" + smtp;
    1225       relevantSMTPs[smtp] = values;
    1226       Log.debug("import: translate relevant SMTP from previous '" + smtp + "' to current '" + relevantSMTPs[smtp].smtp + "'");
    1227     }
    1228     return relevantSMTPs;
    1229   },
    1230 
    1231   _storeMappedSMTPs: function (relevantSMTPs) {
    1232     for (var smtp in relevantSMTPs) {
    1233       if (relevantSMTPs[smtp].smtp == "import_" + smtp) {
    1234         var resource = this._rdfService
    1235           .GetResource(this._rdfDataSource._rdfNS + this._rdfDataSource._rdfNSSMTPservers + "/" + relevantSMTPs[smtp].smtp);
    1236         this._rdfDataSource._setRDFValue(resource, "label", relevantSMTPs[smtp].label);
    1237         this._rdfDataSource._setRDFValue(resource, "hostname", relevantSMTPs[smtp].hostname);
    1238         this._rdfDataSource._setRDFValue(resource, "username", relevantSMTPs[smtp].username);
    1239 
    1240         var position = this._rdfDataSource._smtpContainer.IndexOf(resource); // check for index in new recType
    1241         if (position != -1) this._rdfDataSource._smtpContainer.InsertElementAt(resource, position, false);
    1242         else this._rdfDataSource._smtpContainer.AppendElement(resource);
    1243       }
    1244     }
    1245   },
    1246 
     1066  //--------------------------------------------------------------------------------------------------------
     1067  //only required for update from pre 0.10 versions
     1068  _rdfNSSMTPservers: "vIAccounts/smtp",
     1069
     1070  _getSMTPIDCombinations: function () {
     1071    var SMTPIDCombinations = new Object();
     1072    var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
     1073              .getService(Components.interfaces.nsIMsgAccountManager);
     1074    // search relevant SMTPs
     1075    for (let treeType of Array("email", "maillist", "newsgroup", "filter")) {
     1076      var enumerator = this._rdfImportDataSource.getContainer(treeType).GetElements();
     1077      while (enumerator && enumerator.hasMoreElements()) {
     1078        var resource = enumerator.getNext();
     1079        resource.QueryInterface(Components.interfaces.nsIRDFResource);
     1080        var smtp = this._rdfImportDataSource._getRDFValue(resource, "smtp")
     1081        if (smtp) {
     1082          var id = this._rdfImportDataSource._getRDFValue(resource, "id")
     1083          if (id) {
     1084            if (!SMTPIDCombinations[smtp + "-" + id]) SMTPIDCombinations[smtp + "-" + id] = 1;
     1085            else SMTPIDCombinations[smtp + "-" + id] += 1;
     1086          }
     1087        }
     1088      }
     1089    }
     1090    return SMTPIDCombinations;
     1091  },
     1092
     1093  _searchSmtpIdMismatch: function () {
     1094    Log.debug("searchSmtpIdMismatch (only relevant for pre-0.10 rdf files)");
     1095    var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
     1096              .getService(Components.interfaces.nsIMsgAccountManager);
     1097
     1098    var relevantSMTPs = this._getSMTPIDCombinations();
     1099    var SMTPIDCombinations = [];
     1100
     1101    for (var smtpid in relevantSMTPs) {
     1102      var smtp = smtpid.split("-")[0];
     1103      var id = smtpid.split("-")[1];
     1104
     1105      Log.debug("search combination smtp=" + smtp + " id=" + id + " smtp(id)=" + AccountManager.getIdentity(id).smtpServerKey);
     1106     
     1107      var id_smtp = AccountManager.getIdentity(id).smtpServerKey;
     1108      if (!id_smtp)
     1109        id_smtp = MailServices.smtp.defaultServer.key
     1110     
     1111      if (smtp == id_smtp)
     1112          break;
     1113
     1114      var resource = this._rdfImportDataSource._rdfService.GetResource(this._rdfImportDataSource._rdfNS + this._rdfNSSMTPservers + "/" + smtp);
     1115      var rdfSMTPlabel = this._rdfImportDataSource._getRDFValue(resource, "label");
     1116
     1117      var servers = MailServices.smtp.servers;
     1118
     1119      var smtpName;
     1120      while (servers && servers.hasMoreElements()) {
     1121        var server = servers.getNext();
     1122        if (server instanceof Components.interfaces.nsISmtpServer &&
     1123          !server.redirectorType && id_smtp == server.key) {
     1124          smtpName = server.description ? server.description : server.hostname;
     1125          break;
     1126        }
     1127      }
     1128
     1129      SMTPIDCombinations.push({
     1130        oldkey: smtpid,
     1131        label: rdfSMTPlabel + " / ",
     1132        ext1: AccountManager.getIdentity(id).identityName,
     1133        ext2: "(" + smtpName + ")",
     1134        count: relevantSMTPs[smtpid],
     1135        key: ""
     1136      })
     1137    }
     1138    if (SMTPIDCombinations.length > 0) {
     1139      Log.debug(" found mismatches on smtpid(s).");
     1140      get3PaneWindow().openDialog("chrome://v_identity/content/vI_rdfAccountMismatchDialog.xul", 0,
     1141        "chrome, dialog, modal, alwaysRaised, resizable=yes", "smtpid", SMTPIDCombinations,
     1142        /* callback: */
     1143        this._rdfImportDataSource).focus();
     1144      return true;
     1145    } else {
     1146      Log.debug(" found no mismatch");
     1147      return false;
     1148    }
     1149  },
     1150  //--------------------------------------------------------------------------------------------------------
     1151 
    12471152  import: function () {
    12481153    var filePicker = Components.classes["@mozilla.org/filepicker;1"]
     
    12531158    filePicker.appendFilters(Components.interfaces.nsIFilePicker.filterText | Components.interfaces.nsIFilePicker.filterAll);
    12541159
    1255     if (this._pickerShow(filePicker) == Components.interfaces.nsIFilePicker.returnOK) {
    1256       Log.debug("import: preparation:");
    1257 
    1258       var importRdfDataFile = Components.classes["@mozilla.org/file/local;1"]
    1259         .createInstance(Components.interfaces.nsIFile);
    1260       var file = Components.classes["@mozilla.org/file/directory_service;1"]
    1261         .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
    1262 
    1263       initWithFilePath_tryDelimiters(importRdfDataFile, file.path, this._rdfFileName + "_import");
    1264       filePicker.file.copyTo(importRdfDataFile.parent, importRdfDataFile.leafName);
    1265 
    1266       Log.debug("import: copied file from " + filePicker.file.path + " to " + importRdfDataFile.path + "'");
    1267 
    1268       // init Datasources
     1160    if (this._pickerShow(filePicker) == Components.interfaces.nsIFilePicker.returnOK)
     1161      this._importFile(filePicker.file);
     1162  },
     1163
     1164  importFileByName: function (fileName) {
     1165    var newFile = Components.classes["@mozilla.org/file/local;1"]
     1166      .createInstance(Components.interfaces.nsIFile);
     1167
     1168    var file = Components.classes["@mozilla.org/file/directory_service;1"]
     1169      .getService(Components.interfaces.nsIProperties)
     1170      .get("ProfD", Components.interfaces.nsIFile);
     1171
     1172    initWithFilePath_tryDelimiters(newFile, file.path, fileName);
     1173
     1174    this._importFile(newFile);
     1175  },
     1176
     1177  _importFile: function (file) {
     1178    Log.debug("import: preparation:");
     1179
     1180    var importRdfDataFile = Components.classes["@mozilla.org/file/local;1"]
     1181      .createInstance(Components.interfaces.nsIFile);
     1182    var tmpfile = Components.classes["@mozilla.org/file/directory_service;1"]
     1183      .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
     1184
     1185    initWithFilePath_tryDelimiters(importRdfDataFile, tmpfile.path, this._rdfFileName + "_import");
     1186    file.copyTo(importRdfDataFile.parent, importRdfDataFile.leafName);
     1187
     1188    Log.debug("import: copied file from " + file.path + " to " + importRdfDataFile.path + "'");
     1189
     1190    // init Datasources
     1191    this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true);
     1192
     1193    // search matching IDs for anyones used in import-file
     1194    var relevantIDs = this._translateRelevantIDs();
     1195
     1196    // extension from version 0.10 on does not use any extra SMTP information anymore
     1197    // and uses the SMTP-server from base identity instead.
     1198    // check if any collisions between previously stored SMTP and base identity exists and solve this.
     1199    Log.debug("import: search SMTP-ID mismatches");
     1200    this._searchSmtpIdMismatch();
     1201
     1202    Log.debug("import: preparation done.");
     1203
     1204    for (let treeType of Array("email", "maillist", "newsgroup", "filter")) {
     1205      // re-initialize importDataSource to point rdfService to the right Resources
    12691206      this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true);
    1270 
    1271       // search matching IDs and SMTPs for anyones used in import-file
    1272       var relevantIDs = this._translateRelevantIDs();
    1273       var relevantSMTPs = this._translateRelevantSMTPs();
    1274 
    1275       Log.debug("import: preparation done.");
    1276 
    1277       for (let treeType of Array("email", "maillist", "newsgroup", "filter")) {
    1278         // re-initialize importDataSource to point rdfService to the right Resources
    1279         this._rdfImportDataSource = new rdfDatasource(this._currentWindow, importRdfDataFile.leafName, true);
    1280         var container = this._rdfImportDataSource.getContainer(treeType)
    1281         if (container.GetCount() == 0) continue;
    1282         Log.debug("importing " + treeType + ": " + container.GetCount() + " datasets from " + this._rdfImportDataSource._rdfDataSource.URI);
    1283         var enumerator = container.GetElements();
    1284         // re-initialize dataSource to point rdfService to the right Resources
    1285         this._rdfDataSource = new rdfDatasource(this._currentWindow, this._rdfFileName, true);
    1286         var count = 0;
    1287         while (enumerator.hasMoreElements()) {
    1288           var resource = enumerator.getNext();
    1289           count += 1;
    1290           resource.QueryInterface(Components.interfaces.nsIRDFResource);
    1291           //                     Log.debug(" " + count + " ");
    1292           var name = this._rdfImportDataSource._getRDFValue(resource, "name")
    1293           var email = this._rdfImportDataSource._getRDFValue(resource, "email")
    1294           var fullName = this._rdfImportDataSource._getRDFValue(resource, "fullName")
    1295           var id = this._rdfImportDataSource._getRDFValue(resource, "id")
    1296           id = id ? relevantIDs[id].id : null
    1297           var smtp = this._rdfImportDataSource._getRDFValue(resource, "smtp")
    1298           smtp = (smtp && smtp != DEFAULT_SMTP_TAG) ? relevantSMTPs[smtp].smtp : smtp
    1299           var localIdentityData = new identityData(this._currentWindow, email, fullName, id, smtp,
    1300             new identityDataExtras(this._currentWindow, this._rdfImportDataSource, resource))
    1301 
    1302           this._rdfDataSource.updateRDF(name, treeType, localIdentityData, false, false, null, null, true)
    1303           var resource = this._rdfDataSource._getRDFResourceForVIdentity(name, treeType);
    1304           if (id) this._rdfDataSource._setRDFValue(resource, "id", id); // localIdentityData can only store valid id's, this one might be a temporary invalid id
    1305           if (smtp) this._rdfDataSource._setRDFValue(resource, "smtp", smtp); // localIdentityData can only store valid smtp's, this one might be a temporary invalid smtp
    1306         }
    1307       }
    1308 
    1309       Log.debug("import: removing temporary file " + importRdfDataFile.path);
    1310       this._rdfImportDataSource = null;
    1311       importRdfDataFile.remove(false);
    1312       Log.debug("import: import done.");
    1313 
    1314       Log.debug("import: cleaning ID/SMTP storages:");
     1207      var container = this._rdfImportDataSource.getContainer(treeType)
     1208      if (container.GetCount() == 0) continue;
     1209      Log.debug("importing " + treeType + ": " + container.GetCount() + " datasets from " + this._rdfImportDataSource._rdfDataSource.URI);
     1210      var enumerator = container.GetElements();
     1211      // re-initialize dataSource to point rdfService to the right Resources
    13151212      this._rdfDataSource = new rdfDatasource(this._currentWindow, this._rdfFileName, true);
    1316 
    1317       this._storeMappedIDs(relevantIDs);
    1318       this._rdfDataSource.searchIdentityMismatch();
    1319       this._storeMappedSMTPs(relevantSMTPs);
    1320       this._rdfDataSource.searchSmtpMismatch();
    1321 
    1322       this._rdfDataSource.refreshAccountInfo();
    1323       this._rdfDataSource.clean();
    1324       this._rdfDataSource = null;
    1325       Log.debug("import: cleaning ID/SMTP storages done.");
    1326       Log.debug("IMPORT DONE.");
    1327     }
     1213      var count = 0;
     1214      while (enumerator.hasMoreElements()) {
     1215        var resource = enumerator.getNext();
     1216        count += 1;
     1217        resource.QueryInterface(Components.interfaces.nsIRDFResource);
     1218        //                     Log.debug(" " + count + " ");
     1219        var name = this._rdfImportDataSource._getRDFValue(resource, "name")
     1220        var email = this._rdfImportDataSource._getRDFValue(resource, "email")
     1221        var fullName = this._rdfImportDataSource._getRDFValue(resource, "fullName")
     1222        var id = this._rdfImportDataSource._getRDFValue(resource, "id")
     1223        id = id ? relevantIDs[id].id : null
     1224        var localIdentityData = new identityData(this._currentWindow, email, fullName, id,
     1225          new identityDataExtras(this._currentWindow, this._rdfImportDataSource, resource))
     1226
     1227        this._rdfDataSource.updateRDF(name, treeType, localIdentityData, false, null, null, true)
     1228        var resource = this._rdfDataSource._getRDFResourceForVIdentity(name, treeType);
     1229        if (id) this._rdfDataSource._setRDFValue(resource, "id", id); // localIdentityData can only store valid id's, this one might be a temporary invalid id
     1230      }
     1231    }
     1232
     1233    Log.debug("import: removing temporary file " + importRdfDataFile.path);
     1234    this._rdfImportDataSource = null;
     1235    importRdfDataFile.remove(false);
     1236    Log.debug("import: import done.");
     1237
     1238    Log.debug("import: cleaning ID storages:");
     1239    this._rdfDataSource = new rdfDatasource(this._currentWindow, this._rdfFileName, true);
     1240
     1241    this._storeMappedIDs(relevantIDs);
     1242    this._rdfDataSource.searchIdentityMismatch();
     1243
     1244    this._rdfDataSource.refreshAccountInfo();
     1245    this._rdfDataSource.clean();
     1246    this._rdfDataSource = null;
     1247    Log.debug("import: cleaning ID storages done.");
     1248    Log.debug("IMPORT DONE.");
    13281249  },
    13291250 
Note: See TracChangeset for help on using the changeset viewer.