From 69fc2408b4c69f68c0efae812d960fe75587e023 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Fri, 24 Jun 2016 00:29:34 -0500 Subject: [PATCH] send mail from one user to another --- cloudron.js | 45 ++++++++++++++++++++---------------- test/cloudron-backup-test.js | 4 ++-- test/cloudron-user-test.js | 8 +++++++ 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/cloudron.js b/cloudron.js index d3aac0f..7b726d6 100644 --- a/cloudron.js +++ b/cloudron.js @@ -33,6 +33,10 @@ function Cloudron(box) { }; } +Cloudron.prototype.fqdn = function () { + return this._box.domain; +}; + Cloudron.prototype.adminFqdn = function () { return 'my' + (this._isCustomDomain ? '.' : '-') + this._box.domain; }; @@ -548,24 +552,6 @@ Cloudron.prototype.setDnsConfig = function (dnsConfig) { common.verifyResponse2xx(res, 'Could not set dns config'); }; -Cloudron.prototype.checkMail = function (owner, callback) { - var imap = new ImapProbe({ - user: owner.username, - password: owner.password, - host: this._adminFqdn, - port: 993, // imap port - tls: true, - tlsOptions: { rejectUnauthorized: false }, - readOnly: true - }); - - imap.probe({ - subject: new RegExp('^Hi from e2e test$'), - to: new RegExp(owner.username + '@' + this._box.domain), - body: /The release depends on you/ - }, callback); -}; - Cloudron.prototype.saveSieveScript = function (owner, callback) { var authString = 'AUTHENTICATE "PLAIN" "' + new Buffer('\0' + owner.username + '\0' + owner.password).toString('base64') + '"'; var data = ''; @@ -641,9 +627,28 @@ Cloudron.prototype.sendMail = function (owner, to, callback) { var mailOptions = { from: owner.username + '@'+ this._box.domain, to: to, - subject: 'Hello from e2e test', - text: 'The release depends on you' + subject: 'Hi from e2e test - ' + this._box.domain, + text: 'This release depends on you' }; transport.sendMail(mailOptions, callback); }; + +Cloudron.prototype.checkMail = function (owner, callback) { + var imap = new ImapProbe({ + user: owner.username, + password: owner.password, + host: this._adminFqdn, + port: 993, // imap port + tls: true, + tlsOptions: { rejectUnauthorized: false }, + readOnly: true + }); + + imap.probe({ + subject: new RegExp('^Hi from e2e test - ' + this._box.domain + '$'), + to: new RegExp(owner.username + '@' + this._box.domain), + body: /This release depends on you/ + }, callback); +}; + diff --git a/test/cloudron-backup-test.js b/test/cloudron-backup-test.js index ff5954f..46c483d 100644 --- a/test/cloudron-backup-test.js +++ b/test/cloudron-backup-test.js @@ -83,8 +83,8 @@ describe('Cloudron backup testing', function () { it('sent mail successfully', function (done) { imap.probe({ - subject: new RegExp('^Hello from e2e test$'), - body: /The release depends on you/ + subject: new RegExp('^Hi from e2e test$'), + body: /This release depends on you/ }, done); }); diff --git a/test/cloudron-user-test.js b/test/cloudron-user-test.js index 5cc2e4b..ddfc8ef 100644 --- a/test/cloudron-user-test.js +++ b/test/cloudron-user-test.js @@ -84,6 +84,14 @@ describe('Cloudron user creation testing', function () { cloudron.getOauthToken({ username: 'newuser', password: 'Strong?132' }); }); + it('can send mail from one user to another', function (done) { + cloudron.sendMail(owner, 'newuser@' + cloudron.fqdn(), done); + }); + + it('can receive mail', function (done) { + cloudron.checkMail({ username: 'newuser', password: 'Strong?132' }, done); + }); + it('can delete the cloudron', function () { appStore.deleteCloudron(box); });