smtp/client: always validate with `Message` in send

This commit is contained in:
Zack Schuster 2022-04-26 21:40:11 -07:00
parent 00ccfacb7c
commit 57c5258b25
2 changed files with 2 additions and 25 deletions

View File

@ -54,17 +54,7 @@ export class SMTPClient {
msg: T,
callback: MessageCallback<T>
): void {
const message =
msg instanceof Message
? msg
: this._canMakeMessage(msg)
? new Message(msg)
: null;
if (message == null) {
callback(new Error('message is not a valid Message instance'), msg);
return;
}
const message = msg instanceof Message ? msg : new Message(msg);
const { isValid, validationError } = message.checkValidity();
@ -222,19 +212,6 @@ export class SMTPClient {
this.smtp.connect(connect);
}
/**
* @protected
* @param {MessageStack} msg message stack
* @returns {boolean} can make message
*/
protected _canMakeMessage(msg: MessageHeaders) {
return (
msg.from &&
(msg.to || msg.cc || msg.bcc) &&
(msg.text !== undefined || this._containsInlinedHtml(msg.attachment))
);
}
/**
* @protected
* @param {MessageAttachment | MessageAttachment[]} attachment attachment

View File

@ -137,7 +137,7 @@ export class Message {
* @see https://tools.ietf.org/html/rfc2822
* @param {Partial<MessageHeaders>} headers Message headers
*/
constructor(headers: Partial<MessageHeaders>) {
constructor(headers: Partial<MessageHeaders> = {}) {
for (const header in headers) {
// allow user to override default content-type to override charset or send a single non-text message
if (/^content-type$/i.test(header)) {