Adds correct respect for contiunation responses following APPEND

fork
Andrew Jessup 13 years ago
parent 0b319c31a0
commit 189e4c4e4e

@ -414,7 +414,8 @@ ImapConnection.prototype.connect = function(loginCb) {
} }
} }
} }
} else if (data[0][0] === 'A') { // Tagged server response } else if (data[0][0] === 'A' ||
(data[0] === '+' && self._state.requests.length ) ) { // Tagged server response or continutation response
var sendBox = false; var sendBox = false;
clearTimeout(self._state.tmrKeepalive); clearTimeout(self._state.tmrKeepalive);
@ -427,7 +428,7 @@ ImapConnection.prototype.connect = function(loginCb) {
self._resetBox(); self._resetBox();
} }
} }
debugger;
if (self._state.requests[0].command.indexOf('RENAME') > -1) { if (self._state.requests[0].command.indexOf('RENAME') > -1) {
self._state.box.name = self._state.box._newName; self._state.box.name = self._state.box._newName;
delete self._state.box._newName; delete self._state.box._newName;
@ -438,7 +439,14 @@ ImapConnection.prototype.connect = function(loginCb) {
var err = null; var err = null;
var args = self._state.requests[0].args, var args = self._state.requests[0].args,
cmd = self._state.requests[0].command; cmd = self._state.requests[0].command;
if (data[1] !== 'OK') { if (data[0] === '+') {
if (cmd.indexOf('APPEND') !== 0) {
err = new Error('Unexpected continuation');
err.type = 'continuation';
err.request = cmd;
} else
return self._state.requests[0].callback();
} else if (data[1] !== 'OK') {
err = new Error('Error while executing request: ' + data[2]); err = new Error('Error while executing request: ' + data[2]);
err.type = data[1]; err.type = data[1];
err.request = cmd; err.request = cmd;
@ -466,6 +474,7 @@ ImapConnection.prototype.connect = function(loginCb) {
self.capabilities.indexOf('IDLE') > -1) { self.capabilities.indexOf('IDLE') > -1) {
// According to RFC 2177, we should re-IDLE at least every 29 // According to RFC 2177, we should re-IDLE at least every 29
// minutes to avoid disconnection by the server // minutes to avoid disconnection by the server
debugger;
self._send('IDLE', undefined, true); self._send('IDLE', undefined, true);
} }
self._state.tmrKeepalive = setTimeout(function() { self._state.tmrKeepalive = setTimeout(function() {
@ -639,17 +648,17 @@ ImapConnection.prototype.append = function(data, options, cb) {
cmd += ('0'+(-options.date.getTimezoneOffset() % 60)).slice(-2); cmd += ('0'+(-options.date.getTimezoneOffset() % 60)).slice(-2);
cmd += '"'; cmd += '"';
} }
if (data instanceof Buffer) { cmd += ' {';
cmd += ' {'+data.length+"}\r\n" cmd += (Buffer.isBuffer(data) ? data.length : Buffer.byteLength(data));
cmdbuf = new Buffer(Buffer.byteLength(cmd)+data.length); cmd += '}\r\n';
cmdbuf.write(cmd); var self = this, step = 1;
data.copy(cmdbuf, Buffer.byteLength(cmd)); this._send(cmd, function(err) {
this._send(cmdbuf, cb); if (err || step++ === 2)
} else { return cb(err);
cmd += ' {'+Buffer.byteLength(data.toString())+"}\r\n" self._state.conn.cleartext.write(data);
cmd += data.toString(); // Send the command+data as a string self._state.conn.cleartext.write(CRLF);
this._send(cmd, cb); debug('\n<<SENT>>: ' + util.inspect(data.toString()) + '\n');
} });
} }
ImapConnection.prototype.fetch = function(uids, options) { ImapConnection.prototype.fetch = function(uids, options) {
@ -976,12 +985,12 @@ ImapConnection.prototype._noop = function() {
if (this._state.status >= STATES.AUTH) if (this._state.status >= STATES.AUTH)
this._send('NOOP'); this._send('NOOP');
}; };
ImapConnection.prototype._send = function(cmdobj, cb, bypass) { ImapConnection.prototype._send = function(cmdstr, cb, bypass) {
if (typeof cmdobj !== 'undefined' && !bypass) if (typeof cmdstr !== 'undefined' && !bypass)
this._state.requests.push({ command: cmdobj, callback: cb, args: [] }); this._state.requests.push({ command: cmdstr, callback: cb, args: [] });
if ((typeof cmdobj === 'undefined' && this._state.requests.length) || if ((typeof cmdstr === 'undefined' && this._state.requests.length) ||
this._state.requests.length === 1 || bypass) { this._state.requests.length === 1 || bypass) {
var prefix = '', cmd = (bypass ? cmdobj : this._state.requests[0].command); var prefix = '', cmd = (bypass ? cmdstr : this._state.requests[0].command);
clearTimeout(this._state.tmrKeepalive); clearTimeout(this._state.tmrKeepalive);
if (this._state.ext.idle.sentIdle && cmd !== 'DONE') { if (this._state.ext.idle.sentIdle && cmd !== 'DONE') {
this._send('DONE', undefined, true); this._send('DONE', undefined, true);

Loading…
Cancel
Save