1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-03 11:38:50 +00:00

smtp: strongly type addressparser & emailjs-mime-codec

This commit is contained in:
Zack Schuster 2020-05-01 12:15:46 -07:00
parent 93f23cdc11
commit 106e5bab8f
3 changed files with 13 additions and 5 deletions

View File

@ -1,4 +1,3 @@
// @ts-ignore
import addressparser from 'addressparser';
import { Message } from './message';
import type { MessageAttachment, MessageHeaders } from './message'; // eslint-disable-line no-unused-vars
@ -12,7 +11,7 @@ export interface MessageStack {
text: string;
returnPath: string;
from: string;
to: string | { address: string }[];
to: ReturnType<typeof addressparser>;
cc: string[];
bcc: string[];
}

View File

@ -3,9 +3,7 @@ import { hostname } from 'os';
import { Stream } from 'stream';
import type { Duplex } from 'stream'; // eslint-disable-line no-unused-vars
import type { Indexed } from '@ledge/types'; // eslint-disable-line no-unused-vars
// @ts-ignore
import addressparser from 'addressparser';
// @ts-ignore
import { mimeWordEncode } from 'emailjs-mime-codec';
import { getRFC2822Date } from './date';
@ -80,7 +78,7 @@ function generate_boundary() {
function convertPersonToAddress(person: string) {
return addressparser(person)
.map(({ name, address }: { name: string; address: string }) => {
.map(({ name, address }) => {
return name
? `${mimeWordEncode(name).replace(/,/g, '=2C')} <${address}>`
: address;

11
smtp/typings.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
declare module 'addressparser' {
var addressparser: (address?: string) => { name: string; address: string }[];
export = addressparser;
}
declare module 'emailjs-mime-codec' {
var codec: {
mimeWordEncode: (word?: string) => string;
};
export = codec;
}