ditesh/node-poplib — Issue #1: POP3Client.prototype.uidl - infinite loop
Author: nazar
Created: 2011-11-02 16:15:34+00:00
State: open

Hi Ditesh.

Thank you for the library.

I've encountered a situation where POP3Client.prototype.uidl get stuck in a loop.

```javascript
while(true) {

if ( (offset > endOffset) break;

newoffset = data.indexOf("\r\n", offset);
listitem = data.substr(offset, newoffset-offset);
listitem = listitem.split(" ");
returnValue[listitem[0]] = listitem[1];
offset = newoffset + 2;

}

```
the (offset > endOffSet) is never met as when the last item is added offset is smaller than endOffset.

I patched it as follows:

```javascript
while(true) {

if ( (offset > endOffset) || (newoffset == -1) ) break;

newoffset = data.indexOf("\r\n", offset);
listitem = data.substr(offset, newoffset-offset);
listitem = listitem.split(" ");
returnValue[listitem[0]] = listitem[1];
offset = newoffset + 2;

}

```
There might be a better way.

HTH