How to use the mailsplit.Headers function in mailsplit

To help you get started, we’ve selected a few mailsplit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github forwardemail / free-email-forwarding / helpers / message-splitter.js View on Github external
this.headerBytes += headerPos;
          break;
        } else if (pr1 === 0x0d && pr2 === 0x0a) {
          this.headersParsed = true;
          headerPos = i - lblen + 1;
          this.headerBytes += headerPos;
          break;
        }
      }
    }

    if (this.headersParsed) {
      this.headerChunks.push(data.slice(0, headerPos));
      this.rawHeaders = Buffer.concat(this.headerChunks, this.headerBytes);
      this.headerChunks = null;
      this.headers = new Headers(this.rawHeaders);
      this.emit('headers', this.headers);
      if (data.length - 1 > headerPos) {
        const chunk = data.slice(headerPos);
        // this would be the first chunk of data sent downstream
        // from now on we keep header and body separated until final delivery
        setImmediate(() => this.push(chunk));
      }

      return false;
    }

    this.headerBytes += data.length;
    this.headerChunks.push(data);

    // store last 4 bytes to catch header break
    this._updateLastBytes(data);
github forwardemail / free-email-forwarding / helpers / message-splitter.js View on Github external
_flush(callback) {
    if (this.headerChunks) {
      // all chunks are checked but we did not find where the body starts
      // so emit all we got as headers and push empty line as body
      this.headersParsed = true;
      // add header terminator
      this.headerChunks.push(Buffer.from('\r\n\r\n'));
      this.headerBytes += 4;
      // join all chunks into a header block
      this.rawHeaders = Buffer.concat(this.headerChunks, this.headerBytes);

      this.headers = new Headers(this.rawHeaders);

      this.emit('headers', this.headers);
      this.headerChunks = null;

      // this is our body
      this.push(Buffer.from('\r\n'));
    }

    callback();
  }
}
github zone-eu / zmta-webadmin / routes / index.js View on Github external
message.meta = message.meta || {};
                message.headers = message.headers || [];

                let time = (typeof message.meta.time === 'number' && message.meta.time) || Date.now();

                message.logId = id;
                message.logSeq = seq;
                message.seqTo = seqTo;
                message.logEntries = logEntries;
                message.created = new Date(time).toISOString();

                if (message.meta.expiresAfter) {
                    message.meta.expiresAfter = new Date(message.meta.expiresAfter).toISOString();
                }

                let headers = new mailsplit.Headers(message.meta.headers || []);
                message.subject = headers.getFirst('subject');
                try {
                    message.subject = libmime.decodeWords(message.subject);
                } catch (E) {
                    // ignore
                }

                if (message.meta.spam && message.meta.spam.default) {
                    message.spamStatus = true;
                    switch (message.meta.spam.default.action) {
                        case 'no action':
                            message.spamLabel = 'success';
                            message.spamText = 'Clean';
                            break;
                        case 'reject':
                            message.spamLabel = 'danger';

mailsplit

Split email messages into an object stream

(MIT OR EUPL-1.1+)
Latest version published 1 year ago

Package Health Score

62 / 100
Full package analysis

Popular mailsplit functions

Similar packages