Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('SMTPConnection (Unit)', () => {
// Since they are protected, we can just assume they are set if no error.
// Or inspect via any:
const c = conn as unknown as Record<string, unknown>
expect(c.domain).toBe('example.com')
expect(c._domain).toBe('example.com')
expect(c.host).toBe('mail.example.com')
expect(c.ssl).toBe(true)
expect(c.tls).toBe(true)
Expand Down Expand Up @@ -54,4 +54,13 @@ describe('SMTPConnection (Unit)', () => {
// @ts-expect-error accessing protected
expect(conn.tls).toEqual({ rejectUnauthorized: false })
})

it('does not clash with the node:domain emit hook', async () => {
// Loading node:domain flips EventEmitter.usingDomains on, which makes
// emit() call `this.domain.enter()`. A string `domain` field used to
// shadow that and throw `domain.enter is not a function`.
await import('node:domain')
const conn = new SMTPConnection({ domain: 'example.com' })
expect(() => conn.emit('connect')).not.toThrow()
})
})
10 changes: 5 additions & 5 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class SMTPConnection extends EventEmitter {
protected sock: Socket | TLSSocket | null = null
protected features: { [index: string]: string | boolean } | null = null
protected monitor: SMTPResponseMonitor | null = null
protected domain = hostname()
protected _domain = hostname()
protected host = 'localhost'
protected ssl: boolean | SMTPSocketOptions = false
protected tls: boolean | SMTPSocketOptions = false
Expand Down Expand Up @@ -128,7 +128,7 @@ export class SMTPConnection extends EventEmitter {
}

if (typeof domain === 'string') {
this.domain = domain
this._domain = domain
}

if (typeof host === 'string') {
Expand Down Expand Up @@ -393,7 +393,7 @@ export class SMTPConnection extends EventEmitter {
callback: (err: Error | null | undefined, data?: unknown) => void,
domain?: string
) {
this.command(`helo ${domain || this.domain}`, (err, data) => {
this.command(`helo ${domain || this._domain}`, (err, data) => {
if (err) {
caller(callback, err)
} else {
Expand Down Expand Up @@ -468,7 +468,7 @@ export class SMTPConnection extends EventEmitter {
domain?: string
) {
this.features = {}
this.command(`ehlo ${domain || this.domain}`, (err, data) => {
this.command(`ehlo ${domain || this._domain}`, (err, data) => {
if (err) {
caller(callback, err)
} else {
Expand Down Expand Up @@ -585,7 +585,7 @@ export class SMTPConnection extends EventEmitter {
method: options?.method?.toUpperCase() ?? '',
}

const domain = options?.domain || this.domain
const domain = options?.domain || this._domain

const initiate = (err: Error | null | undefined, data?: unknown) => {
if (err) {
Expand Down