Check for 'SORT' capability in _sort(). Fix style and wording.

fork
Chotiwat Chawannakul 12 years ago
parent 6ef3ae2141
commit 26be70afba

@ -789,22 +789,24 @@ ImapConnection.prototype._sort = function(which, sorts, options, cb) {
if (this._state.status !== STATES.BOXSELECTED)
throw new Error('No mailbox is currently selected');
if (!Array.isArray(sorts) || !sorts.length)
throw new Error('Expected array with at least on criterion for sort criteria');
throw new Error('Expected array with at least one sort criteria');
if (!Array.isArray(options))
throw new Error('Expected array for search options');
if (!this._serverSupports('SORT'))
return cb(new Error('Sorting is not supported on the server'));
var criteria = sorts.map(function(criterion) {
if(typeof criterion !== 'string')
if (typeof criterion !== 'string')
throw new Error('Unexpected sort criterion data type. '
+ 'Expected string. Got: ' + typeof criteria);
var modifier = '';
if(criterion.charAt(0) === '!') {
if (criterion.charAt(0) === '!') {
modifier = 'REVERSE ';
criterion = criterion.substring(1);
}
criterion = criterion.toUpperCase();
switch(criterion) {
switch (criterion) {
case 'ARRIVAL':
case 'CC':
case 'DATE':
@ -814,7 +816,7 @@ ImapConnection.prototype._sort = function(which, sorts, options, cb) {
case 'TO':
break;
default:
throw new Error('Unexpected sort criterion: ' + criterion);
throw new Error('Unexpected sort criteria: ' + criterion);
}
return modifier + criterion;

Loading…
Cancel
Save