Skip to content

Commit

Permalink
private fields
Browse files Browse the repository at this point in the history
  • Loading branch information
lbuchs committed Mar 15, 2023
1 parent 70e61ba commit 3d5a909
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 63 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/npm-publish-github-packages.yml

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ check https://raw.githack.com/netas-ch/eml-parser/main/_test/test.html for a dem
console.log(email.getCc());
console.log(email.getTo());
console.log(email.getReplyTo());
console.log(email.getAttachments());

# license
Copyright © 2023 Netas AG - MIT license
14 changes: 0 additions & 14 deletions package.json

This file was deleted.

30 changes: 17 additions & 13 deletions src/EmlReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,47 @@ import {MultiPartParser} from './MultiPartParser.js';
export class EmlReader {

/**
* @param {ArrayBuffer|Uint8Array} rawContent
* @param {ArrayBuffer|Uint8Array} arrayBuffer
* @returns {EmlReader}
*/
constructor(arrayBuffer) {
this._multipartParser = new MultiPartParser(arrayBuffer);
this.#multipartParser = new MultiPartParser(arrayBuffer);
}

getDate() {
let date = this._multipartParser.getHeader('date');
let date = this.#multipartParser.getHeader('date');
if (date) {
return new Date(date);
}
return null;
}

getSubject() {
return this._multipartParser.getHeader('subject', true, true);
return this.#multipartParser.getHeader('subject', true, true);
}

getFrom() {
return this._multipartParser.getHeader('from', true, true);
return this.#multipartParser.getHeader('from', true, true);
}

getCc() {
return this._multipartParser.getHeader('cc', true, true);
return this.#multipartParser.getHeader('cc', true, true);
}

getTo() {
return this._multipartParser.getHeader('to', true, true);
return this.#multipartParser.getHeader('to', true, true);
}

getReplyTo() {
return this._multipartParser.getHeader('reply-to', true, true);
return this.#multipartParser.getHeader('reply-to', true, true);
}

getHeader(key, decode=false, removeLineBreaks=false) {
return this.#multipartParser.getHeader(key, decode, removeLineBreaks);
}

getAttachments() {
let attachments=[], mixedPart = this._multipartParser.getPartByContentType('multipart', 'mixed');
let attachments=[], mixedPart = this.#multipartParser.getPartByContentType('multipart', 'mixed');

if (mixedPart) {
for (const subPart of mixedPart.getMultiParts()) {
Expand All @@ -64,13 +68,13 @@ export class EmlReader {
}

getMessageText() {
let text = this._multipartParser.getPartByContentType('text', 'plain');
let text = this.#multipartParser.getPartByContentType('text', 'plain');
if (text && !text.isAttachment) {
return text.getBody();
}

// HTML to text
let html = this._multipartParser.getPartByContentType('text', 'html');
let html = this.#multipartParser.getPartByContentType('text', 'html');
if (html && !html.isAttachment) {
let htmlStr = html.getBody(), hIndex = htmlStr.indexOf('<body');
if (hIndex !== -1) {
Expand All @@ -87,13 +91,13 @@ export class EmlReader {
}

getMessageHtml() {
let html = this._multipartParser.getPartByContentType('text', 'html');
let html = this.#multipartParser.getPartByContentType('text', 'html');
if (html && !html.isAttachment) {
return html.getBody();
}

// text to html
let text = this._multipartParser.getPartByContentType('text', 'plain');
let text = this.#multipartParser.getPartByContentType('text', 'plain');
if (text && !text.isAttachment) {
return text.getBody().replace(/\r?\n/g, '<br />');
}
Expand Down

0 comments on commit 3d5a909

Please sign in to comment.