-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
46 lines (44 loc) · 1.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var net = require('net')
var Parser = require('imap-parser')
net.createServer(function (connection) {
function write(str) {
console.log('S: ' + JSON.stringify(str))
connection.write(str + '\r\n')
}
connection
.pipe(new Parser())
.on('data', function (data) {
function done(status, message) {
write(data[0] + ' ' + (status || 'OK') + ' ' + data[1] + ' ' + (message || 'completed'))
}
var command = data[1].toUpperCase()
switch (command) {
case 'CAPABILITY':
write('* CAPABILITY IMAP4rev1')
done()
break
case 'LOGIN':
var user = data[2]
var pass = data[3]
console.log('login(' + JSON.stringify(user) + ', ' + JSON.stringify(pass) + ')')
done()
break
case 'LOGOUT':
write('* BYE')
done()
break
case 'LSUB':
done()
default:
console.dir(data)
break
}
})
.on('log', function (data) {
console.log('C: ' + JSON.stringify(data))
})
write('* OK IMAP4rev1 Service Ready')
connection.on('end', function () {
console.log('CLOSED')
})
}).listen(143)