Skip to content

Commit 18bfbba

Browse files
drauschenbachForbesLindesay
authored andcommitted
Fixes #3. Fix detection of synchronized literal, so that literal event is emitted as advertised. (#4)
1 parent d06cd01 commit 18bfbba

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ IMAPLineParser.prototype._transform = function(chunk, encoding, callback){
7676
if (match = /^\{(\d+)(\+)?\}$/.exec(this.currentNode.value)) {
7777
this._expectedLiteral = Number(match[1])
7878
this.currentNode.value = ''
79-
if (!match[1]) {
79+
if (!match[2]) {
8080
this._synchronizing = true
8181
process.nextTick(this.emit.bind(this, 'literal'))
8282
} else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imap-parser",
3-
"version": "0.0.1",
3+
"version": "0.0.2-prerelease",
44
"description": "A parser for IMAP line based commands",
55
"main": "index.js",
66
"directories": {

test/index.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('types', function () {
4343
})
4444
lp.end('TAG1 "UID FETCH"\r\n')
4545
})
46-
it('parses string literal', function (done) {
46+
it('parses synchronizing string literal', function (done) {
4747
var lp = new Parser()
4848
lp.on('data', function (data) {
4949
assert.deepEqual(data, ['TAG1', 'ABC DEF\r\nGHI JKL', 'TAG2'])
@@ -53,6 +53,16 @@ describe('types', function () {
5353
lp.write('ABC DEF\r\nGHI JKL')
5454
lp.end('"TAG2"\r\n')
5555
})
56+
it('parses non-synchronizing string literal', function (done) {
57+
var lp = new Parser()
58+
lp.on('data', function (data) {
59+
assert.deepEqual(data, ['TAG1', 'ABC DEF\r\nGHI JKL', 'TAG2'])
60+
done()
61+
})
62+
lp.write('TAG1 {16+}\r\n')
63+
lp.write('ABC DEF\r\nGHI JKL')
64+
lp.end('"TAG2"\r\n')
65+
})
5666
it('parses NIL value', function (done) {
5767
var lp = new Parser()
5868
lp.on('data', function (data) {
@@ -130,7 +140,7 @@ describe('structure', function () {
130140
})
131141
})
132142

133-
describe('logging', function () {
143+
describe('events', function () {
134144
it('emits a log event for each line', function (done) {
135145
var lp = new Parser()
136146
lp.on('log', function (data) {
@@ -140,4 +150,11 @@ describe('logging', function () {
140150
lp.write('TAG1 ')
141151
lp.end('FETCH (NAME HEADER BODY)\r\n')
142152
})
153+
it('emits a literal event after a synchronizing literal is received', function (done) {
154+
var lp = new Parser()
155+
lp.on('literal', function () {
156+
done()
157+
})
158+
lp.end('TAG1 {16}\r\n')
159+
})
143160
})

0 commit comments

Comments
 (0)