Skip to content

Commit 9dcc149

Browse files
authored
Merge pull request emailjs#159 from gudmundurg74/values-as-uint8arrays
Values as uint8arrays
2 parents cb47736 + 3bf782a commit 9dcc149

File tree

6 files changed

+45
-2
lines changed

6 files changed

+45
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ Where
312312
* **options** is an optional options object
313313
* **byUid** if `true` executes `UID FETCH` instead of `FETCH`
314314
* **changedSince** is the modseq filter. Only messages with higher modseq value will be returned
315+
* **valueAsString** LITERAL and STRING values are returned as strings rather than Uint8Array objects. Defaults to true.
315316

316317
Resolves with
317318

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"main": "src/emailjs-imap-client",
2222
"dependencies": {
2323
"emailjs-addressparser": "^1.0.1",
24-
"emailjs-imap-handler": "^2.0.0",
24+
"emailjs-imap-handler": "^2.1.0",
2525
"emailjs-mime-codec": "^1.0.1",
2626
"emailjs-tcp-socket": "^1.0.1",
2727
"emailjs-utf7": "^3.0.1"

src/emailjs-imap-client-imap.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@
560560

561561
var response;
562562
try {
563-
response = imapHandler.parser(command);
563+
const valueAsString = this._currentCommand.request && this._currentCommand.request.valueAsString;
564+
response = imapHandler.parser(command, { valueAsString });
564565
this.logger.debug('S:', () => imapHandler.compiler(response, false, true));
565566
} catch (e) {
566567
this.logger.error('Error parsing imap command!', response);

src/emailjs-imap-client.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,11 @@
10951095
value: sequence
10961096
}]
10971097
};
1098+
1099+
if (options.valueAsString !== undefined) {
1100+
command.valueAsString = options.valueAsString;
1101+
}
1102+
10981103
var query = [];
10991104

11001105
items.forEach((item) => {

test/unit/emailjs-imap-client-imap-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,27 @@
516516
client._clientQueue[0].callback({});
517517
}, 0);
518518
});
519+
520+
it('should store valueAsString option in the command', (done) => {
521+
sinon.stub(client, '_sendRequest');
522+
523+
client._tagCounter = 100;
524+
client._clientQueue = [];
525+
client._canSend = false;
526+
527+
client.enqueueCommand({
528+
command: 'abc',
529+
valueAsString: false
530+
}, ['def'], {
531+
t: 1
532+
}).then(() => {
533+
expect(client._clientQueue[0].request.valueAsString).to.equal(false);
534+
}).then(done).catch(done);
535+
536+
setTimeout(() => {
537+
client._clientQueue[0].callback({});
538+
}, 0);
539+
});
519540
});
520541

521542
describe('#_sendRequest', () => {

test/unit/emailjs-imap-client-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,21 @@
14471447
}]
14481448
});
14491449
});
1450+
1451+
it('should build FETCH with the valueAsString option', () => {
1452+
expect(br._buildFETCHCommand('1:*', ['body[]'], {valueAsString: false})).to.deep.equal({
1453+
command: 'FETCH',
1454+
attributes: [{
1455+
type: 'SEQUENCE',
1456+
value: '1:*'
1457+
}, {
1458+
type: 'ATOM',
1459+
value: 'BODY',
1460+
section: []
1461+
}],
1462+
valueAsString: false
1463+
});
1464+
});
14501465
});
14511466

14521467
describe('#_parseFETCH', () => {

0 commit comments

Comments
 (0)