Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix type errors with newer versions of typescript #323

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
112 changes: 65 additions & 47 deletions email.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion email.js.map

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@
"type": "module",
"devDependencies": {
"@ledge/configs": "23.3.23322",
"@rollup/plugin-typescript": "8.3.2",
"@rollup/plugin-typescript": "8.5.0",
"@types/mailparser": "3.4.0",
"@types/node": "12.12.6",
"@types/smtp-server": "3.5.7",
"@typescript-eslint/eslint-plugin": "5.21.0",
"@typescript-eslint/parser": "5.21.0",
"ava": "4.2.0",
"eslint": "8.14.0",
"@typescript-eslint/eslint-plugin": "5.38.0",
"@typescript-eslint/parser": "5.38.0",
"ava": "4.3.3",
"eslint": "8.23.1",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-prettier": "4.2.1",
"mailparser": "3.5.0",
"prettier": "2.6.2",
"rollup": "2.70.2",
"prettier": "2.7.1",
"rollup": "2.79.0",
"smtp-server": "3.11.0",
"ts-node": "10.7.0",
"ts-node": "10.9.1",
"tslib": "2.4.0",
"typescript": "4.3.5"
},
Expand All @@ -44,7 +44,7 @@
}
},
"resolutions": {
"nodemailer": "6.7.4"
"nodemailer": "6.7.8"
},
"engines": {
"node": ">=12"
Expand Down
29 changes: 17 additions & 12 deletions smtp/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface AddressToken {

export interface AddressObject {
address?: string;
name?: string;
name?: string | undefined;
eleith marked this conversation as resolved.
Show resolved Hide resolved
group?: AddressObject[];
}

Expand Down Expand Up @@ -137,7 +137,7 @@ function convertAddressTokens(tokens: AddressToken[]) {
// If no address was found, try to detect one from regular text
if (addresses.length === 0 && texts.length > 0) {
for (let i = texts.length - 1; i >= 0; i--) {
if (texts[i].match(/^[^@\s]+@[^@\s]+$/)) {
if (texts[i]?.match(/^[^@\s]+@[^@\s]+$/) ?? false) {
addresses = texts.splice(i, 1);
break;
}
Expand All @@ -146,16 +146,21 @@ function convertAddressTokens(tokens: AddressToken[]) {
// still no address
if (addresses.length === 0) {
for (let i = texts.length - 1; i >= 0; i--) {
texts[i] = texts[i]
.replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, (address: string) => {
if (addresses.length === 0) {
addresses = [address.trim()];
return ' ';
} else {
return address;
}
})
.trim();
const text = texts[i];
if (text != null && text.length > 0) {
texts[i] = text
.replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, (address: string) => {
if (addresses.length === 0) {
addresses = [address.trim()];
return ' ';
} else {
return address;
}
})
.trim();
} else {
texts[i] = '';
}

if (addresses.length > 0) {
break;
Expand Down
Loading