VulpesOS/gaia/apps/email/js/ext/imap/protocol/snippetparser.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

45 lines
1,013 B
JavaScript
Executable file

define(['./textparser'], function($textparser) {
var TextParser = $textparser.TextParser;
function bufferAppend(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
tmp.set(new Uint8Array(buffer1), 0);
tmp.set(new Uint8Array(buffer2), buffer1.byteLength);
return tmp.buffer;
};
/**
* Wrapper around the textparser, accumulates buffer content and returns it as
* part of the .complete step.
*/
function SnippetParser(partDef) {
TextParser.apply(this, arguments);
}
SnippetParser.prototype = {
parse: function(buffer) {
if (!this._buffer) {
this._buffer = buffer;
} else {
this._buffer = bufferAppend(this._buffer, buffer);
}
// do some magic parsing
TextParser.prototype.parse.apply(this, arguments);
},
complete: function() {
var content =
TextParser.prototype.complete.apply(this, arguments);
content.buffer = this._buffer;
return content;
}
};
return {
SnippetParser: SnippetParser
};
});