Open epinzur opened 9 years ago
Also, I'm not 100% sure my test assertions are correct, but they are at least close.
I'm not having an issue with the message body (though on my fetch I'm requesting just the TEXT), but I do also NOT receive the end
event from imap.end()
, the process just hangs or throws:
{ [Error: read ECONNRESET]
code: 'ECONNRESET',
errno: 'ECONNRESET',
syscall: 'read',
source: 'socket' }
@mscdex have you had time to look at this?
@rltvty Not yet unfortunately, I haven't forgotten about it though.
Somehow it's connected to the TLS and the two sockets. With listening on socket and this._sock to close/end events, it works for me, but surely this is not a real solution. https://github.com/mscdex/node-imap/blob/master/lib/Connection.js#L178
this._sock.once('close', function(had_err) {
clearTimeout(self._tmrConn);
clearTimeout(self._tmrAuth);
clearTimeout(self._tmrKeepalive);
self.state = 'disconnected';
self.debug && self.debug('[connection] Closed');
self.emit('close', had_err);
});
this._sock.once('end', function() {
clearTimeout(self._tmrConn);
clearTimeout(self._tmrAuth);
clearTimeout(self._tmrKeepalive);
self.state = 'disconnected';
self.debug && self.debug('[connection] Ended');
self.emit('end');
});
I'm seeing the same issue (attempting to parse two bodies at the same time). I've debugged it enough to know that Parser._resUntagged regex is picking up the latter BODY[1.MIME] {76} instead of the first BODY[1]. RE_BODYLITERAL is tested first, which why it picks up BODY[1.MIME] {76}. Otherwise parseFetch would have picked up the BODY[1](which it does via RE_BODYINLINEKEY regex).
Looking at the definition of RE_BODYINLINEKEY it looks like it expects that to be on a line by itself. I'm not familiar enough with the IMAP protocol to know if that's mandatory (and I can't make heads or tails out of the RFC). So I'm wondering if these are poorly formatted emails we're getting from the server?
@mscdex The following fixes the issue, but is it legit?
Parser.prototype._resUntagged = function() { var m = RE_BODYLITERAL.exec(this._buffer); var body = /BODY[(.*)] /i.exec(this._buffer)
if (m && (!body || m.index < body.index)) {
Seeing the same issue with the most recent version.
events.js:85
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at exports._errnoException (util.js:746:11)
at TCP.onread (net.js:550:26)
I've been tinkering around this issue and realized that you will get all the bodies
if you have a ''
added to your bodies
array, it should look something like this in the end:
var f = imap.fetch(6, { bodies: ['1', '1.MIME', '2', '2.MIME', ''], struct: true })
This worked for me, this issue has been open for a while
I'm seeing an issue on certain requests, where I'm not getting body events for bodies:
1
and1.MIME
, but I am getting body events for bodies2
and2.MIME
. Also no message-end event is fired.For now I've modified my code to fire the message event for any started messages when the fetch command ends, but I'd like to remove this, and be able to parse the missing data.
I created a test to reproduce this issue. I started debugging the code, and looking into a fix, but I'm not sure what the best approach will be.
I know that
Parser.prototype._resUntagged = function() {
is attempting to parse `... BODY[1] "Test!" BODY[1.MIME] {76}...``` as a single piece instead of two.Please let me know of any questions.
Here is the test I made: