Beispiel #1
0
MailParser.prototype._finalizeContents = function() {
    var streamInfo;

    if (this._currentNode.content) {

        if (!this._currentNode.attachment) {
            if(this._currentNode.meta.charset === 'iso-8859-8-i'){
                this._currentNode.meta.charset = 'iso-8859-8'
            }
            if (this._currentNode.meta.contentType == "text/html" && !this._currentNode.meta.charset) {
                this._currentNode.meta.charset = this._detectHTMLCharset(this._currentNode.content) || this.options.defaultCharset || "iso-8859-1";
            }

            if (this._currentNode.meta.transferEncoding == "quoted-printable") {
                this._currentNode.content = mimelib.decodeQuotedPrintable(this._currentNode.content, false, this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1");
                if (this._currentNode.meta.textFormat == "flowed") {
                    if (this._currentNode.meta.textDelSp == "yes") {
                        this._currentNode.content = this._currentNode.content.replace(/(^|\n)-- \n/g, '$1-- \u0000').replace(/ \n/g, '').replace(/(^|\n)-- \u0000/g, '$1-- \n');
                    } else {
                        this._currentNode.content = this._currentNode.content.replace(/(^|\n)-- \n/g, '$1-- \u0000').replace(/ \n/g, ' ').replace(/(^|\n)-- \u0000/g, '$1-- \n');
                    }
                }
            } else if (this._currentNode.meta.transferEncoding == "base64") {
                this._currentNode.content = mimelib.decodeBase64(this._currentNode.content, this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1");
            } else {
                this._currentNode.content = this._convertStringToUTF8(this._currentNode.content);
            }
        } else {
            if (this._currentNode.meta.transferEncoding == "quoted-printable") {
                this._currentNode.content = mimelib.decodeQuotedPrintable(this._currentNode.content, false, "binary");
            } else if (this._currentNode.meta.transferEncoding == "base64") {

                // WTF? if newlines are not removed, the resulting hash is *always* different
                this._currentNode.content = new Buffer(this._currentNode.content.toString().replace(/\s+/g, ""), "base64");

            } else if (this._currentNode.meta.transferEncoding == "uuencode") {
                var uuestream = new Streams.UUEStream("binary");
                this._currentNode.content = uuestream.decode(new Buffer(this._currentNode.content, "binary"));
            } else {
                this._currentNode.content = new Buffer(this._currentNode.content, "binary");
            }
            this._currentNode.checksum = crypto.createHash("md5");
            this._currentNode.checksum.update(this._currentNode.content);
            this._currentNode.meta.checksum = this._currentNode.checksum.digest("hex");
            this._currentNode.meta.length = this._currentNode.content.length;
        }

    }

    if (this._currentNode.stream) {
        streamInfo = this._currentNode.stream.end() || {};
        if (streamInfo.checksum) {
            this._currentNode.meta.checksum = streamInfo.checksum;
        }
        if (streamInfo.length) {
            this._currentNode.meta.length = streamInfo.length;
        }
    }
};
    this.is_an_autoresponse = function() {
		var matches = this.head_hash['Subject'].match(/^=\?utf-8\?B\?(.*?)\?=/);
        if (matches)
            subj = mimelib.decodeBase64(matches[1]);
        else
            subj = this.head_hash['Subject'];
        for (var i = 0; i < this.autorespondlist.length; ++i) {
			var a = this.autorespondlist[i];
            if (subj.match(new RegExp("/"+a+"/", "i"))) {
//echo "a , subj"; exit;
                this.autoresponse = this.head_hash['Subject'];
                return true;
            }
        }
        return false;
    }
Beispiel #3
0
MailParser.prototype._finalizeContents = function(){
    var streamInfo;

    if(this._currentNode.content){
        
        if(!this._currentNode.attachment){
            
            if(this._currentNode.meta.contentType == "text/html"){
                 this._currentNode.meta.charset = this._detectHTMLCharset(this._currentNode.content) || this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1";
            }
            
            if(this._currentNode.meta.transferEncoding == "quoted-printable"){
                this._currentNode.content = mimelib.decodeQuotedPrintable(this._currentNode.content, false, this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1");
            }else if(this._currentNode.meta.transferEncoding == "base64"){
                this._currentNode.content = mimelib.decodeBase64(this._currentNode.content, this._currentNode.meta.charset || this.options.defaultCharset || "iso-8859-1");
            }else{
                this._currentNode.content = this._encodeString(this._currentNode.content);
            }
        }else{
            if(this._currentNode.meta.transferEncoding == "quoted-printable"){
                this._currentNode.content = mimelib.decodeQuotedPrintable(this._currentNode.content, false, "binary");
            }else if(this._currentNode.meta.transferEncoding == "base64"){
                this._currentNode.content = new Buffer(this._currentNode.content.replace(/[^\w\+\/=]/g,''), "base64");
            }else{
                this._currentNode.content = new Buffer(this._currentNode.content, "binary");
            }
            this._currentNode.checksum.update(this._currentNode.content);
            this._currentNode.meta.checksum = this._currentNode.checksum.digest("hex");
            this._currentNode.meta.length = this._currentNode.content.length;
        }
        
    }

    if(this._currentNode.stream){
        streamInfo = this._currentNode.stream.end() || {};
        if(streamInfo.checksum){
            this._currentNode.meta.checksum = streamInfo.checksum;
        }
        if(streamInfo.length){
            this._currentNode.meta.length = streamInfo.length;
        }
    }
};