Haraka 3.0.3 → 3.0.5

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 (239) hide show
  1. package/.eslintrc.yaml +4 -9
  2. package/CONTRIBUTORS.md +11 -0
  3. package/Changes.md +1397 -1213
  4. package/Plugins.md +117 -105
  5. package/README.md +4 -13
  6. package/bin/haraka +198 -298
  7. package/config/auth_flat_file.ini +1 -0
  8. package/config/dhparams.pem +8 -0
  9. package/config/mail_from.is_resolvable.ini +4 -2
  10. package/config/me +1 -0
  11. package/config/outbound.ini +0 -2
  12. package/config/plugins +35 -36
  13. package/config/smtp.ini +1 -1
  14. package/config/smtp.json +17 -0
  15. package/config/tls.ini +2 -0
  16. package/config/tls_cert.pem +23 -0
  17. package/config/tls_key.pem +28 -0
  18. package/connection.js +46 -73
  19. package/contrib/bsd-rc.d/haraka +3 -1
  20. package/contrib/plugin2npm.sh +6 -36
  21. package/docs/CoreConfig.md +2 -2
  22. package/docs/Logging.md +7 -21
  23. package/docs/Outbound.md +104 -201
  24. package/docs/Plugins.md +2 -2
  25. package/docs/Transaction.md +59 -82
  26. package/docs/plugins/queue/smtp_proxy.md +5 -10
  27. package/docs/plugins/tls.md +37 -9
  28. package/endpoint.js +16 -13
  29. package/haraka.js +10 -14
  30. package/host_pool.js +5 -5
  31. package/http/html/index.html +6 -5
  32. package/line_socket.js +3 -4
  33. package/logger.js +44 -28
  34. package/outbound/client_pool.js +27 -23
  35. package/outbound/config.js +4 -6
  36. package/outbound/fsync_writestream.js +1 -1
  37. package/outbound/hmail.js +178 -218
  38. package/outbound/index.js +86 -99
  39. package/outbound/qfile.js +1 -1
  40. package/outbound/queue.js +51 -44
  41. package/outbound/timer_queue.js +3 -2
  42. package/outbound/tls.js +19 -7
  43. package/package.json +60 -51
  44. package/plugins/.eslintrc.yaml +0 -6
  45. package/plugins/auth/auth_base.js +4 -2
  46. package/plugins/auth/auth_proxy.js +14 -12
  47. package/plugins/auth/auth_vpopmaild.js +1 -1
  48. package/plugins/block_me.js +1 -1
  49. package/plugins/data.signatures.js +2 -4
  50. package/plugins/early_talker.js +2 -1
  51. package/plugins/mail_from.is_resolvable.js +65 -135
  52. package/plugins/queue/deliver.js +4 -5
  53. package/plugins/queue/lmtp.js +11 -12
  54. package/plugins/queue/qmail-queue.js +2 -2
  55. package/plugins/queue/quarantine.js +2 -2
  56. package/plugins/queue/rabbitmq.js +16 -17
  57. package/plugins/queue/smtp_forward.js +3 -3
  58. package/plugins/queue/smtp_proxy.js +10 -1
  59. package/plugins/queue/test.js +2 -2
  60. package/plugins/rcpt_to.host_list_base.js +5 -5
  61. package/plugins/rcpt_to.in_host_list.js +2 -2
  62. package/plugins/relay.js +6 -7
  63. package/plugins/reseed_rng.js +1 -1
  64. package/plugins/status.js +37 -33
  65. package/plugins/tls.js +2 -2
  66. package/plugins/xclient.js +3 -2
  67. package/plugins.js +50 -54
  68. package/run_tests +3 -30
  69. package/server.js +190 -190
  70. package/smtp_client.js +30 -23
  71. package/{tests → test}/config/plugins +0 -2
  72. package/{tests → test}/config/smtp.ini +3 -1
  73. package/test/config/tls/example.com/_.example.com.key +28 -0
  74. package/test/config/tls/example.com/example.com.crt +25 -0
  75. package/{tests/loud → test}/config/tls.ini +4 -2
  76. package/test/connection.js +302 -0
  77. package/test/endpoint.js +94 -0
  78. package/{tests → test}/fixtures/line_socket.js +1 -1
  79. package/{tests → test}/fixtures/util_hmailitem.js +19 -25
  80. package/{tests → test}/host_pool.js +42 -57
  81. package/test/logger.js +258 -0
  82. package/test/outbound/hmail.js +141 -0
  83. package/test/outbound/index.js +220 -0
  84. package/test/outbound/qfile.js +126 -0
  85. package/test/outbound_bounce_net_errors.js +142 -0
  86. package/{tests → test}/outbound_bounce_rfc3464.js +110 -122
  87. package/test/plugins/auth/auth_base.js +484 -0
  88. package/test/plugins/auth/auth_vpopmaild.js +83 -0
  89. package/test/plugins/early_talker.js +104 -0
  90. package/test/plugins/mail_from.is_resolvable.js +35 -0
  91. package/test/plugins/queue/smtp_forward.js +206 -0
  92. package/test/plugins/rcpt_to.host_list_base.js +122 -0
  93. package/test/plugins/rcpt_to.in_host_list.js +193 -0
  94. package/test/plugins/relay.js +303 -0
  95. package/test/plugins/status.js +130 -0
  96. package/test/plugins/tls.js +70 -0
  97. package/test/plugins.js +228 -0
  98. package/test/rfc1869.js +73 -0
  99. package/test/server.js +491 -0
  100. package/test/smtp_client.js +299 -0
  101. package/test/tls_socket.js +277 -0
  102. package/test/transaction.js +270 -0
  103. package/tls_socket.js +202 -252
  104. package/transaction.js +8 -23
  105. package/CONTRIBUTING.md +0 -1
  106. package/bin/dkimverify +0 -40
  107. package/config/access.domains +0 -13
  108. package/config/attachment.ctype.regex +0 -2
  109. package/config/attachment.filename.regex +0 -1
  110. package/config/avg.ini +0 -5
  111. package/config/bounce.ini +0 -15
  112. package/config/data.headers.ini +0 -61
  113. package/config/dkim/dkim_key_gen.sh +0 -78
  114. package/config/dkim_sign.ini +0 -4
  115. package/config/dkim_verify.ini +0 -7
  116. package/config/dnsbl.ini +0 -23
  117. package/config/greylist.ini +0 -43
  118. package/config/helo.checks.ini +0 -52
  119. package/config/messagesniffer.ini +0 -18
  120. package/config/spamassassin.ini +0 -56
  121. package/dkim.js +0 -614
  122. package/docs/plugins/avg.md +0 -35
  123. package/docs/plugins/bounce.md +0 -69
  124. package/docs/plugins/clamd.md +0 -147
  125. package/docs/plugins/esets.md +0 -8
  126. package/docs/plugins/greylist.md +0 -90
  127. package/docs/plugins/helo.checks.md +0 -135
  128. package/docs/plugins/messagesniffer.md +0 -163
  129. package/docs/plugins/spamassassin.md +0 -180
  130. package/outbound/mx_lookup.js +0 -70
  131. package/plugins/auth/auth_ldap.js +0 -3
  132. package/plugins/avg.js +0 -162
  133. package/plugins/backscatterer.js +0 -25
  134. package/plugins/bounce.js +0 -381
  135. package/plugins/clamd.js +0 -382
  136. package/plugins/data.uribl.js +0 -4
  137. package/plugins/dkim_sign.js +0 -395
  138. package/plugins/dkim_verify.js +0 -62
  139. package/plugins/dns_list_base.js +0 -221
  140. package/plugins/dnsbl.js +0 -146
  141. package/plugins/dnswl.js +0 -58
  142. package/plugins/esets.js +0 -71
  143. package/plugins/graph.js +0 -5
  144. package/plugins/greylist.js +0 -645
  145. package/plugins/helo.checks.js +0 -533
  146. package/plugins/messagesniffer.js +0 -381
  147. package/plugins/rcpt_to.ldap.js +0 -3
  148. package/plugins/rcpt_to.max_count.js +0 -24
  149. package/plugins/spamassassin.js +0 -384
  150. package/tests/config/dkim/example.com/dns +0 -29
  151. package/tests/config/dkim/example.com/private +0 -6
  152. package/tests/config/dkim/example.com/public +0 -4
  153. package/tests/config/dkim/example.com/selector +0 -1
  154. package/tests/config/dkim.private.key +0 -6
  155. package/tests/config/dkim_sign.ini +0 -4
  156. package/tests/config/helo.checks.ini +0 -52
  157. package/tests/connection.js +0 -327
  158. package/tests/endpoint.js +0 -128
  159. package/tests/fixtures/vm_harness.js +0 -59
  160. package/tests/logger.js +0 -327
  161. package/tests/outbound/hmail.js +0 -112
  162. package/tests/outbound/index.js +0 -324
  163. package/tests/outbound/qfile.js +0 -67
  164. package/tests/outbound_bounce_net_errors.js +0 -173
  165. package/tests/plugins/auth/auth_base.js +0 -463
  166. package/tests/plugins/auth/auth_vpopmaild.js +0 -91
  167. package/tests/plugins/bounce.js +0 -307
  168. package/tests/plugins/clamd.js +0 -224
  169. package/tests/plugins/deprecated/relay_acl.js +0 -140
  170. package/tests/plugins/deprecated/relay_all.js +0 -59
  171. package/tests/plugins/dkim_sign.js +0 -315
  172. package/tests/plugins/dkim_signer.js +0 -108
  173. package/tests/plugins/dns_list_base.js +0 -259
  174. package/tests/plugins/dnsbl.js +0 -101
  175. package/tests/plugins/early_talker.js +0 -115
  176. package/tests/plugins/greylist.js +0 -58
  177. package/tests/plugins/helo.checks.js +0 -525
  178. package/tests/plugins/mail_from.is_resolvable.js +0 -116
  179. package/tests/plugins/queue/smtp_forward.js +0 -221
  180. package/tests/plugins/rcpt_to.host_list_base.js +0 -132
  181. package/tests/plugins/rcpt_to.in_host_list.js +0 -218
  182. package/tests/plugins/relay.js +0 -339
  183. package/tests/plugins/spamassassin.js +0 -171
  184. package/tests/plugins/status.js +0 -138
  185. package/tests/plugins/tls.js +0 -84
  186. package/tests/plugins.js +0 -247
  187. package/tests/rfc1869.js +0 -61
  188. package/tests/server.js +0 -510
  189. package/tests/smtp_client/auth.js +0 -105
  190. package/tests/smtp_client/basic.js +0 -101
  191. package/tests/smtp_client.js +0 -80
  192. package/tests/tls_socket.js +0 -333
  193. package/tests/transaction.js +0 -284
  194. /package/docs/{plugins → deprecated}/dkim_sign.md +0 -0
  195. /package/docs/{plugins → deprecated}/dkim_verify.md +0 -0
  196. /package/docs/{plugins → deprecated}/dnsbl.md +0 -0
  197. /package/docs/{plugins → deprecated}/dnswl.md +0 -0
  198. /package/{tests → test}/.eslintrc.yaml +0 -0
  199. /package/{tests → test}/config/auth_flat_file.ini +0 -0
  200. /package/{tests → test}/config/dhparams.pem +0 -0
  201. /package/{tests → test}/config/host_list +0 -0
  202. /package/{tests → test}/config/outbound_tls_cert.pem +0 -0
  203. /package/{tests → test}/config/outbound_tls_key.pem +0 -0
  204. /package/{tests → test}/config/smtp_forward.ini +0 -0
  205. /package/{tests → test}/config/tls/ec.pem +0 -0
  206. /package/{tests → test}/config/tls/haraka.local.pem +0 -0
  207. /package/{tests → test}/config/tls/mismatched.pem +0 -0
  208. /package/{tests → test}/config/tls_cert.pem +0 -0
  209. /package/{tests → test}/config/tls_key.pem +0 -0
  210. /package/{tests → test}/fixtures/todo_qfile.txt +0 -0
  211. /package/{tests → test}/installation/config/test-plugin-flat +0 -0
  212. /package/{tests → test}/installation/config/test-plugin.ini +0 -0
  213. /package/{tests → test}/installation/config/tls.ini +0 -0
  214. /package/{tests → test}/installation/node_modules/load_first/index.js +0 -0
  215. /package/{tests → test}/installation/node_modules/load_first/package.json +0 -0
  216. /package/{tests → test}/installation/node_modules/test-plugin/config/test-plugin-flat +0 -0
  217. /package/{tests → test}/installation/node_modules/test-plugin/config/test-plugin.ini +0 -0
  218. /package/{tests → test}/installation/node_modules/test-plugin/package.json +0 -0
  219. /package/{tests → test}/installation/node_modules/test-plugin/test-plugin.js +0 -0
  220. /package/{tests → test}/installation/plugins/base_plugin.js +0 -0
  221. /package/{tests → test}/installation/plugins/folder_plugin/index.js +0 -0
  222. /package/{tests → test}/installation/plugins/folder_plugin/package.json +0 -0
  223. /package/{tests → test}/installation/plugins/inherits.js +0 -0
  224. /package/{tests → test}/installation/plugins/load_first.js +0 -0
  225. /package/{tests → test}/installation/plugins/plugin.js +0 -0
  226. /package/{tests → test}/installation/plugins/tls.js +0 -0
  227. /package/{tests → test}/loud/config/dhparams.pem +0 -0
  228. /package/{tests → test}/loud/config/tls/goobered.pem +0 -0
  229. /package/{tests → test/loud}/config/tls.ini +0 -0
  230. /package/{tests → test}/mail_specimen/base64-root-part.txt +0 -0
  231. /package/{tests → test}/mail_specimen/varied-fold-lengths-preserve-data.txt +0 -0
  232. /package/{tests → test}/queue/1507509981169_1507509981169_0_61403_e0Y0Ym_1_fixed +0 -0
  233. /package/{tests → test}/queue/1507509981169_1507509981169_0_61403_e0Y0Ym_1_haraka +0 -0
  234. /package/{tests → test}/queue/1508269674999_1508269674999_0_34002_socVUF_1_haraka +0 -0
  235. /package/{tests → test}/queue/1508455115683_1508455115683_0_90253_9Q4o4V_1_haraka +0 -0
  236. /package/{tests → test}/queue/multibyte +0 -0
  237. /package/{tests → test}/queue/plain +0 -0
  238. /package/{tests → test}/queue/zero-length +0 -0
  239. /package/{tests → test}/test-queue/delete-me +0 -0
package/docs/Outbound.md CHANGED
@@ -1,71 +1,45 @@
1
- Outbound Mail with Haraka
2
- =========================
1
+ # Outbound Mail with Haraka
3
2
 
4
- A default installation of Haraka will queue outbound mail for delivery in the
5
- queue directory. Those mails will be delivered to the appropriate MX record
6
- for that domain. Mails are queued onto your disk, and will deal appropriately
7
- with temporary failures to retry delivery later.
3
+ A default installation of Haraka will queue outbound mail for delivery in the queue directory. Those mails will be delivered to the appropriate MX record for that domain. Mails are queued onto your disk, and will deal appropriately with temporary failures to retry delivery later.
8
4
 
9
- Outbound mails are defined as those that have set the `connection.relaying`
10
- flag to `true` via a plugin. The simplest way of doing that is to use SMTP
11
- AUTH, and have the client authenticate. For example using the `auth/flat_file`
12
- plugin. However it is very simple to write a custom plugin to do this.
5
+ Outbound mails are defined as those that have set the `connection.relaying` flag to `true` via a plugin. The simplest way of doing that is to use SMTP AUTH, and have the client authenticate. For example using the `auth/flat_file` plugin. The `relay` plugin provides common ways to set it and it is simple to write a custom plugin to do this.
13
6
 
14
- For statistics on outbound mail use the `process_title` plugin. See the
15
- documentation for that plugin for details.
7
+ For statistics on outbound mail use the `process_title` plugin. See the documentation for that plugin for details.
16
8
 
17
- To flush the outbound queue (for temporary failed mails) hit the Haraka master
18
- process with the SIGHUP signal (via the `kill` command line tool).
9
+ To flush the outbound queue (for temporary failed mails) hit the Haraka master process with the SIGHUP signal (via the `kill` command line tool).
19
10
 
20
- Outbound Configuration Files
21
- ----------------------------
11
+ ## Outbound Configuration Files
22
12
 
23
13
  ### outbound.ini
24
14
 
25
15
  * `disabled`
26
16
 
27
- Default: false. Allows one to temporarily disable outbound delivery, while
28
- still receiving and queuing emails. This can be changed while Haraka is
29
- running.
17
+ Default: false. Allows one to temporarily disable outbound delivery, while still receiving and queuing emails. This can be changed while Haraka is running.
30
18
 
31
19
  * `concurrency_max`
32
20
 
33
- Default: 100. Specifies the maximum concurrent connections to make. Note that
34
- if using cluster (multiple CPUs) then this will be multiplied by the number
35
- of CPUs that you have.
21
+ Default: 100. Specifies the maximum concurrent connections to make. Note that if using cluster (multiple CPUs) this will be multiplied by the number of CPUs that you have.
36
22
 
37
23
  * `enable_tls`
38
24
 
39
25
  Default: true. Switch to false to disable TLS for outbound mail.
40
26
 
41
- This uses the same `tls_key.pem` and `tls_cert.pem` files that the `TLS`
42
- plugin uses, along with other values in `tls.ini`. See the [TLS plugin
43
- docs](http://haraka.github.io/plugins/tls) for information on generating those files.
27
+ This uses the same `tls_key.pem` and `tls_cert.pem` files that the `TLS` plugin uses, along with other values in `tls.ini`. See the [TLS plugin docs][url-tls] for more information.
44
28
 
45
29
  Within `tls.ini` you can specify global options for the values `ciphers`, `minVersion`, `requestCert` and `rejectUnauthorized`, alternatively you can provide separate values by putting them under a key: `[outbound]`, such as:
46
30
 
47
- ```
31
+ ```ini
48
32
  [outbound]
49
33
  ciphers=!DES
50
34
  ```
51
35
 
52
- * `ipv6_enabled`
53
-
54
- When this has a "true" value inside (usually a `1`), it defaults to an 'AAAA'
55
- lookup first for each MX record, and uses those hosts to send email via.
56
-
57
36
  * `always_split`
58
37
 
59
- Default: false. By default, Haraka groups message recipients by domain so that
60
- messages with multiple recipients at the same domain get sent in a single SMTP
61
- session. When `always_split` is enabled, each recipient gets a queue entry and
62
- delivery in its own SMTP session. This carries a performance penalty but
63
- enables more flexibility in mail delivery and bounce handling.
38
+ Default: false. By default, Haraka groups message recipients by domain so that messages with multiple recipients at the same domain get sent in a single SMTP session. When `always_split` is enabled, each recipient gets a queue entry and delivery in its own SMTP session. This carries a performance penalty but enables more flexibility in mail delivery and bounce handling.
64
39
 
65
40
  * `received_header`
66
41
 
67
- Default: "Haraka outbound". If this text is any string except *disabled*, the
68
- string is attached as a `Received` header to all outbound mail just before it is queued.
42
+ Default: "Haraka outbound". If this text is any string except *disabled*, the string is attached as a `Received` header to all outbound mail just before it is queued.
69
43
 
70
44
  * `connect_timeout`
71
45
 
@@ -73,69 +47,50 @@ Timeout for connecting to remote servers. Default: 30s
73
47
 
74
48
  * `local_mx_ok`
75
49
 
76
- Default: false. By default, outbound to a local IP is disabled, to avoid creating
77
- outbound loops. Set this to true if you want to allow outbound to local IPs.
78
- This could be useful if you want to deliver mail to localhost on another port.
50
+ Default: false. By default, outbound to a local IP is disabled, to avoid creating mail loops. Set this to true if you want to allow outbound to local IPs. This could be useful if you want to deliver mail to private IPs or localhost on another port.
79
51
 
80
52
  * `temp_fail_intervals`
81
53
 
82
- Set this to specify the delay intervals to use between trying to re-send an email
83
- that has a temporary failure condition. The setting is a comma separated list of
84
- time spans and multipliers. The time span is a number followed by `s`, `m`, `h`, or `d` to represent seconds, minutes, hours, and days, respectively. The multiplier is an asterisk followed by an integer representing the number of times to repeat the interval.
85
- For example, the entry `1m, 5m*2, 1h*3` results in an array of delay times of
54
+ Set this to specify the delay intervals to use between trying to re-send an email that has a temporary failure condition. The setting is a comma separated list of time spans and multipliers. The time span is a number followed by `s`, `m`, `h`, or `d` to represent seconds, minutes, hours, and days, respectively. The multiplier is an asterisk followed by an integer representing the number of times to repeat the interval. For example, the entry `1m, 5m*2, 1h*3` results in an array of delay times of
86
55
  `[60,300,300,3600,3600,3600]` in seconds. The email will be bounced when the array runs out of intervals (the 7th failure in this case). Set this to `none` to bounce the email on the first temporary failure.
87
56
 
88
57
  ### outbound.bounce\_message
89
58
 
90
59
  See "Bounce Messages" below for details.
91
60
 
92
- The HMail Object
93
- ----------------
61
+ ## The HMail Object
94
62
 
95
63
  Many hooks (see below) pass in a `hmail` object.
96
64
 
97
- You likely won't ever need to call methods on this object, so they are left
98
- undocumented here.
65
+ You likely won't ever need to call methods on this object, so they are left undocumented here.
99
66
 
100
67
  The attributes of an `hmail` object that may be of use are:
101
68
 
102
69
  * path - the full path to the queue file
103
70
  * filename - the filename within the queue dir
104
71
  * num_failures - the number of times this mail has been temp failed
105
- * notes - notes you can store on a hmail object (similar to `transaction.notes`)
106
- to allow you to pass information between outbound hooks
72
+ * notes - notes you can store on a hmail object (similar to `transaction.notes`) to allow you to pass information between outbound hooks
107
73
  * todo - see below
108
74
 
109
- The ToDo Object
110
- ---------------
75
+ ## The ToDo Object
111
76
 
112
- The `todo` object contains information about how to deliver this mail. Keys
113
- you may be interested in are:
77
+ The `todo` object contains information about how to deliver this mail. Keys you may be interested in are:
114
78
 
115
- * rcpt_to - an Array of `Address`[1] objects - the rfc.2821 recipients of this mail
116
- * mail_from - an `Address`[1] object - the rfc.2821 sender of this mail
79
+ * rcpt_to - an Array of `Address`<sup>[1](#fn1)</sup> objects - the rfc.2821 recipients of this mail
80
+ * mail_from - an Address<sup>[1](#fn1)</sup> object - the rfc.2821 sender of this mail
117
81
  * domain - the domain this mail is going to (see `always_split` above)
118
- * notes - the original transaction.notes for this mail, also contains the
119
- following useful keys:
120
- ** outbound_ip - the IP address to bind to (do not set manually,
121
- use the `get_mx` hook)
122
- ** outbound_helo - the EHLO domain to use (again, do not set manually)
82
+ * notes - the original transaction.notes for this mail, also contains the following useful keys:
83
+ * outbound_ip - the IP address to bind to (do not set manually, use the `get_mx` hook)
84
+ * outbound_helo - the EHLO domain to use (again, do not set manually)
123
85
  * queue_time - the epoch milliseconds time when this mail was queued
124
86
  * uuid - the original transaction.uuid
125
87
  * force_tls - if true, this mail will be sent over TLS or defer
126
88
 
127
-
128
- Outbound Mail Hooks
129
- -------------------
89
+ ## Outbound Mail Hooks
130
90
 
131
91
  ### The queue\_outbound hook
132
92
 
133
- The first hook that is called prior to queueing an outbound mail is the
134
- `queue_outbound` hook. Only if all these hooks return `CONT` (or if there are
135
- no hooks) will the mail be queued for outbound delivery. A return of `OK` will
136
- indicate that the mail has been queued in some custom manner for outbound
137
- delivery. Any of the `DENY` return codes will cause the message to be
138
- appropriately rejected.
93
+ The first hook that is called prior to queueing an outbound mail is the `queue_outbound` hook. Only if all these hooks return `CONT` (or if there are no hooks) will the mail be queued for outbound delivery. A return of `OK` will indicate that the mail has been queued in some custom manner for outbound delivery. Any of the `DENY` return codes will cause the message to be appropriately rejected.
139
94
 
140
95
  ### The send\_email hook
141
96
 
@@ -149,63 +104,31 @@ Respond with `next(DELAY, delay_seconds)` to defer sending the email at this tim
149
104
 
150
105
  Parameters: `next, hmail, domain`
151
106
 
152
- Upon starting delivery the `get_mx` hook is called, with the parameter set to
153
- the domain in question (for example a mail to `user@example.com` will call the
154
- `get_mx` hook with `(next, hmail, domain)` as parameters). This is to allow
155
- you to implement a custom handler to find MX records. For most installations
156
- there is no reason to implement this hook - Haraka will find the correct MX
157
- records for you.
158
-
159
- The MX record is sent via next(OK, mx) and can be one of:
160
-
161
- * A string of one of the following formats:
162
- * hostname
163
- * hostname:port
164
- * ipaddress
165
- * ipaddress:port
166
- * An MX object of the form: `{priority: 0, exchange: hostname}` with the
167
- following optional properies:
168
- * `port` to specify an alternate port
169
- * `bind` to specify an outbound IP address to bind to
170
- * `bind_helo` to specify an outbound helo for IP address to bind to
171
- * `using_lmtp` boolean to specify that delivery should be attempted using
172
- LMTP instead of SMTP.
173
- * `auth_user` to specify an AUTH username (required if AUTH is desired)
174
- * `auth_pass` to specify an AUTH password (required if AUTH is desired)
175
- * `auth_type` to specify an AUTH type that should be used with the MX.
176
- If this is not specified then Haraka will pick an appropriate method.
177
- * A list of MX objects in an array, each in the same format as above.
107
+ Upon starting delivery the `get_mx` hook is called, with the parameter set to the domain in question (for example a mail to `user@example.com` will call the `get_mx` hook with `(next, hmail, domain)` as parameters). This is to allow you to implement a custom handler to find MX records. For most installations there is no reason to implement this hook - Haraka will find the MX records via DNS.
108
+
109
+ The MX is sent via next(OK, mx). `mx` is a [HarakaMx][url-harakamx] object, an array of HarakaMx objects, or any suitable HarakaMx input.
178
110
 
179
111
  ### The deferred hook
180
112
 
181
113
  Parameters: `next, hmail, {delay: ..., err: ...}`
182
114
 
183
- If the mail is temporarily deferred, the `deferred` hook is called. The hook
184
- parameter is an object with keys: `delay` and `err`, which explain the delay
185
- (in seconds) and error message.
115
+ If the mail is temporarily deferred, the `deferred` hook is called. The hook parameter is an object with keys: `delay` and `err`, which explain the delay (in seconds) and error message.
186
116
 
187
- If you want to stop at this point, and drop the mail completely, then you
188
- can call `next(OK)`.
117
+ If you want to stop at this point, and drop the mail completely, then you can call `next(OK)`.
189
118
 
190
- If you want to change the delay, then call `next(DENYSOFT, delay_in_seconds)`.
191
- Using this you can define a custom delay algorithm indexed by
192
- `hmail.num_failures`.
119
+ If you want to change the delay, then call `next(DENYSOFT, delay_in_seconds)`. Using this you can define a custom delay algorithm indexed by `hmail.num_failures`.
193
120
 
194
121
  ### The bounce hook
195
122
 
196
123
  Parameters: `next, hmail, error`
197
124
 
198
- If the mail completely bounces then the `bounce` hook is called. This is *not*
199
- called if the mail is issued a temporary failure (a 4xx error code). The hook
200
- parameter is the error message received from the remote end as an `Error` object.
201
- The object may also have the following properties:
125
+ If the mail completely bounces then the `bounce` hook is called. This is *not* called if the mail is issued a temporary failure (a 4xx error code). The hook parameter is the error message received from the remote end as an `Error` object. The object may also have the following properties:
202
126
 
203
127
  * mx - the MX object that caused the bounce
204
128
  * deferred_rcpt - the deferred recipients that eventually bounced
205
129
  * bounced_rcpt - the bounced recipients
206
130
 
207
- If you do not wish to have a bounce message sent to the originating sender of the
208
- email then you can return `OK` from this hook to stop it from sending a bounce message.
131
+ If you do not wish to have a bounce message sent to the originating sender of the email then you can return `OK` from this hook to stop it from sending a bounce message.
209
132
 
210
133
  ### The delivered hook
211
134
 
@@ -213,58 +136,34 @@ Parameters: `next, hmail, params`
213
136
 
214
137
  Params is a list of: `[host, ip, response, delay, port, mode, ok_recips, secured]`
215
138
 
216
- When mails are successfully delivered to the remote end then the `delivered`
217
- hook is called. The return codes from this hook have no effect, so it is only
218
- useful for logging the fact that a successful delivery occurred.
139
+ When mails are successfully delivered to the remote end then the `delivered` hook is called. The return codes from this hook have no effect, so it is only useful for logging the fact that a successful delivery occurred.
219
140
 
220
141
  * `host` - Hostname of the MX that the message was delivered to,
221
142
  * `ip` - IP address of the host that the message was delivered to,
222
- * `response` - Variable contains the SMTP response text returned by the host
223
- that received the message and will typically contain the remote queue ID and
224
- * `delay` - Time taken between the queue file being created and the
225
- message being delivered.
143
+ * `response` - Variable contains the SMTP response text returned by the host that received the message and will typically contain the remote queue ID and
144
+ * `delay` - Time taken between the queue file being created and the message being delivered.
226
145
  * `port` - Port number that the message was delivered to.
227
146
  * `mode` - Shows whether SMTP or LMTP was used to deliver the mail.
228
- * `ok_recips` - an `Address`[1] array containing all of the recipients that were
229
- successfully delivered to.
147
+ * `ok_recips` - an `Address`<sup>[1](#fn1)</sup> array containing all of the recipients that were successfully delivered to.
230
148
  * `secured` - A boolean denoting if the connection used TLS or not.
231
149
 
232
- Outbound IP address
233
- -------------------
150
+ ## Outbound IP address
234
151
 
235
- Normally the OS will decide which IP address will be used for outbound
236
- connections using the IP routing table.
152
+ Normally the OS will decide which IP address will be used for outbound connections using the IP routing table.
237
153
 
238
- There are instances where you may want to separate outbound traffic on
239
- different IP addresses based on sender, domain or some other identifier.
240
- To do this, the IP address that you want to use *must* be bound to an
241
- interface (or alias) on the local system.
154
+ There are instances where you may want to separate outbound traffic on different IP addresses based on sender, domain or some other identifier. To do this, the IP address that you want to use *must* be bound to an interface (or alias) on the local system.
242
155
 
243
- As described above, the outbound IP can be set using the `bind` parameter
244
- and also the outbound helo for the IP can be set using the `bind_ehlo`
245
- parameter returned by the `get_mx` hook.
156
+ As described above, the outbound IP can be set using the `bind` parameter and also the outbound helo for the IP can be set using the `bind_ehlo` parameter returned by the `get_mx` hook.
246
157
 
158
+ ## AUTH
247
159
 
248
- AUTH
249
- ----
160
+ If you wish to use AUTH for a particular domain or domains, or you wish to force all mail to an outbound service or smart host that requires authentication then you can use the `get_mx` hook documented above to do this by supplying both `auth_user` and `auth_pass` properties in an MX object.
250
161
 
251
- If you wish to use AUTH for a particular domain or domains, or you wish to
252
- force all mail to an outbound service or smart host that requires authentication
253
- then you can use the `get_mx` hook documented above to do this by supplying
254
- both `auth_user` and `auth_pass` properties in an MX object.
162
+ If AUTH properties are supplied and the remote end does not offer AUTH or there are no compatible AUTH methods, then the message will be sent without AUTH and a warning will be logged.
255
163
 
256
- If AUTH properties are supplied and the remote end does not offer AUTH or there
257
- are no compatible AUTH methods, then the message will be sent without AUTH and
258
- a warning will be logged.
164
+ ## Bounce Messages
259
165
 
260
-
261
- Bounce Messages
262
- ---------------
263
-
264
- The contents of the bounce message are configured by a file called
265
- `config/outbound.bounce_message`. If you look at this file you will see it
266
- contains several template entries wrapped in curly brackets. These will be
267
- populated as follows:
166
+ The contents of the bounce message are configured by a file called `config/outbound.bounce_message`. If you look at this file you will see it contains several template entries wrapped in curly brackets. These will be populated as follows:
268
167
 
269
168
  Optional: Possibility to add HTML code (with optional image) to the bounce message is possible by adding the files `config/outbound.bounce_message_html`. An image can be attached to the mail by using `config/outbound.bounce_message_image`.
270
169
 
@@ -277,72 +176,76 @@ Optional: Possibility to add HTML code (with optional image) to the bounce messa
277
176
  multiple people
278
177
  * reason - the text from the remote server indicating why it bounced
279
178
 
280
- Following the bounce message itself will be a copy of the entire original
281
- message.
179
+ Following the bounce message itself will be a copy of the entire original message.
282
180
 
283
- Creating a mail internally for outbound delivery
284
- ------------------------------------------------
181
+ ## Creating a mail internally for outbound delivery
285
182
 
286
183
  Sometimes it is necessary to generate a new mail from within a plugin.
287
184
 
288
185
  To do that, you can use the `outbound` module directly:
289
186
 
290
- var outbound = require('./outbound');
291
-
292
- var plugin = this;
293
-
294
- var to = 'user@example.com';
295
- var from = 'sender@example.com';
296
-
297
- var contents = [
298
- "From: " + from,
299
- "To: " + to,
300
- "MIME-Version: 1.0",
301
- "Content-type: text/plain; charset=us-ascii",
302
- "Subject: Some subject here",
303
- "",
304
- "Some email body here",
305
- ""].join("\n");
306
-
307
- var outnext = function (code, msg) {
308
- switch (code) {
309
- case DENY: plugin.logerror("Sending mail failed: " + msg);
310
- break;
311
- case OK: plugin.loginfo("mail sent");
312
- next();
313
- break;
314
- default: plugin.logerror("Unrecognized return code from sending email: " + msg);
315
- next();
316
- }
317
- };
318
-
319
- outbound.send_email(from, to, contents, outnext);
320
-
321
- The callback on `send_email()` is passed `OK` if the mail is successfully
322
- queued to disk, not when it is successfully delivered. To check delivery
323
- status you still need to hook `delivered` and `bounce` to know if it was
324
- successfully delivered.
325
-
326
- The callback parameter may be omitted if you don't need to handle errors
327
- should queueing to disk fail e.g:
328
-
329
- outbound.send_email(from, to, contents);
330
-
331
- You can pass various options to `outbound.send_email` like so:
332
-
333
- outbound.send_email(from, to, contents, outnext, options);
187
+ ```js
188
+ const outbound = require('./outbound');
189
+
190
+ const to = 'user@example.com';
191
+ const from = 'sender@example.com';
192
+
193
+ const contents = [
194
+ "From: " + from,
195
+ "To: " + to,
196
+ "MIME-Version: 1.0",
197
+ "Content-type: text/plain; charset=us-ascii",
198
+ "Subject: Some subject here",
199
+ "",
200
+ "Some email body here",
201
+ ""].join("\n");
202
+
203
+ const outnext = (code, msg) => {
204
+ switch (code) {
205
+ case DENY: this.logerror("Sending mail failed: " + msg);
206
+ break;
207
+ case OK: this.loginfo("mail sent");
208
+ next();
209
+ break;
210
+ default: this.logerror("Unrecognized return code from sending email: " + msg);
211
+ next();
212
+ }
213
+ }
214
+
215
+ outbound.send_email(from, to, contents, outnext)
216
+ ```
217
+
218
+ The callback on `send_email()` is passed `OK` if the mail is successfully queued, not when it is successfully delivered. To check delivery status, you need to hook `delivered` and `bounce`.
219
+
220
+ The callback parameter may be omitted if you don't need to handle errors should queueing to disk fail e.g:
221
+
222
+ ```js
223
+ outbound.send_email(from, to, contents);
224
+ ```
225
+
226
+ Various options can be passed to `outbound.send_email` like so:
227
+
228
+ ```js
229
+ outbound.send_email(from, to, contents, outnext, options);
230
+ ```
334
231
 
335
232
  Where `options` is a Object that may contain the following keys:
336
233
 
337
- | Key/Value | Description |
338
- |------------------------|--------------------------------------------------------------------------------------------
339
- | `dot_stuffed: true` | Use this if you are passing your content dot-stuffed (a dot at the start of a line is doubled, like it is in SMTP conversation, see [RFC 2821](https://tools.ietf.org/html/rfc2821#section-4.5.2).|
234
+ | Key/Value | Description |
235
+ |------------------------|-------------|
236
+ | `dot_stuffed: true` | Use this if you are passing your content dot-stuffed (a dot at the start of a line is doubled, like it is in SMTP conversation, see [RFC 2821][url-rfc2821].|
340
237
  | `notes: { key: value}` | In case you need notes in the new transaction that `send_email()` creates. |
341
238
  | `remove_msgid: true` | Remove any Message-Id header found in the message. If you are reading a message in from the filesystem and you want to ensure that a generated Message-Id header is used in preference over the original. This is useful if you are releasing mail from a quarantine. |
342
239
  | `remove_date: true` | Remove any Date header found in the message. If you are reading a message in from the filesystem and you want to ensure that a generated Date header is used in preference over the original. This is useful if you are releasing mail from a quarantine. |
343
240
  | `origin: Object` | Adds object as argument to logger.log calls inside outbound.send_email. Useful for tracking which Plugin/Connection/HMailItem object generated email. |
344
241
 
345
242
 
346
- outbound.send_email(from, to, contents, outnext, { notes: transaction.notes });
243
+ ```js
244
+ outbound.send_email(from, to, contents, outnext, { notes: transaction.notes });
245
+ ```
246
+
247
+ <a name="fn1">1</a>: `Address` objects are [address-rfc2821](https://github.com/haraka/node-address-rfc2821) objects.
347
248
 
348
- [1]: `Address` objects are [address-rfc2821 objects](https://github.com/haraka/node-address-rfc2821).
249
+ [url-tls]: https://haraka.github.io/plugins/tls
250
+ [url-harakamx]: https://github.com/haraka/haraka-net-utils?tab=readme-ov-file#harakamx
251
+ [url-rfc2821]: https://tools.ietf.org/html/rfc2821#section-4.5.2
package/docs/Plugins.md CHANGED
@@ -260,11 +260,11 @@ If you are writing a complex plugin, you may have to split it into multiple plug
260
260
 
261
261
  ```js
262
262
  exports.register = function () {
263
- this.register_hook('connect', 'hook_connect', -100);
263
+ this.register_hook('connect', 'do_connect_stuff', -100);
264
264
  }
265
265
  ```
266
266
 
267
- This would ensure that your hook_connect function will run before any other
267
+ This would ensure that your `do_connect_stuff` function will run before any other
268
268
  plugins registered on the `connect` hook, regardless of the order it was
269
269
  specified in `config/plugins`.
270
270