|
|
|
@ -10,7 +10,7 @@ var CR = 13,
|
|
|
|
|
COLON = 58,
|
|
|
|
|
SPACE = 32,
|
|
|
|
|
TAB = 9,
|
|
|
|
|
RE_FOLD = /\r\n\s+/g;
|
|
|
|
|
REGEXP_FOLD = /\r\n\s+/g;
|
|
|
|
|
|
|
|
|
|
var MIMEParser = module.exports = function() {
|
|
|
|
|
this._state = PARSE_HEADER_NAME;
|
|
|
|
@ -19,8 +19,9 @@ var MIMEParser = module.exports = function() {
|
|
|
|
|
this._sawCR = false;
|
|
|
|
|
this._sawLF = false;
|
|
|
|
|
this._needUnfold = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
inherits(MIMEParser, EventEmitter);
|
|
|
|
|
|
|
|
|
|
MIMEParser.prototype.execute = function(b, start, end) {
|
|
|
|
|
if (this._state == PARSE_BODY) {
|
|
|
|
|
var chunk;
|
|
|
|
@ -96,7 +97,7 @@ MIMEParser.prototype.execute = function(b, start, end) {
|
|
|
|
|
else if (finished) {
|
|
|
|
|
this._hdrval += b.toString('ascii', start, (i < end ? i - 2 : end));
|
|
|
|
|
if (this._needUnfold)
|
|
|
|
|
this._hdrval = this._hdrval.replace(RE_FOLD, ' ');
|
|
|
|
|
this._hdrval = this._hdrval.replace(REGEXP_FOLD, ' ');
|
|
|
|
|
this.emit('header', this._hdrname, this._hdrval.trim());
|
|
|
|
|
this._hdrname = '';
|
|
|
|
|
this._hdrval = '';
|
|
|
|
@ -111,6 +112,7 @@ MIMEParser.prototype.execute = function(b, start, end) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MIMEParser.prototype.finish = function() {
|
|
|
|
|
this._state = PARSE_HEADER_NAME;
|
|
|
|
|
this._hdrname = '';
|
|
|
|
|