Skip to content

Commit 1b3191e

Browse files
committed
Create a folder if the folder entered in the settings doesn't exist
1 parent a0f8dea commit 1b3191e

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ It is currently possible to upload files as large as 1GB.
3030
## Nextcloud configuration
3131

3232
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
33-
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
33+
1. By default your mail attachments will be saved in a folder called `Mail-attachments`.
3434

3535
*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*
3636

src/components/nsNextcloud.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,22 @@ Nextcloud.prototype = {
271271
createExistingAccount: function nsNc_createExistingAccount (aRequestObserver) {
272272
// XXX: replace this with a better function
273273
let successCb = function () {
274+
275+
let callbackCreateFolder = function (created) {
276+
if (created) {
277+
aRequestObserver.onStopRequest(null, this, Cr.NS_OK);
278+
}
279+
else {
280+
aRequestObserver.onStopRequest(null, this, Ci.nsIMsgCloudFileProvider.authErr);
281+
}
282+
}.bind(this);
283+
274284
let folderExists = function (exists) {
275285
if (exists) {
276286
aRequestObserver.onStopRequest(null, this, Cr.NS_OK);
277287
}
278288
else {
279-
aRequestObserver.onStopRequest(null, this, Ci.nsIMsgCloudFileProvider.authErr);
289+
this._createFolder(callbackCreateFolder);
280290
}
281291
}.bind(this);
282292
this._checkFolderExists(folderExists);
@@ -637,6 +647,38 @@ Nextcloud.prototype = {
637647
}
638648
},
639649

650+
/**
651+
* A private function which creates a folder entered
652+
* in the settings screen on the server.
653+
*
654+
* @param callback callback function called with true or false as an argument
655+
* @private
656+
*/
657+
_createFolder: function createFolder(callback) {
658+
if (this._storageFolder !== '/') {
659+
let req = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
660+
.createInstance(Ci.nsIXMLHttpRequest);
661+
662+
req.open("MKCOL", this._serverUrl + kWebDavPath +
663+
("/" + this._storageFolder + "/").replace(/\/+/g, '/'), true, this._userName,
664+
this._password);
665+
666+
req.onload = function () {
667+
if (req.status === 201) {
668+
return callback(true);
669+
}
670+
else {
671+
return callback(false);
672+
}
673+
}.bind(this);
674+
req.send();
675+
}
676+
else {
677+
return callback(false);
678+
}
679+
680+
},
681+
640682
/**
641683
* A private function that first ensures that the user is logged in, and then
642684
* retrieves the user's profile information.

0 commit comments

Comments
 (0)