smtp/connection: use WeakSet for greylist tracking

This commit is contained in:
Zack Schuster 2020-11-24 16:56:08 -08:00
parent d4748a3cb2
commit d1fca9efe3
1 changed files with 4 additions and 7 deletions

View File

@ -120,10 +120,7 @@ export class SMTPConnection extends EventEmitter {
protected tls: boolean | SMTPSocketOptions = false; protected tls: boolean | SMTPSocketOptions = false;
protected port: number; protected port: number;
private greylistResponseTracker = new WeakMap< private greylistResponseTracker = new WeakSet<(...rest: any[]) => void>();
(...rest: any[]) => void,
boolean
>();
/** /**
* SMTP class written using python's (2.7) smtplib.py as a base. * SMTP class written using python's (2.7) smtplib.py as a base.
@ -411,9 +408,9 @@ export class SMTPConnection extends EventEmitter {
} else if ( } else if (
(code === 450 || code === 451) && (code === 450 || code === 451) &&
msg.message.toLowerCase().includes('greylist') && msg.message.toLowerCase().includes('greylist') &&
this.greylistResponseTracker.get(response) === false this.greylistResponseTracker.has(response) === false
) { ) {
this.greylistResponseTracker.set(response, true); this.greylistResponseTracker.add(response);
setTimeout(() => { setTimeout(() => {
this.send(cmd + CRLF, response); this.send(cmd + CRLF, response);
}, GREYLIST_DELAY); }, GREYLIST_DELAY);
@ -435,7 +432,7 @@ export class SMTPConnection extends EventEmitter {
} }
}; };
this.greylistResponseTracker.set(response, false); this.greylistResponseTracker.delete(response);
this.send(cmd + CRLF, response); this.send(cmd + CRLF, response);
} }