From 1b3191ef3fdbaf65dd9282c5ce4e87fa9b593eaa Mon Sep 17 00:00:00 2001 From: Thomas Bille Date: Thu, 20 Apr 2017 16:37:59 +0200 Subject: Create a folder if the folder entered in the settings doesn't exist --- README.md | 2 +- src/components/nsNextcloud.js | 44 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1ea4830..c6bba62 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ It is currently possible to upload files as large as 1GB. ## Nextcloud configuration 1. Make sure that you have checked "Allow users to share via link" in the **"Sharing"** section of the admin page of your Nextcloud installation. If you have also checked-in the **"Enforce password protection"** option, make sure to fill the **"Password for uploaded files"** field when setting up the add-on in Thunderbird -1. By default your mail attachments will be saved in a folder called `Mail-attachments`. You currently need to create that folder in the root folder of your Nextcloud prior to using the Thunderbird add-on +1. By default your mail attachments will be saved in a folder called `Mail-attachments`. *Note: It's also possible to use a different folder name. Simply type the name of the folder you want to use when setting up the provider in Thunderbird* diff --git a/src/components/nsNextcloud.js b/src/components/nsNextcloud.js index 746b629..0b9f480 100644 --- a/src/components/nsNextcloud.js +++ b/src/components/nsNextcloud.js @@ -271,12 +271,22 @@ Nextcloud.prototype = { createExistingAccount: function nsNc_createExistingAccount (aRequestObserver) { // XXX: replace this with a better function let successCb = function () { + + let callbackCreateFolder = function (created) { + if (created) { + aRequestObserver.onStopRequest(null, this, Cr.NS_OK); + } + else { + aRequestObserver.onStopRequest(null, this, Ci.nsIMsgCloudFileProvider.authErr); + } + }.bind(this); + let folderExists = function (exists) { if (exists) { aRequestObserver.onStopRequest(null, this, Cr.NS_OK); } else { - aRequestObserver.onStopRequest(null, this, Ci.nsIMsgCloudFileProvider.authErr); + this._createFolder(callbackCreateFolder); } }.bind(this); this._checkFolderExists(folderExists); @@ -637,6 +647,38 @@ Nextcloud.prototype = { } }, + /** + * A private function which creates a folder entered + * in the settings screen on the server. + * + * @param callback callback function called with true or false as an argument + * @private + */ + _createFolder: function createFolder(callback) { + if (this._storageFolder !== '/') { + let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"] + .createInstance(Ci.nsIXMLHttpRequest); + + req.open("MKCOL", this._serverUrl + kWebDavPath + + ("/" + this._storageFolder + "/").replace(/\/+/g, '/'), true, this._userName, + this._password); + + req.onload = function () { + if (req.status === 201) { + return callback(true); + } + else { + return callback(false); + } + }.bind(this); + req.send(); + } + else { + return callback(false); + } + + }, + /** * A private function that first ensures that the user is logged in, and then * retrieves the user's profile information. -- cgit v1.2.3