@haraka/test-fixtures 0.0.0-stage → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +337 -0
- package/LICENSE +21 -0
- package/README.md +263 -2
- package/config/smtp.ini +64 -0
- package/index.js +41 -0
- package/lib/assertions.js +111 -0
- package/lib/connection.js +579 -0
- package/lib/dns.js +206 -0
- package/lib/helpers.js +150 -0
- package/lib/hooks.js +123 -0
- package/lib/invoke.js +55 -0
- package/lib/line_socket.js +68 -0
- package/lib/logger.js +125 -0
- package/lib/plugin.js +320 -0
- package/lib/stub.js +50 -0
- package/lib/transaction.js +270 -0
- package/package.json +72 -4
- package/types/index.d.ts +19 -0
- package/types/lib/assertions.d.ts +54 -0
- package/types/lib/connection.d.ts +144 -0
- package/types/lib/dns.d.ts +15 -0
- package/types/lib/helpers.d.ts +98 -0
- package/types/lib/hooks.d.ts +54 -0
- package/types/lib/invoke.d.ts +26 -0
- package/types/lib/line_socket.d.ts +14 -0
- package/types/lib/logger.d.ts +42 -0
- package/types/lib/plugin.d.ts +30 -0
- package/types/lib/stub.d.ts +38 -0
- package/types/lib/transaction.d.ts +72 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// A mock SMTP Transaction
|
|
2
|
+
|
|
3
|
+
import util from 'node:util'
|
|
4
|
+
|
|
5
|
+
import Notes from '@haraka/notes'
|
|
6
|
+
import message from 'haraka-email-message'
|
|
7
|
+
|
|
8
|
+
import logger from './logger.js'
|
|
9
|
+
|
|
10
|
+
/** @typedef {import('./logger.js').LogMethod} LogMethod */
|
|
11
|
+
|
|
12
|
+
export class Transaction {
|
|
13
|
+
// installed by logger.add_log_methods(); declared for the types
|
|
14
|
+
/** @type {LogMethod} */ logdata
|
|
15
|
+
/** @type {LogMethod} */ logprotocol
|
|
16
|
+
/** @type {LogMethod} */ logdebug
|
|
17
|
+
/** @type {LogMethod} */ loginfo
|
|
18
|
+
/** @type {LogMethod} */ lognotice
|
|
19
|
+
/** @type {LogMethod} */ logwarn
|
|
20
|
+
/** @type {LogMethod} */ logerror
|
|
21
|
+
/** @type {LogMethod} */ logcrit
|
|
22
|
+
/** @type {LogMethod} */ logalert
|
|
23
|
+
/** @type {LogMethod} */ logemerg
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} [uuid]
|
|
27
|
+
* @param {any} [cfg]
|
|
28
|
+
*/
|
|
29
|
+
constructor(uuid, cfg) {
|
|
30
|
+
this.uuid = uuid || '111111-222222-333-4444444'
|
|
31
|
+
this.cfg = cfg
|
|
32
|
+
this.mail_from = null
|
|
33
|
+
this.rcpt_to = []
|
|
34
|
+
this.header_lines = []
|
|
35
|
+
this.data_lines = []
|
|
36
|
+
this.attachment_start_hooks = []
|
|
37
|
+
this.banner = null
|
|
38
|
+
this.body_filters = []
|
|
39
|
+
this.data_bytes = 0
|
|
40
|
+
this.header_pos = 0
|
|
41
|
+
this.found_hb_sep = false
|
|
42
|
+
this.body = null
|
|
43
|
+
this.parse_body = false
|
|
44
|
+
this.notes = new Notes()
|
|
45
|
+
this.notes.skip_plugins = []
|
|
46
|
+
this.header = new message.Header()
|
|
47
|
+
this.message_stream = new message.stream(this.cfg, this.uuid, this.header.header_list)
|
|
48
|
+
this.discard_data = false
|
|
49
|
+
this.resetting = false
|
|
50
|
+
this.rcpt_count = {
|
|
51
|
+
accept: 0,
|
|
52
|
+
tempfail: 0,
|
|
53
|
+
reject: 0,
|
|
54
|
+
}
|
|
55
|
+
this.msg_status = undefined
|
|
56
|
+
this.data_post_start = null
|
|
57
|
+
this.data_post_delay = 0
|
|
58
|
+
this.encoding = 'utf8'
|
|
59
|
+
this.mime_part_count = 0
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ensure_body() {
|
|
63
|
+
if (this.body) return
|
|
64
|
+
|
|
65
|
+
this.body = new message.Body(this.header)
|
|
66
|
+
for (const hook of this.attachment_start_hooks) {
|
|
67
|
+
this.body.on('attachment_start', hook)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (this.banner) this.body.set_banner(this.banner)
|
|
71
|
+
|
|
72
|
+
for (const o of this.body_filters) {
|
|
73
|
+
this.body.add_filter((ct, enc, buf) => {
|
|
74
|
+
const re_match = util.types.isRegExp(o.ct_match) && o.ct_match.test(ct.toLowerCase())
|
|
75
|
+
const ct_begins = ct.toLowerCase().indexOf(String(o.ct_match).toLowerCase()) === 0
|
|
76
|
+
if (re_match || ct_begins) return o.filter(ct, enc, buf)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Removes the CR of a CRLF newline at the end of the buffer.
|
|
82
|
+
remove_final_cr(data) {
|
|
83
|
+
if (data.length < 2) return data
|
|
84
|
+
if (!Buffer.isBuffer(data)) data = Buffer.from(data)
|
|
85
|
+
|
|
86
|
+
if (data[data.length - 2] === 0x0d && data[data.length - 1] === 0x0a) {
|
|
87
|
+
data[data.length - 2] = 0x0a
|
|
88
|
+
return data.slice(0, data.length - 1)
|
|
89
|
+
}
|
|
90
|
+
return data
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Duplicates any '.' chars at the beginning of a line (dot-stuffing) and
|
|
94
|
+
// ensures all newlines are CRLF.
|
|
95
|
+
add_dot_stuffing_and_ensure_crlf_newlines(data) {
|
|
96
|
+
if (!data.length) return data
|
|
97
|
+
if (!Buffer.isBuffer(data)) data = Buffer.from(data)
|
|
98
|
+
|
|
99
|
+
// Make a new buffer big enough to hold two bytes for every one input
|
|
100
|
+
// byte. At most, we add one extra character per input byte, so this
|
|
101
|
+
// is always big enough. We allocate it "unsafe" (i.e. no memset) for
|
|
102
|
+
// speed because we're about to fill it with data, and the remainder of
|
|
103
|
+
// the space we don't fill will be sliced away before we return this.
|
|
104
|
+
const output = Buffer.allocUnsafe(data.length * 2)
|
|
105
|
+
let output_pos = 0
|
|
106
|
+
|
|
107
|
+
let input_pos = 0
|
|
108
|
+
let next_dot = data.indexOf(0x2e)
|
|
109
|
+
let next_lf = data.indexOf(0x0a)
|
|
110
|
+
while (next_dot !== -1 || next_lf !== -1) {
|
|
111
|
+
const run_end = next_dot !== -1 && (next_lf === -1 || next_dot < next_lf) ? next_dot : next_lf
|
|
112
|
+
|
|
113
|
+
// Copy up till whichever comes first, '.' or '\n' (but don't
|
|
114
|
+
// copy the '.' or '\n' itself).
|
|
115
|
+
data.copy(output, output_pos, input_pos, run_end)
|
|
116
|
+
output_pos += run_end - input_pos
|
|
117
|
+
|
|
118
|
+
if (data[run_end] === 0x2e && (run_end === 0 || data[run_end - 1] === 0x0a)) {
|
|
119
|
+
// Replace /^\./ with '..'
|
|
120
|
+
output[output_pos++] = 0x2e
|
|
121
|
+
} else if (data[run_end] === 0x0a && (run_end === 0 || data[run_end - 1] !== 0x0d)) {
|
|
122
|
+
// Replace /\r?\n/ with '\r\n'
|
|
123
|
+
output[output_pos++] = 0x0d
|
|
124
|
+
}
|
|
125
|
+
output[output_pos++] = data[run_end]
|
|
126
|
+
|
|
127
|
+
input_pos = run_end + 1
|
|
128
|
+
|
|
129
|
+
if (run_end === next_dot) {
|
|
130
|
+
next_dot = data.indexOf(0x2e, input_pos)
|
|
131
|
+
} else {
|
|
132
|
+
next_lf = data.indexOf(0x0a, input_pos)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (input_pos < data.length) {
|
|
137
|
+
data.copy(output, output_pos, input_pos)
|
|
138
|
+
output_pos += data.length - input_pos
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return output.slice(0, output_pos)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
add_data(line) {
|
|
145
|
+
if (typeof line === 'string') {
|
|
146
|
+
// This shouldn't ever happen...
|
|
147
|
+
line = Buffer.from(line, this.encoding)
|
|
148
|
+
}
|
|
149
|
+
// is this the end of headers line?
|
|
150
|
+
if (this.header_pos === 0 && (line[0] === 0x0a || (line[0] === 0x0d && line[1] === 0x0a))) {
|
|
151
|
+
this.header.parse(this.header_lines)
|
|
152
|
+
this.header_pos = this.header_lines.length
|
|
153
|
+
this.found_hb_sep = true
|
|
154
|
+
if (this.parse_body) {
|
|
155
|
+
this.ensure_body()
|
|
156
|
+
}
|
|
157
|
+
} else if (this.header_pos === 0) {
|
|
158
|
+
// Build up headers
|
|
159
|
+
if (this.header_lines.length < this.cfg.headers.max_lines) {
|
|
160
|
+
if (line[0] === 0x2e) line = line.slice(1) // Strip leading "."
|
|
161
|
+
this.header_lines.push(line.toString(this.encoding).replace(/\r\n$/, '\n'))
|
|
162
|
+
}
|
|
163
|
+
} else if (this.parse_body) {
|
|
164
|
+
let new_line = line
|
|
165
|
+
if (new_line[0] === 0x2e) new_line = new_line.slice(1) // Strip leading "."
|
|
166
|
+
|
|
167
|
+
line = this.add_dot_stuffing_and_ensure_crlf_newlines(this.body.parse_more(this.remove_final_cr(new_line)))
|
|
168
|
+
if (!line.length) return // buffering for banners
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!this.discard_data) this.message_stream.add_line(line)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** @param {() => void} [cb] */
|
|
175
|
+
end_data(cb) {
|
|
176
|
+
if (!this.found_hb_sep && this.header_lines.length) {
|
|
177
|
+
// Headers not parsed yet - must be a busted email
|
|
178
|
+
// Strategy: Find the first line that doesn't look like a header.
|
|
179
|
+
// Treat anything before that as headers, anything after as body.
|
|
180
|
+
let header_pos = 0
|
|
181
|
+
for (let i = 0; i < this.header_lines.length; i++) {
|
|
182
|
+
// Anything that doesn't match a header or continuation
|
|
183
|
+
if (!/^(?:([^\s:]*):\s*([\s\S]*)$|[ \t])/.test(this.header_lines[i])) {
|
|
184
|
+
break
|
|
185
|
+
}
|
|
186
|
+
header_pos = i
|
|
187
|
+
}
|
|
188
|
+
const body_lines = this.header_lines.splice(header_pos + 1)
|
|
189
|
+
this.header.parse(this.header_lines)
|
|
190
|
+
this.header_pos = header_pos
|
|
191
|
+
if (this.parse_body) {
|
|
192
|
+
this.ensure_body()
|
|
193
|
+
for (const bodyLine of body_lines) {
|
|
194
|
+
this.body.parse_more(bodyLine)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (this.header_pos && this.parse_body) {
|
|
199
|
+
const line = this.add_dot_stuffing_and_ensure_crlf_newlines(this.body.parse_end())
|
|
200
|
+
if (line.length) {
|
|
201
|
+
this.body.force_end()
|
|
202
|
+
|
|
203
|
+
if (!this.discard_data) this.message_stream.add_line(line)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (this.discard_data) {
|
|
208
|
+
cb()
|
|
209
|
+
} else {
|
|
210
|
+
this.message_stream.add_line_end(cb)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
add_header(key, value) {
|
|
215
|
+
this.header.add_end(key, value)
|
|
216
|
+
if (this.header_pos > 0) this.reset_headers()
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
add_leading_header(key, value) {
|
|
220
|
+
this.header.add(key, value)
|
|
221
|
+
if (this.header_pos > 0) this.reset_headers()
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
reset_headers() {
|
|
225
|
+
const header_lines = this.header.lines()
|
|
226
|
+
this.header_pos = header_lines.length
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
remove_header(key) {
|
|
230
|
+
this.header.remove(key)
|
|
231
|
+
if (this.header_pos > 0) this.reset_headers()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
attachment_hooks(start) {
|
|
235
|
+
this.parse_body = 1
|
|
236
|
+
this.attachment_start_hooks.push(start)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* @param {string} text
|
|
241
|
+
* @param {string} [html]
|
|
242
|
+
*/
|
|
243
|
+
set_banner(text, html) {
|
|
244
|
+
// throw "transaction.set_banner is currently non-functional";
|
|
245
|
+
this.parse_body = true
|
|
246
|
+
if (!html) {
|
|
247
|
+
html = text.replace(/\n/g, '<br/>\n')
|
|
248
|
+
}
|
|
249
|
+
this.banner = [text, html]
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
add_body_filter(ct_match, filter) {
|
|
253
|
+
this.parse_body = true
|
|
254
|
+
this.body_filters.push({ ct_match, filter })
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
incr_mime_count() {
|
|
258
|
+
this.mime_part_count++
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @param {string} [uuid]
|
|
264
|
+
* @param {object} [cfg]
|
|
265
|
+
*/
|
|
266
|
+
export function createTransaction(uuid, cfg) {
|
|
267
|
+
const t = new Transaction(uuid, cfg)
|
|
268
|
+
logger.add_log_methods(t, 'mock-connection')
|
|
269
|
+
return t
|
|
270
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,74 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@haraka/test-fixtures",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Haraka Test Fixtures",
|
|
5
|
+
"author": "Haraka Team <haraka.mail@gmail.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/haraka/test-fixtures.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./index.js",
|
|
13
|
+
"types": "./types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./types/index.d.ts",
|
|
17
|
+
"default": "./index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"CHANGELOG.md",
|
|
23
|
+
"config",
|
|
24
|
+
"index.js",
|
|
25
|
+
"lib",
|
|
26
|
+
"types"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=24"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@haraka/config": "^2.0.1",
|
|
33
|
+
"@haraka/constants": "^2.0.0",
|
|
34
|
+
"@haraka/email-address": "^3.1.7",
|
|
35
|
+
"@haraka/notes": "^2.0.1",
|
|
36
|
+
"@haraka/results": "^3.0.1",
|
|
37
|
+
"@haraka/utils": "^3.0.1",
|
|
38
|
+
"haraka-email-message": "^1.4.5",
|
|
39
|
+
"ipaddr.js": "^2.5.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@haraka/eslint-config": "^3.0.1",
|
|
43
|
+
"@types/node": "^26.6.11",
|
|
44
|
+
"typescript": "^7.0.2"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/haraka/test-fixtures/issues"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"prepare": "git rev-parse --git-dir >/dev/null 2>&1 && git config core.hooksPath .githooks || true",
|
|
51
|
+
"format": "npm run prettier:fix && npm run lint:fix",
|
|
52
|
+
"lint": "eslint *.js lib test",
|
|
53
|
+
"lint:fix": "eslint *.js lib test --fix",
|
|
54
|
+
"prettier": "npx prettier . --check",
|
|
55
|
+
"prettier:fix": "npx prettier . --write --log-level=warn",
|
|
56
|
+
"qlty": "qlty smells --all",
|
|
57
|
+
"test": "npm run test:types && node --test test/*.js",
|
|
58
|
+
"test:coverage": "node --test --experimental-test-coverage test/*.js",
|
|
59
|
+
"test:coverage:lcov": "mkdir -p coverage && node --test --test-concurrency=1 --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info test/*.js",
|
|
60
|
+
"versions": "npx npm-dep-mgr check",
|
|
61
|
+
"versions:fix": "npx npm-dep-mgr update",
|
|
62
|
+
"test:types": "npm run types && tsc -p test/types",
|
|
63
|
+
"types": "tsc -p tsconfig.json",
|
|
64
|
+
"prepack": "npm run types"
|
|
65
|
+
},
|
|
66
|
+
"prettier": {
|
|
67
|
+
"printWidth": 120,
|
|
68
|
+
"semi": false,
|
|
69
|
+
"singleQuote": true
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public"
|
|
73
|
+
}
|
|
74
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type LoadedPlugin = import('./lib/plugin.js').LoadedPlugin;
|
|
2
|
+
export type Connection = import('./lib/connection.js').Connection;
|
|
3
|
+
export type Transaction = import('./lib/transaction.js').Transaction;
|
|
4
|
+
export type HookResult = import('./lib/hooks.js').HookResult;
|
|
5
|
+
export type Stub = import('./lib/stub.js').Stub;
|
|
6
|
+
export { default as results, default as result_store } from '@haraka/results';
|
|
7
|
+
export * as assertions from './lib/assertions.js';
|
|
8
|
+
export * as connection from './lib/connection.js';
|
|
9
|
+
export * as dns from './lib/dns.js';
|
|
10
|
+
export * as helpers from './lib/helpers.js';
|
|
11
|
+
export * as hooks from './lib/hooks.js';
|
|
12
|
+
export * as line_socket from './lib/line_socket.js';
|
|
13
|
+
export { default as logger } from './lib/logger.js';
|
|
14
|
+
export { default as plugin } from './lib/plugin.js';
|
|
15
|
+
export * as transaction from './lib/transaction.js';
|
|
16
|
+
export { stub } from './lib/stub.js';
|
|
17
|
+
export { callHook, makePlugin, makeConnection, getResult } from './lib/helpers.js';
|
|
18
|
+
export { callConnect, callHelo, callEhlo, callMail, callRcpt, callRcptOk, callData, callDataPost, callQueue, callQueueOk, callDisconnect, } from './lib/hooks.js';
|
|
19
|
+
export { assertCont, assertOk, assertDeny, assertResult } from './lib/assertions.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assert the hook continued (no return code, or explicit CONT).
|
|
3
|
+
*
|
|
4
|
+
* assertCont(rc)
|
|
5
|
+
* assertCont(result)
|
|
6
|
+
*
|
|
7
|
+
* @param {unknown} rcOrResult a return code, or the { rc, msg } from a call helper
|
|
8
|
+
*/
|
|
9
|
+
export declare const assertCont: (rcOrResult: unknown) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Assert the hook returned OK. Optional msg matcher.
|
|
12
|
+
*
|
|
13
|
+
* assertOk(rc)
|
|
14
|
+
* assertOk(result)
|
|
15
|
+
* assertOk(result, /accepted/)
|
|
16
|
+
*
|
|
17
|
+
* @param {unknown} rcOrResult a return code, or the { rc, msg } from a call helper
|
|
18
|
+
* @param {string | RegExp} [msgMatcher]
|
|
19
|
+
*/
|
|
20
|
+
export declare const assertOk: (rcOrResult: unknown, msgMatcher?: string | RegExp) => void;
|
|
21
|
+
/**
|
|
22
|
+
* Assert the hook denied. By default accepts any DENY* code; pass a
|
|
23
|
+
* specific code (DENY, DENYSOFT, DENYDISCONNECT, DENYSOFTDISCONNECT)
|
|
24
|
+
* to require an exact match.
|
|
25
|
+
*
|
|
26
|
+
* assertDeny(rc)
|
|
27
|
+
* assertDeny(result)
|
|
28
|
+
* assertDeny(result, /no thanks/)
|
|
29
|
+
* assertDeny(result, /no thanks/, DENYSOFT)
|
|
30
|
+
*
|
|
31
|
+
* @param {unknown} rcOrResult a return code, or the { rc, msg } from a call helper
|
|
32
|
+
* @param {string | RegExp} [msgMatcher]
|
|
33
|
+
* @param {number} [code]
|
|
34
|
+
*/
|
|
35
|
+
export declare const assertDeny: (rcOrResult: unknown, msgMatcher?: string | RegExp, code?: number) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Assert that connection.results.get(plugin)[kind] contains an entry
|
|
38
|
+
* matching `matcher` (string substring or RegExp). Without a matcher,
|
|
39
|
+
* just asserts the bucket is non-empty.
|
|
40
|
+
*
|
|
41
|
+
* assertResult(conn, plugin, 'pass')
|
|
42
|
+
* assertResult(conn, plugin, 'pass', /^connect:/)
|
|
43
|
+
* assertResult(conn, 'access', 'fail', 'blacklist')
|
|
44
|
+
*
|
|
45
|
+
* @param {{ results: import('@haraka/results').default }} connection
|
|
46
|
+
* @param {string | { name: string }} pluginOrName
|
|
47
|
+
* @param {string} kind
|
|
48
|
+
* @param {string | RegExp} [matcher]
|
|
49
|
+
*/
|
|
50
|
+
export declare const assertResult: (connection: {
|
|
51
|
+
results: import('@haraka/results').default;
|
|
52
|
+
}, pluginOrName: string | {
|
|
53
|
+
name: string;
|
|
54
|
+
}, kind: string, matcher?: string | RegExp) => void;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import Notes from '@haraka/notes';
|
|
2
|
+
import ResultStore from '@haraka/results';
|
|
3
|
+
export type LogMethod = import('./logger.js').LogMethod;
|
|
4
|
+
export declare class Connection {
|
|
5
|
+
client: any;
|
|
6
|
+
server: any;
|
|
7
|
+
cfg: any;
|
|
8
|
+
local: {
|
|
9
|
+
ip: null;
|
|
10
|
+
port: null;
|
|
11
|
+
host: string;
|
|
12
|
+
info: string;
|
|
13
|
+
};
|
|
14
|
+
remote: {
|
|
15
|
+
ip: string;
|
|
16
|
+
port: null;
|
|
17
|
+
host: null;
|
|
18
|
+
info: null;
|
|
19
|
+
closed: boolean;
|
|
20
|
+
is_private: boolean;
|
|
21
|
+
is_local: boolean;
|
|
22
|
+
};
|
|
23
|
+
hello: {
|
|
24
|
+
host: null;
|
|
25
|
+
verb: null;
|
|
26
|
+
};
|
|
27
|
+
tls: {
|
|
28
|
+
enabled: boolean;
|
|
29
|
+
advertised: boolean;
|
|
30
|
+
verified: boolean;
|
|
31
|
+
cipher: {};
|
|
32
|
+
};
|
|
33
|
+
proxy: {
|
|
34
|
+
allowed: boolean;
|
|
35
|
+
ip: null;
|
|
36
|
+
type: null;
|
|
37
|
+
timer: null;
|
|
38
|
+
};
|
|
39
|
+
current_data: any;
|
|
40
|
+
current_line: any;
|
|
41
|
+
state: number;
|
|
42
|
+
encoding: string;
|
|
43
|
+
prev_state: number | null;
|
|
44
|
+
loop_code: any;
|
|
45
|
+
loop_msg: any;
|
|
46
|
+
uuid: string;
|
|
47
|
+
notes: Notes;
|
|
48
|
+
transaction: any;
|
|
49
|
+
tran_count: number;
|
|
50
|
+
capabilities: any;
|
|
51
|
+
ehlo_hello_message: string;
|
|
52
|
+
connection_close_message: string;
|
|
53
|
+
banner_includes_uuid: boolean;
|
|
54
|
+
deny_includes_uuid: boolean;
|
|
55
|
+
early_talker: boolean;
|
|
56
|
+
pipelining: boolean;
|
|
57
|
+
_relaying: boolean;
|
|
58
|
+
esmtp: boolean;
|
|
59
|
+
last_response: any;
|
|
60
|
+
hooks_to_run: any[];
|
|
61
|
+
start_time: number;
|
|
62
|
+
last_reject: string;
|
|
63
|
+
max_bytes: number;
|
|
64
|
+
max_mime_parts: number;
|
|
65
|
+
totalbytes: number;
|
|
66
|
+
rcpt_count: {
|
|
67
|
+
accept: number;
|
|
68
|
+
tempfail: number;
|
|
69
|
+
reject: number;
|
|
70
|
+
};
|
|
71
|
+
msg_count: {
|
|
72
|
+
accept: number;
|
|
73
|
+
tempfail: number;
|
|
74
|
+
reject: number;
|
|
75
|
+
};
|
|
76
|
+
max_line_length: number;
|
|
77
|
+
max_data_line_length: number;
|
|
78
|
+
results: ResultStore;
|
|
79
|
+
errors: number;
|
|
80
|
+
last_rcpt_msg: string | null | undefined;
|
|
81
|
+
hook: any;
|
|
82
|
+
/** @type {LogMethod} */ logdata: LogMethod;
|
|
83
|
+
/** @type {LogMethod} */ logprotocol: LogMethod;
|
|
84
|
+
/** @type {LogMethod} */ logdebug: LogMethod;
|
|
85
|
+
/** @type {LogMethod} */ loginfo: LogMethod;
|
|
86
|
+
/** @type {LogMethod} */ lognotice: LogMethod;
|
|
87
|
+
/** @type {LogMethod} */ logwarn: LogMethod;
|
|
88
|
+
/** @type {LogMethod} */ logerror: LogMethod;
|
|
89
|
+
/** @type {LogMethod} */ logcrit: LogMethod;
|
|
90
|
+
/** @type {LogMethod} */ logalert: LogMethod;
|
|
91
|
+
/** @type {LogMethod} */ logemerg: LogMethod;
|
|
92
|
+
constructor(client: any, server: any, cfg: any);
|
|
93
|
+
static setupClient(self: any): void;
|
|
94
|
+
setTLS(obj: any): void;
|
|
95
|
+
set(prop_str: any, val: any): void;
|
|
96
|
+
get(prop_str: any): any;
|
|
97
|
+
set relaying(val: any);
|
|
98
|
+
get relaying(): any;
|
|
99
|
+
auth_results(): void;
|
|
100
|
+
/**
|
|
101
|
+
* @param {number} code
|
|
102
|
+
* @param {string | string[]} msg
|
|
103
|
+
* @param {() => any} [func]
|
|
104
|
+
*/
|
|
105
|
+
respond(code: number, msg: string | string[], func?: () => any): any;
|
|
106
|
+
/** @param {() => void} [done] */
|
|
107
|
+
init_transaction(done?: () => void): void;
|
|
108
|
+
/** @param {() => void} [done] */
|
|
109
|
+
reset_transaction(done?: () => void): void;
|
|
110
|
+
pause(): void;
|
|
111
|
+
resume(): void;
|
|
112
|
+
process_data(data: any): void;
|
|
113
|
+
_process_data(): void;
|
|
114
|
+
process_line(line: any): void;
|
|
115
|
+
disconnect(): void;
|
|
116
|
+
get_capabilities(): string[];
|
|
117
|
+
/**
|
|
118
|
+
* @param {number} [retval]
|
|
119
|
+
* @param {string} [msg]
|
|
120
|
+
*/
|
|
121
|
+
mail_respond(retval?: number, msg?: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* @param {any} rcpt
|
|
124
|
+
* @param {string} action
|
|
125
|
+
* @param {string} [msg]
|
|
126
|
+
*/
|
|
127
|
+
rcpt_incr(rcpt: any, action: string, msg?: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* @param {number} [retval]
|
|
130
|
+
* @param {string} [msg]
|
|
131
|
+
*/
|
|
132
|
+
rcpt_ok_respond(retval?: number, msg?: string): void;
|
|
133
|
+
/**
|
|
134
|
+
* @param {number} [retval]
|
|
135
|
+
* @param {string} [msg]
|
|
136
|
+
*/
|
|
137
|
+
rcpt_respond(retval?: number, msg?: string): void;
|
|
138
|
+
/**
|
|
139
|
+
* @param {number} [retval]
|
|
140
|
+
* @param {string} [msg]
|
|
141
|
+
*/
|
|
142
|
+
data_respond(retval?: number, msg?: string): void;
|
|
143
|
+
}
|
|
144
|
+
export declare function createConnection(client?: {}, server?: {}, cfg?: {}): Connection;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const TYPE: {
|
|
2
|
+
A: number;
|
|
3
|
+
MX: number;
|
|
4
|
+
TXT: number;
|
|
5
|
+
AAAA: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const RCODE: {
|
|
8
|
+
NOERROR: number;
|
|
9
|
+
FORMERR: number;
|
|
10
|
+
SERVFAIL: number;
|
|
11
|
+
NXDOMAIN: number;
|
|
12
|
+
NOTIMP: number;
|
|
13
|
+
REFUSED: number;
|
|
14
|
+
};
|
|
15
|
+
export declare function start(zones?: {}, opts?: {}): Promise<any>;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Address } from '@haraka/email-address';
|
|
2
|
+
/**
|
|
3
|
+
* Wraps a Haraka hook callback into an awaitable Promise.
|
|
4
|
+
*
|
|
5
|
+
* Haraka hooks follow the convention: plugin.method(next, connection, ...args)
|
|
6
|
+
* where next is called as next(rc, msg). This helper turns that into:
|
|
7
|
+
*
|
|
8
|
+
* const { rc, msg } = await callHook(plugin, 'bare_ip', connection, 'helo')
|
|
9
|
+
*
|
|
10
|
+
* Prefer the typed call helpers (callMail, callRcpt, etc.) when possible —
|
|
11
|
+
* they're more readable and resolve the method name automatically. Use this
|
|
12
|
+
* generic version for hooks without a typed wrapper, or to call a specific
|
|
13
|
+
* method directly.
|
|
14
|
+
*
|
|
15
|
+
* @param {import('./plugin.js').LoadedPlugin} plugin
|
|
16
|
+
* @param {string} method - Hook method name (e.g. 'hook_rcpt', 'bare_ip')
|
|
17
|
+
* @param {object} connection
|
|
18
|
+
* @param {...*} args - Additional hook arguments (params, helo host, etc.)
|
|
19
|
+
* @returns {Promise<{rc: *, msg: *}>}
|
|
20
|
+
*/
|
|
21
|
+
export declare const callHook: (plugin: import('./plugin.js').LoadedPlugin, method: string, connection: object, ...args: any[]) => Promise<{
|
|
22
|
+
rc: any;
|
|
23
|
+
msg: any;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Creates, optionally registers, and returns a Plugin instance.
|
|
27
|
+
*
|
|
28
|
+
* const plugin = makePlugin('helo.checks')
|
|
29
|
+
* const plugin = makePlugin('access', { configDir: __dirname })
|
|
30
|
+
*
|
|
31
|
+
* @param {string} name
|
|
32
|
+
* @param {object} [opts]
|
|
33
|
+
* @param {boolean} [opts.register=true] - call plugin.register() after creation
|
|
34
|
+
* @param {string} [opts.configDir] - resolve to plugin.config.module_config(path.resolve(configDir))
|
|
35
|
+
* *before* register() runs
|
|
36
|
+
* @returns {import('./plugin.js').LoadedPlugin}
|
|
37
|
+
*/
|
|
38
|
+
export declare const makePlugin: (name: string, { register, configDir }?: {
|
|
39
|
+
register?: boolean;
|
|
40
|
+
configDir?: string;
|
|
41
|
+
}) => import('./plugin.js').LoadedPlugin;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a Connection with commonly-needed options pre-applied.
|
|
44
|
+
*
|
|
45
|
+
* const conn = makeConnection({ ip: '1.2.3.4', mailFrom: 'user@host' })
|
|
46
|
+
*
|
|
47
|
+
* If mailFrom, rcptTo, or txNotes is given, a transaction is created
|
|
48
|
+
* automatically (no need to pass withTxn).
|
|
49
|
+
*
|
|
50
|
+
* @param {object} [opts]
|
|
51
|
+
* @param {string} [opts.ip='127.0.0.1'] - remote.ip
|
|
52
|
+
* @param {boolean} [opts.withTxn=false] - call init_transaction()
|
|
53
|
+
* @param {boolean} [opts.relaying=false] - connection._relaying
|
|
54
|
+
* @param {string} [opts.helo] - hello.host (EHLO hostname)
|
|
55
|
+
* @param {string|Address} [opts.mailFrom] - transaction.mail_from (string coerced to Address)
|
|
56
|
+
* @param {Array<string|Address>} [opts.rcptTo] - transaction.rcpt_to (strings coerced to Address)
|
|
57
|
+
* @param {object} [opts.notes] - seed connection.notes
|
|
58
|
+
* @param {object} [opts.txNotes] - seed transaction.notes
|
|
59
|
+
* @param {object} [opts.server] - assigned to connection.server; use for
|
|
60
|
+
* server.notes.* injection (e.g. shared redis handle)
|
|
61
|
+
* @param {string} [opts.host] - remote.host (rDNS hostname)
|
|
62
|
+
* @param {boolean} [opts.silent=false] - replace every log method with a no-op
|
|
63
|
+
* @param {boolean} [opts.stubLogs=false] - replace every log method with a recording stub()
|
|
64
|
+
* @returns {import('./connection.js').Connection}
|
|
65
|
+
*/
|
|
66
|
+
export declare const makeConnection: ({ ip, withTxn, relaying, helo, host, mailFrom, rcptTo, notes, txNotes, server, silent, stubLogs, }?: {
|
|
67
|
+
ip?: string;
|
|
68
|
+
withTxn?: boolean;
|
|
69
|
+
relaying?: boolean;
|
|
70
|
+
helo?: string;
|
|
71
|
+
mailFrom?: string | Address;
|
|
72
|
+
rcptTo?: Array<string | Address>;
|
|
73
|
+
notes?: object;
|
|
74
|
+
txNotes?: object;
|
|
75
|
+
server?: object;
|
|
76
|
+
host?: string;
|
|
77
|
+
silent?: boolean;
|
|
78
|
+
stubLogs?: boolean;
|
|
79
|
+
}) => import('./connection.js').Connection;
|
|
80
|
+
/**
|
|
81
|
+
* Returns the result-store entry for a plugin, accepting either the plugin
|
|
82
|
+
* instance or its string name. Falls back to an empty result object so
|
|
83
|
+
* callers can write `getResult(conn, plugin).pass.length` without null checks.
|
|
84
|
+
*
|
|
85
|
+
* const r = getResult(connection, plugin)
|
|
86
|
+
* assert.ok(r.pass.length)
|
|
87
|
+
*
|
|
88
|
+
* @param {object} connection
|
|
89
|
+
* @param {object|string} pluginOrName
|
|
90
|
+
* @returns {{ pass: string[], fail: string[], skip: string[], err: string[], data: object }}
|
|
91
|
+
*/
|
|
92
|
+
export declare const getResult: (connection: object, pluginOrName: object | string) => {
|
|
93
|
+
pass: string[];
|
|
94
|
+
fail: string[];
|
|
95
|
+
skip: string[];
|
|
96
|
+
err: string[];
|
|
97
|
+
data: object;
|
|
98
|
+
};
|