Haraka 3.1.2 → 3.1.4

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.
Files changed (66) hide show
  1. package/.prettierignore +2 -0
  2. package/CONTRIBUTORS.md +24 -2
  3. package/Changes.md +48 -0
  4. package/Plugins.md +81 -64
  5. package/README.md +1 -1
  6. package/bin/haraka +9 -7
  7. package/config/connection.ini +10 -0
  8. package/config/smtp.ini +0 -9
  9. package/connection.js +15 -19
  10. package/docs/CoreConfig.md +2 -3
  11. package/docs/Plugins.md +1 -1
  12. package/docs/plugins/aliases.md +0 -2
  13. package/docs/plugins/queue/qmail-queue.md +0 -1
  14. package/docs/tutorials/Migrating_from_v1_to_v2.md +1 -1
  15. package/logger.js +2 -2
  16. package/outbound/client_pool.js +1 -1
  17. package/outbound/hmail.js +76 -83
  18. package/outbound/index.js +36 -34
  19. package/outbound/queue.js +231 -176
  20. package/package.json +29 -31
  21. package/plugins/prevent_credential_leaks.js +2 -2
  22. package/plugins/process_title.js +1 -1
  23. package/plugins/queue/smtp_forward.js +1 -1
  24. package/plugins/status.js +8 -5
  25. package/plugins/tls.js +1 -1
  26. package/plugins.js +19 -14
  27. package/rfc1869.js +10 -10
  28. package/run_tests +20 -2
  29. package/server.js +15 -10
  30. package/smtp_client.js +2 -9
  31. package/test/config/tls/haraka.local.pem +47 -47
  32. package/test/connection.js +286 -147
  33. package/test/fixtures/line_socket.js +1 -0
  34. package/test/fixtures/util_hmailitem.js +1 -1
  35. package/test/outbound/bounce_net_errors.js +176 -0
  36. package/test/outbound/bounce_rfc3464.js +303 -0
  37. package/test/outbound/hmail.js +140 -104
  38. package/test/outbound/index.js +61 -101
  39. package/test/outbound/qfile.js +25 -25
  40. package/test/outbound/queue.js +233 -0
  41. package/test/plugins/queue/smtp_forward.js +1 -1
  42. package/test/plugins/record_envelope_addresses.js +93 -0
  43. package/test/plugins/tls.js +2 -2
  44. package/test/plugins/xclient.js +137 -0
  45. package/test/rfc1869.js +43 -0
  46. package/test/smtp_client.js +6 -6
  47. package/test/transaction.js +486 -201
  48. package/tls_socket.js +3 -3
  49. package/transaction.js +33 -10
  50. package/config/me +0 -1
  51. package/config/rabbitmq.ini +0 -10
  52. package/config/rabbitmq_amqplib.ini +0 -19
  53. package/config/tls_cert.pem +0 -23
  54. package/config/tls_key.pem +0 -28
  55. package/docs/plugins/queue/rabbitmq.md +0 -34
  56. package/docs/plugins/queue/rabbitmq_amqplib.md +0 -51
  57. package/plugins/queue/rabbitmq.js +0 -141
  58. package/plugins/queue/rabbitmq_amqplib.js +0 -96
  59. package/test/config/tls/ec.pem +0 -23
  60. package/test/config/tls/mismatched.pem +0 -49
  61. package/test/outbound_bounce_net_errors.js +0 -157
  62. package/test/outbound_bounce_rfc3464.js +0 -366
  63. package/test/queue/multibyte +0 -0
  64. package/test/queue/plain +0 -0
  65. package/test/test-queue/delete-me +0 -0
  66. package/test/tls_socket.js +0 -273
package/tls_socket.js CHANGED
@@ -615,7 +615,7 @@ function createServer(cb) {
615
615
 
616
616
  cryptoSocket.removeAllListeners('data')
617
617
 
618
- const options = Object.assign({}, certsByHost['*'])
618
+ const options = { ...certsByHost['*'] }
619
619
  options.server = server // TLSSocket needs server for SNI to work
620
620
 
621
621
  options.rejectUnauthorized = exports.get_rejectUnauthorized(
@@ -679,11 +679,11 @@ function connect(conn_options = {}) {
679
679
  const host = conn_options.host
680
680
  if (exports.cfg === undefined) exports.load_tls_ini()
681
681
  if (exports.cfg.mutual_auth_hosts[host]) {
682
- options = Object.assign(options, getCertFor(exports.cfg.mutual_auth_hosts[host]))
682
+ options = { ...options, ...getCertFor(exports.cfg.mutual_auth_hosts[host]) }
683
683
  } else if (exports.cfg.mutual_auth_hosts_exclude[host]) {
684
684
  // send no client cert
685
685
  } else if (exports.cfg.main.mutual_tls) {
686
- options = Object.assign(options, getCertFor(host))
686
+ options = { ...options, ...getCertFor(host) }
687
687
  }
688
688
  }
689
689
  options.socket = cryptoSocket
package/transaction.js CHANGED
@@ -55,9 +55,12 @@ class Transaction {
55
55
 
56
56
  for (const o of this.body_filters) {
57
57
  this.body.add_filter((ct, enc, buf) => {
58
- const re_match = util.types.isRegExp(o.ct_match) && o.ct_match.test(ct.toLowerCase())
59
- const ct_begins = ct.toLowerCase().indexOf(String(o.ct_match).toLowerCase()) === 0
60
- if (re_match || ct_begins) return o.filter(ct, enc, buf)
58
+ if (!ct) return buf
59
+ const ct_lc = String(ct).toLowerCase().trim()
60
+ const re_match = util.types.isRegExp(o.ct_match) && o.ct_match.test(ct_lc)
61
+ const ct_begins = ct_lc.indexOf(String(o.ct_match).toLowerCase()) === 0
62
+ if (re_match || ct_begins) return o.filter(ct, enc, buf) || buf
63
+ return buf
61
64
  })
62
65
  }
63
66
  }
@@ -133,7 +136,7 @@ class Transaction {
133
136
  // is this the end of headers line?
134
137
  if (this.header_pos === 0 && (line[0] === 0x0a || (line[0] === 0x0d && line[1] === 0x0a))) {
135
138
  this.header.parse(this.header_lines)
136
- this.header_pos = this.header_lines.length
139
+ this.header_pos = this.header.header_list ? this.header.header_list.length : -1
137
140
  this.found_hb_sep = true
138
141
  if (this.parse_body) this.ensure_body()
139
142
  } else if (this.header_pos === 0) {
@@ -143,6 +146,7 @@ class Transaction {
143
146
  this.header_lines.push(line.toString(this.encoding).replace(/\r\n$/, '\n'))
144
147
  }
145
148
  } else if (this.parse_body) {
149
+ this.ensure_body()
146
150
  let new_line = line
147
151
  if (new_line[0] === 0x2e) new_line = new_line.slice(1) // Strip leading "."
148
152
 
@@ -169,13 +173,23 @@ class Transaction {
169
173
  }
170
174
  const body_lines = this.header_lines.splice(header_pos + 1)
171
175
  this.header.parse(this.header_lines)
172
- this.header_pos = header_pos
176
+ this.header_pos = this.header.header_list ? this.header.header_list.length : -1
177
+ this.found_hb_sep = true
178
+
179
+ // We MUST add an empty line to the message_stream so that it knows
180
+ // where the headers end. Otherwise it skips everything.
181
+ if (!this.discard_data) this.message_stream.add_line(Buffer.from('\r\n'))
182
+
173
183
  if (this.parse_body) {
174
184
  this.ensure_body()
175
185
  for (const bodyLine of body_lines) {
176
186
  this.body.parse_more(bodyLine)
177
187
  }
178
188
  }
189
+
190
+ for (const bodyLine of body_lines) {
191
+ if (!this.discard_data) this.message_stream.add_line(Buffer.from(`${bodyLine}\n`))
192
+ }
179
193
  }
180
194
  if (this.header_pos && this.parse_body) {
181
195
  const line = this.add_dot_stuffing_and_ensure_crlf_newlines(this.body.parse_end())
@@ -195,22 +209,21 @@ class Transaction {
195
209
 
196
210
  add_header(key, value) {
197
211
  this.header.add_end(key, value)
198
- if (this.header_pos > 0) this.reset_headers()
212
+ if (this.found_hb_sep) this.reset_headers()
199
213
  }
200
214
 
201
215
  add_leading_header(key, value) {
202
216
  this.header.add(key, value)
203
- if (this.header_pos > 0) this.reset_headers()
217
+ if (this.found_hb_sep) this.reset_headers()
204
218
  }
205
219
 
206
220
  reset_headers() {
207
- const header_lines = this.header.lines()
208
- this.header_pos = header_lines.length
221
+ this.header_pos = this.header.header_list ? this.header.header_list.length : -1
209
222
  }
210
223
 
211
224
  remove_header(key) {
212
225
  this.header.remove(key)
213
- if (this.header_pos > 0) this.reset_headers()
226
+ if (this.found_hb_sep) this.reset_headers()
214
227
  }
215
228
 
216
229
  attachment_hooks(start, data, end) {
@@ -230,6 +243,16 @@ class Transaction {
230
243
  add_body_filter(ct_match, filter) {
231
244
  this.parse_body = true
232
245
  this.body_filters.push({ ct_match, filter })
246
+ if (this.body) {
247
+ this.body.add_filter((ct, enc, buf) => {
248
+ if (!ct) return buf
249
+ const ct_lc = String(ct).toLowerCase().trim()
250
+ const re_match = util.types.isRegExp(ct_match) && ct_match.test(ct_lc)
251
+ const ct_begins = ct_lc.indexOf(String(ct_match).toLowerCase()) === 0
252
+ if (re_match || ct_begins) return filter(ct, enc, buf) || buf
253
+ return buf
254
+ })
255
+ }
233
256
  }
234
257
 
235
258
  incr_mime_count(line) {
package/config/me DELETED
@@ -1 +0,0 @@
1
- home.simerson.net
@@ -1,10 +0,0 @@
1
- [rabbitmq]
2
- exchangeName = emailMessages
3
- server_ip = localhost
4
- server_port = 5672
5
- queueName = email
6
- deliveryMode = 2
7
- confirm = true
8
- durable = true
9
- autoDelete = false
10
- exchangeType = direct
@@ -1,19 +0,0 @@
1
- [rabbitmq]
2
- host = localhost
3
- port = 5672
4
- user = guest
5
- password = guest
6
- exchangeName = email_messages
7
- exchangeType = direct
8
- queueName = emails
9
- deliveryMode = 2
10
- confirm = true
11
- durable = true
12
- autoDelete = false
13
-
14
- ; Optional queue arguments
15
- ; [queue_args]
16
- ; x-dead-letter-exchange =
17
- ; x-dead-letter-routing-key = emails_dlq
18
- ; x-overflow = reject-publish
19
- ; x-queue-type = quorum
@@ -1,23 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIID3zCCAsegAwIBAgIULzqgBA7/eKhkpsSvZ3OzpAWLkYEwDQYJKoZIhvcNAQEL
3
- BQAwfzELMAkGA1UEBhMCVVMxEzARBgNVBAgMCldhc2hpbmd0b24xEjAQBgNVBAcM
4
- CVNob3JlbGluZTENMAsGA1UECgwEVE5QSTEaMBgGA1UEAwwRaG9tZS5zaW1lcnNv
5
- bi5uZXQxHDAaBgkqhkiG9w0BCQEWDW1hdHRAdG5waS5uZXQwHhcNMjQwNDI3MDM1
6
- MzI2WhcNMzAwNDI2MDM1MzI2WjB/MQswCQYDVQQGEwJVUzETMBEGA1UECAwKV2Fz
7
- aGluZ3RvbjESMBAGA1UEBwwJU2hvcmVsaW5lMQ0wCwYDVQQKDARUTlBJMRowGAYD
8
- VQQDDBFob21lLnNpbWVyc29uLm5ldDEcMBoGCSqGSIb3DQEJARYNbWF0dEB0bnBp
9
- Lm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKotMDxPuAU+ygZy
10
- 82wBMmzo7bFuM4sV1jKTuoNpIus4j98Y/uIHVc0v0A9nGYkwb4Emo5vmcF6MntHH
11
- ICUTgN31W8YT0gDyyU4JdB+QHIxdMLtspDildH9wJKDxz43orOv6dsU4m542Fbk0
12
- E7lnh9GV1CoHlYRcmA8KGH9jfCjfyBuW8rLRF5QLE13pFDJkJl11GKm71w8XPk9h
13
- YuFvDsxhMDXDqaYdaLLQnE6NL7/fBF+31A/5+6VsHst0S8/WMvua67vxHbzGrw2i
14
- zAVkyciZ/peA132krkNXNgkjKusOfJheZYpYqzPSjEmsSvKayfuf1YByz060osXC
15
- 0Tcd4usCAwEAAaNTMFEwHQYDVR0OBBYEFB7paKGFiG7kJfH4VljMNUa9+VURMB8G
16
- A1UdIwQYMBaAFB7paKGFiG7kJfH4VljMNUa9+VURMA8GA1UdEwEB/wQFMAMBAf8w
17
- DQYJKoZIhvcNAQELBQADggEBAJBhuhIi36wfDbDn0DvJXKEgukUv5dnxc8HYf8CN
18
- ep51uOXQ2zBdd5A7+QNW52z29GlaLkMWgZJLUvk3v98dmGFv1DUMmAMVQeAuufDx
19
- VIdRE/d6W/ynDqJ4l+IBmcczGEK0FXYh2qoLmmwybD3G0eGgSdPFICZv6eJTsBAz
20
- X7F1MSORPSSVLdqP87O3Z2bR9TCSnIbie9sR8R7+ux62lbRiKR4qjcT0u4yn4z9q
21
- 0iqd4JC/m9YlgHNeSX0mZFT/oym4bdgPgkG/whjjDw5YpixYh5DVyEd8TeVQoNuV
22
- +8XoYYcTscSeMzu/DXs9kP87u03uJzq3qjz+T5GZ6bAQsMw=
23
- -----END CERTIFICATE-----
@@ -1,28 +0,0 @@
1
- -----BEGIN PRIVATE KEY-----
2
- MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCqLTA8T7gFPsoG
3
- cvNsATJs6O2xbjOLFdYyk7qDaSLrOI/fGP7iB1XNL9APZxmJMG+BJqOb5nBejJ7R
4
- xyAlE4Dd9VvGE9IA8slOCXQfkByMXTC7bKQ4pXR/cCSg8c+N6Kzr+nbFOJueNhW5
5
- NBO5Z4fRldQqB5WEXJgPChh/Y3wo38gblvKy0ReUCxNd6RQyZ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KzhWmYqqOSpmdIp3rFtDOFMQKBgQCP
22
- jqfXSBccFCgaApf7aEcFLknYGz7MEe8AobSvKAl96GxQMLK41AA6G8K74oaU9N6b
23
- 8kN01WvTjRsIahmLKy/ptkEFzYpRSB7llNNkNi9T4TsZVaCIdwDCjA6nwBNGVWSy
24
- Mvh5h149gZIrAuHZxjBlDpPU/pdTp1fjjmAeGtDNuQKBgHuKQaE5AYqBmeZUoGPP
25
- AsvnSvBt9ZY+vCjUK255s7CPWrA5kN4EZWXGB9EBYNit80CvkaNAK1jsR5qErNA0
26
- HGUfBIIsUAoOV9VdeN5PoYsE4dqxlpRvuEJpgXzk4KATSdBxP7jAs2SepVlBExa9
27
- yLRsVL/PYvEykaKHAyS2dwp4
28
- -----END PRIVATE KEY-----
@@ -1,34 +0,0 @@
1
- # queue/rabbitmq
2
-
3
- This plugin delivers mails to rabbitmq queue for further processing.
4
-
5
- ## Configuration
6
-
7
- - `config/rabbitmq.ini`
8
- This config file provides server address and port of rabbitmq server to deliver with other configs of queues and exchange.
9
-
10
- Example:
11
-
12
- [rabbitmq]
13
- ; This is name of exchange.
14
- exchangeName = emailMessages
15
- ; ip and port of the server.
16
- server_ip = localhost
17
- server_port = 5672
18
- ; user and password
19
- user = guest
20
- password = guest
21
- ; name of the queue which reader will read
22
- queueName = email
23
- ; This is for making it persistant while publishing message
24
- deliveryMode = 2
25
- ; If true it will require ack for marking it complete from worker
26
- confirm = true
27
- ; Again for persistance passed while creating queue
28
- durable = true
29
- ; if true will delete queue if publisher quits
30
- autoDelete = false
31
- ; type of the exchange
32
- exchangeType = direct
33
-
34
- More information about rabbitmq can be found at https://www.rabbitmq.com/
@@ -1,51 +0,0 @@
1
- # queue/rabbitmq_amqplib
2
-
3
- This plugin delivers emails to RabbitMQ queue for further processing. Based on `queue/rabbitmq` but using `amqplib`.
4
-
5
- ## Dependency
6
-
7
- - `amqplib` - https://github.com/squaremo/amqp.node
8
-
9
- ## Configuration
10
-
11
- - `config/rabbitmq.ini` - Connection, exchange and queue settings
12
-
13
- Example:
14
-
15
- [rabbitmq]
16
- ; Connection
17
- ; Protocol. Either "amqp" or "amqps"
18
- protocol = amqp
19
- host = localhost
20
- port = 5672
21
- ;Virtual Host. Start with "/". Leave blank or not use if you don't want to use virtual hosts.
22
- vhost = /haraka
23
- ;Credentials
24
- user = guest
25
- password = guest
26
- ; Exchange
27
- exchangeName = email_messages
28
- exchangeType = direct
29
- ; Queue
30
- queueName = emails
31
- confirm = true
32
- durable = true
33
- autoDelete = false
34
- ; Message
35
- deliveryMode = 2
36
- priority = 1
37
-
38
- ; Optional exchange arguments
39
- ; More information about exchange x-arguments can be found at https://www.rabbitmq.com/docs/exchanges#optional-arguments
40
- [exchange_args]
41
- alternate-exchange =
42
-
43
- ; Optional queue arguments
44
- ; More information about queue x-arguments can be found at https://www.rabbitmq.com/queues.html#optional-arguments
45
- [queue_args]
46
- x-dead-letter-exchange =
47
- x-dead-letter-routing-key = emails_dlq
48
- x-overflow = reject-publish
49
- x-queue-type = quorum
50
-
51
- More information about RabbitMQ can be found at https://www.rabbitmq.com/
@@ -1,141 +0,0 @@
1
- const amqp = require('amqp')
2
-
3
- let rabbitqueue
4
- let exchangeName
5
- let queueName
6
- let deliveryMode
7
- let connExchange_
8
- let connQueue_
9
- let routing_
10
- exports.exchangeMapping = {}
11
-
12
- //This method registers the hook and try to initialize the connection to rabbitmq server for later use.
13
- exports.register = function () {
14
- this.logdebug('About to connect and initialize queue object')
15
- this.init_rabbitmq_server()
16
- this.logdebug(`Finished initiating : ${exports.exchangeMapping[exchangeName + queueName]}`)
17
- }
18
-
19
- //Actual magic of publishing message to rabbit when email comes happen here.
20
- exports.hook_queue = function (next, connection) {
21
- if (!connection?.transaction) return next()
22
-
23
- //Calling the get_data method and when it gets the data on callback, publish the message to queue with routing key.
24
- connection.transaction.message_stream.get_data((buffere) => {
25
- const exchangeData = exports.exchangeMapping[exchangeName + queueName]
26
- this.logdebug(`Sending the data: ${queueName} Routing : ${exchangeData} exchange :${connExchange_}`)
27
- if (connExchange_ && routing_) {
28
- //This is publish function of rabbitmq amqp library, currently direct queue is configured and routing is fixed.
29
- //Needs to be changed.
30
- connExchange_.publish(routing_, buffere, { deliveryMode }, (error) => {
31
- if (error) {
32
- //There was some error while sending the email to queue.
33
- this.logdebug('queueFailure: #{JSON.stringify(error)}')
34
- exports.init_rabbitmq_server()
35
- next()
36
- } else {
37
- //Queueing was successful, send ok as reply
38
- this.logdebug('queueSuccess')
39
- next(OK, 'Successfully Queued! in rabbitmq')
40
- }
41
- })
42
- } else {
43
- //Seems like connExchange is not defined , lets create one for next call
44
- exports.init_rabbitmq_server()
45
- next()
46
- }
47
- })
48
- }
49
-
50
- //This initializes the connection to rabbitmq server, It reads values from rabbitmq.ini file in config directory.
51
- exports.init_rabbitmq_server = function () {
52
- // this is called during init of rabbitmq
53
-
54
- //Read the config file rabbitmq
55
- const config = this.config.get('rabbitmq.ini')
56
- //Just putting the defaults
57
- const options = {}
58
- let confirm = true
59
- let durable = true
60
- let autoDelete = false
61
- let exchangeType = 'direct'
62
-
63
- //Getting the values from config file rabbitmq.ini
64
- if (config.rabbitmq) {
65
- options.host = config.rabbitmq.server_ip || '127.0.0.1'
66
- options.port = config.rabbitmq.server_port || '5672'
67
- options.login = config.rabbitmq.user || 'guest'
68
- options.password = config.rabbitmq.password || 'guest'
69
- exchangeName = config.rabbitmq.exchangeName || 'emailMessages'
70
- exchangeType = config.rabbitmq.exchangeType || 'direct'
71
- confirm = config.rabbitmq.confirm === 'true' || true
72
- durable = config.rabbitmq.durable === 'true' || true
73
- autoDelete = config.rabbitmq.autoDelete === 'true' || false
74
- deliveryMode = config.rabbitmq.deliveryMode || 2
75
- queueName = config.rabbitmq.queueName || 'emails'
76
- } else {
77
- //If config file is not available , lets get the default values
78
- queueName = 'emails'
79
- exchangeName = 'emailMessages'
80
- deliveryMode = 2
81
- durable = true
82
- }
83
-
84
- //Create connection to the rabbitmq server
85
- this.logdebug('About to Create connection with server')
86
- rabbitqueue = amqp.createConnection(options)
87
-
88
- //Declaring listerner on error on connection.
89
- rabbitqueue.on('error', (error) => {
90
- this.logerror(`There was some error on the connection : ${error}`)
91
- })
92
-
93
- //Declaring listerner on close on connection.
94
- rabbitqueue.on('close', (close) => {
95
- this.logdebug(` Connection is being closed : ${close}`)
96
- })
97
-
98
- /* Declaring the function to perform when connection is established and ready, function involves like:
99
- * 1. Creating or connecting to Exchange.
100
- * 2. Creating or connecting to Queue.
101
- * 3. Binding the Exchange and Queue.
102
- * 4. Saving some variables in global to be used while publishing message.
103
- */
104
-
105
- rabbitqueue.on('ready', () => {
106
- this.logdebug('Connection is ready, will try making exchange')
107
- // Now connection is ready will try to open exchange with config data.
108
- rabbitqueue.exchange(exchangeName, { type: exchangeType, confirm, durable }, (connExchange) => {
109
- this.logdebug(`connExchange with server ${connExchange} autoDelete : ${autoDelete}`)
110
-
111
- //Exchange is now open, will try to open queue.
112
- return rabbitqueue.queue(queueName, { autoDelete, durable }, (connQueue) => {
113
- this.logdebug(`connQueue with server ${connQueue}`)
114
-
115
- //Creating the Routing key to bind the queue and exchange.
116
- const routing = `${queueName}Routing`
117
-
118
- // Will try to bing queue and exchange which was created above.
119
- connQueue.bind(connExchange, routing)
120
- const key = exchangeName + queueName
121
-
122
- //Save the variables for publising later.
123
- if (!exports.exchangeMapping[key]) {
124
- exports.exchangeMapping[key] = []
125
- }
126
- connExchange_ = connExchange
127
- connQueue_ = connQueue
128
- routing_ = routing
129
- exports.exchangeMapping[key].push({
130
- exchange: connExchange_,
131
- queue: connQueue_,
132
- routing: routing_,
133
- queueName,
134
- })
135
- this.logdebug(
136
- `exchange: ${exchangeName}, queue: ${queueName} exchange : ${connExchange_} queue : ${connQueue_}`,
137
- )
138
- })
139
- })
140
- })
141
- }
@@ -1,96 +0,0 @@
1
- // queue/rabbitmq_amqplib
2
-
3
- const amqp = require('amqplib/callback_api')
4
-
5
- let channel
6
- let queue
7
- let deliveryMode
8
- let priority
9
-
10
- exports.register = function () {
11
- this.init_amqp_connection()
12
- }
13
-
14
- exports.rabbitmq_queue = function (next, connection) {
15
- if (!connection?.transaction) return next()
16
-
17
- connection.transaction.message_stream.get_data((str) => {
18
- const sendOptions = { deliveryMode }
19
- if (priority != null) {
20
- sendOptions.priority = priority
21
- }
22
- if (channel?.sendToQueue(queue, str, sendOptions)) {
23
- return next(OK)
24
- } else {
25
- this.logerror('Failed to queue to rabbitmq')
26
- return next()
27
- }
28
- })
29
- }
30
-
31
- exports.init_amqp_connection = function () {
32
- const cfg = this.config.get('rabbitmq.ini').rabbitmq
33
-
34
- const protocol = cfg.protocol || 'amqp'
35
- const host = cfg.host || '127.0.0.1'
36
- const port = cfg.port || '5672'
37
- const vhost = cfg.vhost || ''
38
- const user = cfg.user || 'guest'
39
- const password = cfg.password || 'guest'
40
- const exchangeName = cfg.exchangeName || 'emailMessages'
41
- const exchangeType = cfg.exchangeType || 'direct'
42
- const queueName = cfg.queueName || 'emails'
43
- const durable = cfg.durable === 'true' || true
44
- // var confirm = cfg.confirm === "true" || true;
45
- const autoDelete = cfg.autoDelete === 'true' || false
46
- deliveryMode = cfg.deliveryMode || 2
47
- priority = cfg.priority
48
-
49
- amqp.connect(
50
- `${protocol}://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:${port}${vhost}`,
51
- (err, conn) => {
52
- if (err) {
53
- this.logerror(`Connection to rabbitmq failed: ${err}`)
54
- return
55
- }
56
- // TODO: if !confirm conn.createChannel...
57
- conn.createConfirmChannel((err2, ch) => {
58
- if (err2) {
59
- this.logerror(`Error creating rabbitmq channel: ${err2}`)
60
- return conn.close()
61
- }
62
- ch.assertExchange(
63
- exchangeName,
64
- exchangeType,
65
- {
66
- durable,
67
- arguments: this.config.get('rabbitmq.ini').exchange_args,
68
- },
69
- (err3, ok) => {
70
- if (err3) {
71
- this.logerror(`Error asserting rabbitmq exchange: ${err3}`)
72
- return conn.close()
73
- }
74
- ch.assertQueue(
75
- queueName,
76
- {
77
- durable,
78
- autoDelete,
79
- arguments: this.config.get('rabbitmq.ini').queue_args,
80
- },
81
- (err4, ok2) => {
82
- if (err4) {
83
- this.logerror(`Error asserting rabbitmq queue: ${err4}`)
84
- return conn.close()
85
- }
86
- queue = ok2.queue
87
- channel = ch
88
- this.register_hook('queue', 'rabbitmq_queue')
89
- },
90
- )
91
- },
92
- )
93
- })
94
- },
95
- )
96
- }
@@ -1,23 +0,0 @@
1
- -----BEGIN EC PARAMETERS-----
2
- BggqhkjOPQMBBw==
3
- -----END EC PARAMETERS-----
4
- -----BEGIN EC PRIVATE KEY-----
5
- MHcCAQEEIIDhiI5q6l7txfMJ6kIEYjK12EFcHLvDIkfWIwzdZBsloAoGCCqGSM49
6
- AwEHoUQDQgAEZg2nHEFy9nquFPF3DQyQE28e/ytjXeb4nD/8U+L4KHKFtglaX3R4
7
- uZ+5JcwfcDghpL4Z8h4ouUD/xqe957e2+g==
8
- -----END EC PRIVATE KEY-----
9
- -----BEGIN CERTIFICATE-----
10
- MIICaTCCAg+gAwIBAgIUEDa9VX16wCdo97WvIk7jyEBz1wQwCgYIKoZIzj0EAwIw
11
- gYkxCzAJBgNVBAYTAlVTMRMwEQYDVQQIDApXYXNoaW5ndG9uMRAwDgYDVQQHDAdT
12
- ZWF0dGxlMRQwEgYDVQQKDAtIYXJha2EgTWFpbDEXMBUGA1UEAwwObWFpbC5oYXJh
13
- a2EuaW8xJDAiBgkqhkiG9w0BCQEWFWhhcmFrYS5tYWlsQGdtYWlsLmNvbTAeFw0y
14
- MTEwMTQwNjQxMTlaFw0yMjEwMTQwNjQxMTlaMIGJMQswCQYDVQQGEwJVUzETMBEG
15
- A1UECAwKV2FzaGluZ3RvbjEQMA4GA1UEBwwHU2VhdHRsZTEUMBIGA1UECgwLSGFy
16
- YWthIE1haWwxFzAVBgNVBAMMDm1haWwuaGFyYWthLmlvMSQwIgYJKoZIhvcNAQkB
17
- FhVoYXJha2EubWFpbEBnbWFpbC5jb20wWTATBgcqhkjOPQIBBggqhkjOPQMB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