rewrite checkMail to use imapProbe

This commit is contained in:
Girish Ramakrishnan 2016-06-23 22:06:36 -05:00
parent 150b65ae64
commit b66ad2882a
2 changed files with 13 additions and 62 deletions

View File

@ -6,7 +6,7 @@ var assert = require('assert'),
common = require('./common.js'),
debug = require('debug')('e2e:cloudron'),
dns = require('dns'),
Imap = require('imap'),
ImapProbe = require('./imap-probe.js'),
querystring = require('querystring'),
once = require('once'),
request = require('superagent-sync'),
@ -547,51 +547,21 @@ Cloudron.prototype.setDnsConfig = function (dnsConfig) {
};
Cloudron.prototype.checkMail = function (owner, callback) {
callback = once(callback);
var imap = new Imap({
var imap = new ImapProbe({
user: owner.username,
password: owner.password,
host: this._adminFqdn,
port: 993,
port: 993, // imap port
tls: true,
tlsOptions: {
rejectUnauthorized: false
}
tlsOptions: { rejectUnauthorized: false },
readOnly: true
});
// see mailer.sendMailToCloudronUser
imap.once('ready', function() {
imap.openBox('INBOX', false /* openReadOnly */, function (error, box) {
if (error) return callback(error);
if (box.messages.total !== 1) callback(new Error('Expecting one mail in inbox. Saw ' + box.messages.total));
var f = imap.seq.fetch('1:1', { bodies: [ 'TEXT' ] });
f.on('message', function (msg, seq) {
msg.on('body', function (stream, info) {
var buffer = '';
stream.on('data', function (chunk) { buffer += chunk.toString('utf8'); });
stream.on('end', function () {
imap.end();
if (buffer.indexOf('The release depends on you') !== -1) return callback();
callback(new Error('Failed to get message body: ' + buffer));
});
stream.on('error', callback);
});
});
f.on('end', function () { });
f.on('error', callback);
});
});
imap.once('error', callback);
imap.once('end', function () { });
imap.connect();
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) {

View File

@ -10,7 +10,6 @@ var AppStore = require('../appstore.js'),
Cloudron = require('../cloudron.js'),
common = require('../common.js'),
dnsSync = require('dns-sync'),
ImapProbe = require('../imap-probe.js'),
mailer = require('../mailer.js'),
sleep = require('sleep').sleep;
@ -26,7 +25,7 @@ describe('Cloudron backup testing', function () {
var owner = common.getOwner();
var admin = common.getAdmin();
var cloudron, appId, box, backupInfo, imap;
var cloudron, appId, box, backupInfo;
it('can login to the store', function () {
var accessToken = appStore.getAccessToken(owner);
@ -45,16 +44,6 @@ describe('Cloudron backup testing', function () {
});
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
imap = new ImapProbe({
user: common.getOwner().username,
password: common.getOwner().password,
host: cloudron.adminFqdn(),
port: 993, // imap port
tls: true,
tlsOptions: { rejectUnauthorized: false },
readOnly: true
});
});
it('can activate the box', function () {
@ -75,11 +64,7 @@ describe('Cloudron backup testing', function () {
});
it('can receive mail', function (done) {
imap.probe({
subject: new RegExp('^Hi from e2e test$'),
to: new RegExp(owner.username + '@' + box.domain),
body: /The release depends on you/
}, done);
cloudron.checkMail(owner, done);
});
var location = 'test' + (Math.random() * 10000).toFixed();
@ -122,11 +107,7 @@ describe('Cloudron backup testing', function () {
});
it('retains old mail', function (done) {
imap.probe({
subject: new RegExp('^Hi from e2e test$'),
to: new RegExp(owner.username + '@' + box.domain),
body: /The release depends on you/
}, done);
cloudron.checkMail(owner, done);
});
it('can check sieve script', function (done) {