Commit 30502acb authored by CardBook's avatar CardBook

version 34.2

parent 4a37b1aa
......@@ -10,16 +10,17 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
var wdw_addressbooksAdd = {
gRunningDirPrefId : [],
gFile : {},
gCardDAVURLs : [],
gRunningDirPrefId: [],
gFile: {},
gCardDAVURLs: [],
// [ [ AB type, URL, username, AB name, vCard version, AB type action, source id, collected true|false] ]
gAccountsFound : [],
gFinishParams : [],
gValidateURL : false,
gValidateDescription : "Validation module",
gSearchDefinition : {},
gFirstFirstStepDone : false,
gAccountsFound: [],
gFinishParams: [],
gValidateURL: false,
gValidateDescription: "Validation module",
gAutoconfigURL: "https://gitlab.com/CardBook/CardBook/raw/master/autoconfig/",
gSearchDefinition: {},
gFirstFirstStepDone: false,
lTimerRefreshTokenAll : {},
lTimerDiscoveryAll : {},
......@@ -76,7 +77,7 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
}
},
checkFindLinesRequired: function (aArray) {
checkFindLinesRequired: function () {
var canAdvance = false;
var i = 0;
while (true) {
......@@ -281,7 +282,7 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
document.getElementById('remotePagePasswordLabel').disabled=true;
document.getElementById('remotePagePassword').disabled=true;
document.getElementById('remotePagePassword').setAttribute('required', 'false');
document.getElementById('passwordCheckBox').disabled=true;
document.getElementById('remotePagePasswordCheckBox').disabled=true;
} else if (type == 'APPLE') {
document.getElementById('remotePageUriLabel').disabled=true;
document.getElementById('remotePageURI').disabled=true;
......@@ -289,7 +290,7 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
document.getElementById('remotePagePasswordLabel').disabled=false;
document.getElementById('remotePagePassword').disabled=false;
document.getElementById('remotePagePassword').setAttribute('required', 'true');
document.getElementById('passwordCheckBox').disabled=false;
document.getElementById('remotePagePasswordCheckBox').disabled=false;
} else {
document.getElementById('remotePageUriLabel').disabled=false;
document.getElementById('remotePageURI').disabled=false;
......@@ -297,7 +298,7 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
document.getElementById('remotePagePasswordLabel').disabled=false;
document.getElementById('remotePagePassword').disabled=false;
document.getElementById('remotePagePassword').setAttribute('required', 'true');
document.getElementById('passwordCheckBox').disabled=false;
document.getElementById('remotePagePasswordCheckBox').disabled=false;
}
wdw_addressbooksAdd.checklocationNetwork();
cardbookNotifications.setNotification("resultNotifications", "OK");
......@@ -368,12 +369,12 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
}
},
showPassword: function () {
var passwordType = document.getElementById('remotePagePassword').type;
if (passwordType != "password") {
document.getElementById('remotePagePassword').type = "password";
showPassword: function (aCheckBox) {
var myPasswordTextbox = document.getElementById(aCheckBox.id.replace(/Checkbox$/, ''));
if (myPasswordTextbox.type != "password") {
myPasswordTextbox.setAttribute('type', 'password');
} else {
document.getElementById('remotePagePassword').type = "";
myPasswordTextbox.removeAttribute('type');
}
},
......@@ -455,6 +456,8 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
return;
}
var dirPrefId = cardbookUtils.getUUID();
document.getElementById('findPageValidateButton' + aRowId).setAttribute('dirPrefId', dirPrefId);
var myType = document.getElementById('findPageValidateButton' + aRowId).getAttribute('validationType');
var myURL = document.getElementById('findPageURLTextbox' + aRowId).value;
var myUsername = document.getElementById('findUsernameTextbox' + aRowId).value;
......@@ -477,15 +480,19 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
cardbookPreferences.setId(dirPrefId, dirPrefId);
cardbookPreferences.setUrl(dirPrefId, myURL);
wdw_addressbooksAdd.gRunningDirPrefId.push(dirPrefId);
cardbookPasswordManager.removeAccount(aUsername, myURL);
cardbookPasswordManager.addAccount(aUsername, myURL, myPassword);
cardbookPasswordManager.removeAccount(myUsername, myURL);
cardbookPasswordManager.addAccount(myUsername, myURL, myPassword);
cardbookSynchronization.initMultipleOperations(dirPrefId);
cardbookRepository.cardbookServerValidation[dirPrefId] = {length: 0, user: myUsername};
cardbookRepository.cardbookServerSyncRequest[dirPrefId]++;
var connection = {connUser: myUsername, connPrefId: dirPrefId, connUrl: myURL, connDescription: wdw_addressbooksAdd.gValidateDescription};
var params = {aPrefIdType: myType};
cardbookSynchronization.validateWithoutDiscovery(connection, "GETDISPLAYNAME", params);
if (myURL.endsWith(".well-known/carddav")) {
cardbookSynchronization.discoverPhase1(connection, "GETDISPLAYNAME", params);
} else {
cardbookSynchronization.validateWithoutDiscovery(connection, "GETDISPLAYNAME", params);
}
wdw_addressbooksAdd.waitForFindDiscoveryFinished(aRowId, dirPrefId, myUsername, myPassword, myType);
}
},
......@@ -572,7 +579,7 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
myButton.setAttribute('label', cardbookRepository.strBundle.GetStringFromName("ValidationOKLabel"));
wdw_addressbooksAdd.checkFindLinesRequired();
cardbookSynchronization.finishMultipleOperations(aDirPrefId);
lTimerRefreshToken.cancel();
lTimerDiscovery.cancel();
}
}
}, 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
......@@ -758,7 +765,36 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
}
},
createBoxesForFinds: function (aType, aUsername, aAddPassword, aVCardVersion, aUrl, aABName) {
sendRequestForFinds: function (aEmail) {
let domain = aEmail.split("@")[1];
let request = new XMLHttpRequest();
request.open('GET', wdw_addressbooksAdd.gAutoconfigURL + domain, true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
let xmlParser = Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
let responseXML = xmlParser.parseFromString(request.responseText, "text/xml");
let responseJSON = new XMLToJSONParser(responseXML);
if (responseJSON && responseJSON.clientConfig && responseJSON.clientConfig[0] && responseJSON.clientConfig[0].carddavProvider
&& responseJSON.clientConfig[0].carddavProvider[0]) {
let infos = responseJSON.clientConfig[0].carddavProvider[0];
if (!infos.carddavURL[0]) {
return;
}
let url = infos.carddavURL[0].replace("%EMAILADDRESS%", aEmail);
let password = "";
let foundLogins = Services.logins.findLogins({}, "smtp://smtp." + domain, "", "");
if (foundLogins.length > 0) {
password = foundLogins[0].password;
}
let vCardVersion = infos.vCardVersion[0] ? infos.vCardVersion[0] : "";
wdw_addressbooksAdd.createBoxesForFinds("CARDDAV", aEmail, password, vCardVersion, url, aEmail);
}
}
};
request.send(null);
},
createBoxesForFinds: function (aType, aUsername, aPassword, aVCardVersion, aUrl, aABName) {
var aListRows = document.getElementById('findRows');
var aId = aListRows.childNodes.length - 1;
var aRow = document.createElement('row');
......@@ -788,13 +824,23 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
aTextbox.setAttribute('disabled', true);
aTextbox.value = aUsername;
if (aAddPassword) {
if (aPassword != null) {
var aTextbox = document.createElement('textbox');
aRow.appendChild(aTextbox);
aTextbox.setAttribute('id', 'findPasswordTextbox' + aId);
aTextbox.setAttribute("aria-labelledby", "findPagePasswordLabel");
aTextbox.setAttribute('flex', '1');
aTextbox.setAttribute('type', 'password');
aTextbox.setAttribute('required', true);
aTextbox.value = aPassword;
var aCheckbox = document.createElement('checkbox');
aRow.appendChild(aCheckbox);
aCheckbox.setAttribute('id', 'findPasswordTextbox' + aId + 'Checkbox');
aCheckbox.setAttribute("aria-labelledby", "findPagePasswordShowLabel");
aCheckbox.addEventListener("command", function() {
wdw_addressbooksAdd.showPassword(this);
}, false);
} else {
var aHbox = document.createElement('hbox');
aRow.appendChild(aHbox);
......@@ -815,13 +861,28 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
aTextbox.setAttribute("aria-labelledby", "findPageURLLabel");
aTextbox.setAttribute('hidden', 'true');
aTextbox.value = aUrl;
var aTextbox = document.createElement('textbox');
aRow.appendChild(aTextbox);
aTextbox.setAttribute('id', 'findPageABNameTextbox' + aId);
aTextbox.setAttribute("aria-labelledby", "findPageABNameLabel");
aTextbox.setAttribute('hidden', 'true');
aTextbox.value = aABName;
var found = false;
for (var i = 0; i < aListRows.childNodes.length; i++) {
if (document.getElementById('findPasswordTextbox' + i)) {
found = true;
break;
}
}
if (found) {
document.getElementById('findPagePasswordLabel').removeAttribute('hidden');
document.getElementById('findPagePasswordShowLabel').removeAttribute('hidden');
} else {
document.getElementById('findPagePasswordLabel').setAttribute('hidden', 'true');
document.getElementById('findPagePasswordShowLabel').setAttribute('hidden', 'true');
}
},
loadFinds: function () {
......@@ -849,20 +910,20 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
sortedEmailAccounts = cardbookUtils.sortArrayByString(sortedEmailAccounts,1);
sortedEmailAccounts = cardbookRepository.arrayUnique(sortedEmailAccounts);
for (var i = 0; i < sortedEmailAccounts.length; i++) {
for (var email of sortedEmailAccounts) {
let found = false;
// first OAuth
for (var j in cardbookRepository.cardbookOAuthData) {
if (sortedEmailAccounts[i].endsWith(cardbookRepository.cardbookOAuthData[j].EMAIL_TYPE)) {
wdw_addressbooksAdd.createBoxesForFinds(j, sortedEmailAccounts[i], false, cardbookRepository.cardbookOAuthData[j].VCARD_VERSIONS.toString(),
cardbookRepository.cardbookOAuthData[j].ROOT_API, sortedEmailAccounts[i]);
if (email.endsWith(cardbookRepository.cardbookOAuthData[j].EMAIL_TYPE)) {
wdw_addressbooksAdd.createBoxesForFinds(j, email, null, cardbookRepository.cardbookOAuthData[j].VCARD_VERSIONS.toString(),
cardbookRepository.cardbookOAuthData[j].ROOT_API, email);
found = true;
break;
}
}
// then CARDDAV
if (!found) {
var test;
wdw_addressbooksAdd.sendRequestForFinds(email);
}
}
......@@ -891,14 +952,31 @@ if ("undefined" == typeof(wdw_addressbooksAdd)) {
while (true) {
if (document.getElementById('findPageValidateButton' + i)) {
if (document.getElementById('findPageValidateButton' + i).getAttribute('validated') == "true") {
wdw_addressbooksAdd.gAccountsFound.push([document.getElementById('findPageValidateButton' + i).getAttribute('validationType'),
var type = document.getElementById('findPageValidateButton' + i).getAttribute('validationType');
var dirPrefId = document.getElementById('findPageValidateButton' + i).getAttribute('dirPrefId');
var vCard = document.getElementById('findPageVCardVersionsTextbox' + i).value.split(",");
var name = document.getElementById('findPageABNameTextbox' + i).value;
if (type == "CARDDAV") {
var result = cardbookUtils.fromValidationToArray(dirPrefId, type);
for (var j = 0; j < result.length; j++) {
if (name != "") {
result[j][3] = name;
}
if (vCard != "") {
result[j][4] = vCard;
}
wdw_addressbooksAdd.gAccountsFound.push(result[j]);
}
} else {
wdw_addressbooksAdd.gAccountsFound.push([type,
document.getElementById('findPageURLTextbox' + i).value,
document.getElementById('findUsernameTextbox' + i).value,
document.getElementById('findPageABNameTextbox' + i).value,
document.getElementById('findPageVCardVersionsTextbox' + i).value.split(","),
name,
vCard,
"",
"",
false]);
}
}
i++
} else {
......
......@@ -175,7 +175,7 @@
type="password"
required="true"
oninput="wdw_addressbooksAdd.remotePageTextboxInput();"/>
<checkbox id="passwordCheckBox" label="&remotePage.passwordShow.label;" oncommand="wdw_addressbooksAdd.showPassword();" disabled="false"/>
<checkbox id="remotePagePasswordCheckbox" label="&remotePage.passwordShow.label;" oncommand="wdw_addressbooksAdd.showPassword(this);" disabled="false"/>
</row>
</rows>
</grid>
......@@ -271,7 +271,8 @@
<row id="findHeadersRow">
<label id="findPageValidateLabel" value="&remotePage.validatebutton.label;"/>
<label id="findPageUserLabel" flex="1" value="&remotePage.user.label;"/>
<label id="findPagePasswordLabel" value="&remotePage.password.label;" type="password"/>
<label id="findPagePasswordLabel" value="&remotePage.password.label;"/>
<label id="findPagePasswordShowLabel" value="&remotePage.passwordShow.label;"/>
<label id="findPageVCardVersionsLabel" hidden="true"/>
<label id="findPageURLLabel" hidden="true"/>
<label id="findPageABNameLabel" hidden="true"/>
......
......@@ -101,7 +101,7 @@ if ("undefined" == typeof(ovl_synchro)) {
prefs.setCharPref("accountsShown", "all");
prefs.setCharPref("accountShown", "");
prefs.setCharPref("uncategorizedCards", "");
prefs.setCharPref("addonVersion", "34.1");
prefs.setCharPref("addonVersion", "34.2");
prefs.setCharPref("defaultRegion", "NOTSET");
prefs.setBoolPref("localDataEncryption", false);
......
......@@ -6,7 +6,7 @@
<Description about="urn:mozilla:install-manifest">
<em:id>cardbook@vigneau.philippe</em:id>
<em:name>CardBook</em:name>
<em:version>34.1</em:version>
<em:version>34.2</em:version>
<em:type>2</em:type>
<em:description>vCard Address Book</em:description>
<em:creator>Philippe Vigneau</em:creator>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment