Fix retrieval of utf8-encoded message bodies and fetching of only message structures.

fork
Brian White 14 years ago
parent 92e91ca3c1
commit cbeb2b95c6

@ -130,24 +130,24 @@ ImapConnection.prototype.connect = function(loginCb) {
if (self._state.curExpected > 0) { if (self._state.curExpected > 0) {
var extra = '', curReq = self._state.requests[0]; var extra = '', curReq = self._state.requests[0];
if (!curReq._done) { if (!curReq._done) {
self._state.curXferred += data.length; self._state.curXferred += Buffer.byteLength(data, 'utf8');
if (self._state.curXferred <= self._state.curExpected) { if (self._state.curXferred <= self._state.curExpected) {
if (curReq._msgtype === 'headers') if (curReq._msgtype === 'headers')
// buffer headers since they're generally not large and need to be // buffer headers since they're generally not large and are
// processed anyway // processed anyway
self._state.curData += data; self._state.curData += data;
else else
curReq._msg.emit('data', data); curReq._msg.emit('data', data);
return; return;
} }
var pos = data.length-(self._state.curXferred-self._state.curExpected); var pos = Buffer.byteLength(data, 'utf8')-(self._state.curXferred-self._state.curExpected);
extra = data.substr(pos); extra = (new Buffer(data)).slice(pos).toString('utf8');
if (pos > 0) { if (pos > 0) {
if (curReq._msgtype === 'headers') { if (curReq._msgtype === 'headers') {
self._state.curData += data.substr(0, pos); self._state.curData += (new Buffer(data)).slice(0, pos).toString('utf8');
curReq._msgheaders = self._state.curData; curReq._msgheaders = self._state.curData;
} else } else
curReq._msg.emit('data', data.substr(0, pos)); curReq._msg.emit('data', (new Buffer(data)).slice(0, pos).toString('utf8'));
} }
self._state.curData = ''; self._state.curData = '';
data = extra; data = extra;
@ -320,6 +320,15 @@ ImapConnection.prototype.connect = function(loginCb) {
if (self._state.box.messages.total > 0) if (self._state.box.messages.total > 0)
self._state.box.messages.total--; self._state.box.messages.total--;
break; break;
default:
if (/^FETCH/.test(data[2])) { // fetches without header or body (part) retrievals
var curReq = self._state.requests[0],
msg = new ImapMessage();
parseFetch(data[2].substring(data[2].indexOf("(")+1, data[2].lastIndexOf(")")), "", msg);
curReq._fetcher.emit('message', msg);
msg.emit('end');
}
break;
} }
} }
} }

Loading…
Cancel
Save