Skip to content

Commit

Permalink
fixed type import issues
Browse files Browse the repository at this point in the history
dependencies updated
  • Loading branch information
muratgozel committed Feb 11, 2024
1 parent 4129dd5 commit 5c42ad9
Show file tree
Hide file tree
Showing 84 changed files with 5,476 additions and 15,576 deletions.
54 changes: 29 additions & 25 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,40 @@
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"extends": "standard-with-typescript",
"overrides": [
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
"@typescript-eslint/non-nullable-type-assertion-style": "off",
"@typescript-eslint/strict-boolean-expressions": "off",
"no-undef-init": "off",
"@typescript-eslint/method-signature-style": "off",
"indent": "off",
"@typescript-eslint/indent": ["error", 4, {
"SwitchCase": 1,
"VariableDeclarator": 1,
"outerIIFEBody": 1,
"MemberExpression": 1,
"FunctionDeclaration": { "parameters": 1, "body": 1 },
"FunctionExpression": { "parameters": 1, "body": 1 },
"CallExpression": { "arguments": 1 },
"ArrayExpression": 1,
"ObjectExpression": 1,
"ImportDeclaration": 1,
"flatTernaryExpressions": false,
"ignoreComments": false,
"ignoredNodes": [
"TemplateLiteral *", "JSXElement", "JSXElement > *", "JSXAttribute", "JSXIdentifier",
"JSXNamespacedName", "JSXMemberExpression", "JSXSpreadAttribute", "JSXExpressionContainer",
"JSXOpeningElement", "JSXClosingElement", "JSXFragment", "JSXOpeningFragment",
"JSXClosingFragment", "JSXText", "JSXEmptyExpression", "JSXSpreadChild"],
"offsetTernaryExpressions": true
}]
}
}
}
158 changes: 83 additions & 75 deletions build/MIMEMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ export class MIMEMessage {
const lines = this.headers.dump();
const plaintext = this.getMessageByType('text/plain');
const html = this.getMessageByType('text/html');
const primaryMessage = html ? html : plaintext ? plaintext : undefined;
const primaryMessage = html ?? (plaintext ?? undefined);
if (primaryMessage === undefined) {
throw new MIMETextError('MIMETEXT_MISSING_BODY', 'No content added to the message.');
}
const hasAttachments = this.hasAttachments();
const hasInlineAttachments = this.hasInlineAttachments();
const structure = hasInlineAttachments && hasAttachments ? 'mixed+related'
: hasAttachments ? 'mixed'
: hasInlineAttachments ? 'related'
: plaintext && html ? 'alternative'
const structure = hasInlineAttachments && hasAttachments
? 'mixed+related'
: hasAttachments
? 'mixed'
: hasInlineAttachments
? 'related'
: plaintext && html
? 'alternative'
: '';
if (structure === 'mixed+related') {
const attachments = this.getAttachments()
Expand All @@ -40,52 +44,52 @@ export class MIMEMessage {
.map((a) => '--' + this.boundaries.related + eol + a.dump() + eol + eol)
.join('')
.slice(0, -1 * eol.length);
return lines + eol
+ 'Content-Type: multipart/mixed; boundary=' + this.boundaries.mixed + eol
+ eol
+ '--' + this.boundaries.mixed + eol
+ 'Content-Type: multipart/related; boundary=' + this.boundaries.related + eol
+ eol
+ this.dumpTextContent(plaintext, html, this.boundaries.related) + eol
+ eol
+ inlineAttachments
+ '--' + this.boundaries.related + '--' + eol
+ attachments
+ '--' + this.boundaries.mixed + '--';
return lines + eol +
'Content-Type: multipart/mixed; boundary=' + this.boundaries.mixed + eol +
eol +
'--' + this.boundaries.mixed + eol +
'Content-Type: multipart/related; boundary=' + this.boundaries.related + eol +
eol +
this.dumpTextContent(plaintext, html, this.boundaries.related) + eol +
eol +
inlineAttachments +
'--' + this.boundaries.related + '--' + eol +
attachments +
'--' + this.boundaries.mixed + '--';
}
else if (structure === 'mixed') {
const attachments = this.getAttachments()
.map((a) => '--' + this.boundaries.mixed + eol + a.dump() + eol + eol)
.join('')
.slice(0, -1 * eol.length);
return lines + eol
+ 'Content-Type: multipart/mixed; boundary=' + this.boundaries.mixed + eol
+ eol
+ this.dumpTextContent(plaintext, html, this.boundaries.mixed) + eol
+ (plaintext && html ? '' : eol)
+ attachments
+ '--' + this.boundaries.mixed + '--';
return lines + eol +
'Content-Type: multipart/mixed; boundary=' + this.boundaries.mixed + eol +
eol +
this.dumpTextContent(plaintext, html, this.boundaries.mixed) + eol +
(plaintext && html ? '' : eol) +
attachments +
'--' + this.boundaries.mixed + '--';
}
else if (structure === 'related') {
const inlineAttachments = this.getInlineAttachments()
.map((a) => '--' + this.boundaries.related + eol + a.dump() + eol + eol)
.join('')
.slice(0, -1 * eol.length);
return lines + eol
+ 'Content-Type: multipart/related; boundary=' + this.boundaries.related + eol
+ eol
+ this.dumpTextContent(plaintext, html, this.boundaries.related) + eol
+ eol
+ inlineAttachments
+ '--' + this.boundaries.related + '--';
return lines + eol +
'Content-Type: multipart/related; boundary=' + this.boundaries.related + eol +
eol +
this.dumpTextContent(plaintext, html, this.boundaries.related) + eol +
eol +
inlineAttachments +
'--' + this.boundaries.related + '--';
}
else if (structure === 'alternative') {
return lines + eol
+ 'Content-Type: multipart/alternative; boundary=' + this.boundaries.alt + eol
+ eol
+ this.dumpTextContent(plaintext, html, this.boundaries.alt) + eol
+ eol
+ '--' + this.boundaries.alt + '--';
return lines + eol +
'Content-Type: multipart/alternative; boundary=' + this.boundaries.alt + eol +
eol +
this.dumpTextContent(plaintext, html, this.boundaries.alt) + eol +
eol +
'--' + this.boundaries.alt + '--';
}
else {
return lines + eol + primaryMessage.dump();
Expand All @@ -96,31 +100,35 @@ export class MIMEMessage {
}
dumpTextContent(plaintext, html, boundary) {
const eol = this.envctx.eol;
const primaryMessage = html ? html : plaintext;
const primaryMessage = html ?? plaintext;
let data = '';
if (plaintext && html && !this.hasInlineAttachments() && this.hasAttachments())
data = '--' + boundary + eol
+ 'Content-Type: multipart/alternative; boundary=' + this.boundaries.alt + eol
+ eol
+ '--' + this.boundaries.alt + eol
+ plaintext.dump() + eol
+ eol
+ '--' + this.boundaries.alt + eol
+ html.dump() + eol
+ eol
+ '--' + this.boundaries.alt + '--';
else if (plaintext && html && this.hasInlineAttachments())
data = '--' + boundary + eol
+ html.dump();
else if (plaintext && html)
data = '--' + boundary + eol
+ plaintext.dump() + eol
+ eol
+ '--' + boundary + eol
+ html.dump();
else
data = '--' + boundary + eol
+ primaryMessage.dump();
if (plaintext && html && !this.hasInlineAttachments() && this.hasAttachments()) {
data = '--' + boundary + eol +
'Content-Type: multipart/alternative; boundary=' + this.boundaries.alt + eol +
eol +
'--' + this.boundaries.alt + eol +
plaintext.dump() + eol +
eol +
'--' + this.boundaries.alt + eol +
html.dump() + eol +
eol +
'--' + this.boundaries.alt + '--';
}
else if (plaintext && html && this.hasInlineAttachments()) {
data = '--' + boundary + eol +
html.dump();
}
else if (plaintext && html) {
data = '--' + boundary + eol +
plaintext.dump() + eol +
eol +
'--' + boundary + eol +
html.dump();
}
else {
data = '--' + boundary + eol +
primaryMessage.dump();
}
return data;
}
hasInlineAttachments() {
Expand All @@ -145,13 +153,13 @@ export class MIMEMessage {
if (!this.isObject(opts.headers))
opts.headers = {};
if (typeof opts.filename !== 'string') {
throw new MIMETextError('MIMETEXT_MISSING_FILENAME', 'The property filename must exist while adding attachments.');
throw new MIMETextError('MIMETEXT_MISSING_FILENAME', 'The property "filename" must exist while adding attachments.');
}
let type = opts.headers['Content-Type'] || opts.contentType || 'none';
let type = (opts.headers['Content-Type'] ?? opts.contentType) || 'none';
if (this.envctx.validateContentType(type) === false) {
throw new MIMETextError('MIMETEXT_INVALID_MESSAGE_TYPE', `You specified an invalid content type "${type}".`);
}
const encoding = opts.headers['Content-Transfer-Encoding'] || opts.encoding || 'base64';
const encoding = (opts.headers['Content-Transfer-Encoding'] ?? opts.encoding) ?? 'base64';
if (!this.validContentTransferEncodings.includes(encoding)) {
type = 'application/octet-stream';
}
Expand All @@ -170,15 +178,15 @@ export class MIMEMessage {
addMessage(opts) {
if (!this.isObject(opts.headers))
opts.headers = {};
let type = opts.headers['Content-Type'] || opts.contentType || 'none';
let type = (opts.headers['Content-Type'] ?? opts.contentType) || 'none';
if (!this.validTypes.includes(type)) {
throw new MIMETextError('MIMETEXT_INVALID_MESSAGE_TYPE', `Valid content types are ${this.validTypes.join(', ')} but you specified "${type}".`);
}
const encoding = opts.headers['Content-Transfer-Encoding'] || opts.encoding || '7bit';
const encoding = (opts.headers['Content-Transfer-Encoding'] ?? opts.encoding) ?? '7bit';
if (!this.validContentTransferEncodings.includes(encoding)) {
type = 'application/octet-stream';
}
const charset = opts.charset || 'UTF-8';
const charset = opts.charset ?? 'UTF-8';
opts.headers = Object.assign({}, opts.headers, {
'Content-Type': `${type}; charset=${charset}`,
'Content-Transfer-Encoding': encoding
Expand Down Expand Up @@ -207,17 +215,17 @@ export class MIMEMessage {
getRecipients(config = { type: 'To' }) {
return this.getHeader(config.type);
}
setRecipient(input) {
return this.setRecipients(input, { type: 'To' });
setRecipient(input, config = { type: 'To' }) {
return this.setRecipients(input, config);
}
setTo(input) {
return this.setRecipients(input, { type: 'To' });
setTo(input, config = { type: 'To' }) {
return this.setRecipients(input, config);
}
setCc(input) {
return this.setRecipients(input, { type: 'Cc' });
setCc(input, config = { type: 'Cc' }) {
return this.setRecipients(input, config);
}
setBcc(input) {
return this.setRecipients(input, { type: 'Bcc' });
setBcc(input, config = { type: 'Bcc' }) {
return this.setRecipients(input, config);
}
setSubject(value) {
this.setHeader('subject', value);
Expand Down
5 changes: 3 additions & 2 deletions build/MIMEMessageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class MIMEMessageHeader {
const ind = this.fields.findIndex(fieldMatcher);
const field = this.fields[ind];
if (field.validate && !field.validate(value)) {
throw new MIMETextError('MIMETEXT_INVALID_HEADER_VALUE', 'You specified an invalid value for the header ' + name);
throw new MIMETextError('MIMETEXT_INVALID_HEADER_VALUE', `The value for the header "${name}" is invalid.`);
}
this.fields[ind].value = value;
return this.fields[ind];
Expand All @@ -124,7 +124,7 @@ export class MIMEMessageHeader {
this.fields.push(obj);
return obj;
}
throw new MIMETextError('MIMETEXT_INVALID_HEADER_FIELD', 'You specified an invalid header field object.');
throw new MIMETextError('MIMETEXT_INVALID_HEADER_FIELD', 'Invalid input for custom header. It must be in type of HeaderField.');
}
validateMailboxSingle(v) {
return v instanceof Mailbox;
Expand Down Expand Up @@ -181,6 +181,7 @@ export class MIMEMessageContentHeader extends MIMEMessageHeader {
name: 'Content-Disposition'
}
];
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(envctx) {
super(envctx);
}
Expand Down
11 changes: 8 additions & 3 deletions build/Mailbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ export class Mailbox {
this.parse(input);
}
getAddrDomain() {
return this.addr.includes('@') ? this.addr.split('@')[1] : '';
if (this.addr.includes('@')) {
const arr = this.addr.split('@');
if (arr.length > 1)
return arr[1];
}
return '';
}
dump() {
return this.name ? `"${this.name}" <${this.addr}>` : `<${this.addr}>`;
return this.name.length > 0 ? `"${this.name}" <${this.addr}>` : `<${this.addr}>`;
}
parse(input) {
if (this.isMailboxAddrObject(input)) {
Expand All @@ -25,7 +30,7 @@ export class Mailbox {
}
if (this.isMailboxAddrText(input)) {
const text = input.trim();
if (text.slice(0, 1) == '<' && text.slice(-1) == '>') {
if (text.slice(0, 1) === '<' && text.slice(-1) === '>') {
this.addr = text.slice(1, -1);
return this;
}
Expand Down
Loading

0 comments on commit 5c42ad9

Please sign in to comment.