Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ function ImapConnection(server, stream) {
this.parser.on('end', this.clean.bind(this, false));
this.stream.on('error', function(e) {
c.stream._err = e;
if(e.code != 'ECONNRESET' && e.code != 'EPIPE') {
console.log('Unmanaged:', e, '\n', e.stack);
throw e;
if (e.code.indexOf('ECONNABORTED') > -1) {
console.error('Connection closed');
} else if(e.code.indexOf('ECONNRESET') === -1
&& e.code.indexOf('EPIPE') === -1) {
console.error('Unmanaged:', e, '\n', e.stack);
}
});
this.stream.on('close', this.clean.bind(this, true));
Expand Down Expand Up @@ -126,7 +128,7 @@ ImapConnection.prototype.onLine = function(line) {
this.close();
return;
}
if(this.state == States.NotAuthenticated) {
if(this.state === States.NotAuthenticated) {
switch(cmd) {
case 'STARTTLS':
this.callPlugins('starttls', [this, tag]);
Expand All @@ -152,7 +154,7 @@ ImapConnection.prototype.onLine = function(line) {
return;
}
}
if(this.state == States.Authenticated) {
if(this.state === States.Authenticated) {
switch(cmd) {
case 'EXAMINE':
case 'CREATE':
Expand Down Expand Up @@ -187,6 +189,32 @@ ImapConnection.prototype.onLine = function(line) {
return;
}
}
if(this.state === States.Selected) {
switch(cmd) {
case 'FETCH':
if (args.length >= 2) {
this.callPlugins('uid_fetch', [this, args], afterCommand.bind(this, tag));
} else {
this.send(tag, 'BAD', 'FETCH needs minimum 2 arguments');
}
case 'UID':
if (args.length > 0 && (''+ args[0]).toUpperCase() === 'FETCH') {
var sub_args = args.slice(1);
if (sub_args.length >= 2) {
this.callPlugins('uid_fetch', [this, sub_args], afterCommand.bind(this, tag));
} else {
this.send(tag, 'BAD', 'FETCH needs minimum 2 arguments');
}
} else {
console.log('Received command:', cmd, args);
this.send(tag, 'BAD', 'Command not implemented');
}
return;
default:
this.callPlugins('unknown_command', [this, cmd, args], afterCommand.bind(this, tag));
return;
}
}
};

function afterCommand(code, err, res, msg) {
Expand Down