@bobfrankston/mailx 1.0.12 → 1.0.13

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 (237) hide show
  1. package/bin/mailx.js +47 -29
  2. package/client/app.js +93 -13
  3. package/client/components/folder-tree.js +84 -3
  4. package/client/components/message-list.js +134 -8
  5. package/client/components/message-viewer.js +130 -13
  6. package/client/compose/compose.html +4 -4
  7. package/client/compose/compose.js +53 -34
  8. package/client/index.html +33 -9
  9. package/client/lib/api-client.js +102 -30
  10. package/client/lib/mailxapi.js +123 -0
  11. package/client/package.json +1 -1
  12. package/client/styles/components.css +188 -15
  13. package/client/styles/layout.css +2 -1
  14. package/killmail.cmd +6 -0
  15. package/launch.ps1 +47 -5
  16. package/launcher/bin/mailx-app.exe +0 -0
  17. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Breadcrumbs +0 -0
  18. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Crashpad/metadata +0 -0
  19. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Crashpad/settings.dat +0 -0
  20. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Crashpad/throttle_store.dat +1 -0
  21. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/CrashpadMetrics-active.pma +0 -0
  22. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/BrowsingTopicsSiteData +0 -0
  23. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Cache/No_Vary_Search/journal.baj +1 -0
  24. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/DIPS +0 -0
  25. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/DashTrackerDatabase +0 -0
  26. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/EdgeJourneys/EdgeJourneys.db +0 -0
  27. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension Rules/LOCK +0 -0
  28. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension Rules/LOG +3 -0
  29. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension Rules/MANIFEST-000001 +0 -0
  30. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension Scripts/LOCK +0 -0
  31. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension Scripts/LOG +3 -0
  32. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension Scripts/MANIFEST-000001 +0 -0
  33. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension State/LOCK +0 -0
  34. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension State/LOG +3 -0
  35. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Extension State/MANIFEST-000001 +0 -0
  36. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/ExtensionActivityComp +0 -0
  37. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/ExtensionActivityEdge +0 -0
  38. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Favicons +0 -0
  39. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/History +0 -0
  40. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/History-journal +0 -0
  41. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/IndexedDB/devtools_devtools_0.indexeddb.leveldb/LOCK +0 -0
  42. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/IndexedDB/devtools_devtools_0.indexeddb.leveldb/LOG +3 -0
  43. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/IndexedDB/devtools_devtools_0.indexeddb.leveldb/MANIFEST-000001 +0 -0
  44. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Local Storage/leveldb/LOCK +0 -0
  45. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Local Storage/leveldb/LOG +3 -0
  46. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Local Storage/leveldb/MANIFEST-000001 +0 -0
  47. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Login Data +0 -0
  48. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Login Data For Account +0 -0
  49. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Network/Cookies +0 -0
  50. NEL +0 -0
  51. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Network/Trust Tokens +0 -0
  52. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Network Action Predictor +0 -0
  53. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Preferences +1 -0
  54. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Safe Browsing Network/Safe Browsing Cookies +0 -0
  55. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/ServerCertificate +0 -0
  56. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Session Storage/LOCK +0 -0
  57. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Session Storage/LOG +3 -0
  58. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Session Storage/MANIFEST-000001 +0 -0
  59. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Shared Dictionary/db +0 -0
  60. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/SharedStorage +0 -0
  61. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Shortcuts +0 -0
  62. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Site Characteristics Database/LOCK +0 -0
  63. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Site Characteristics Database/LOG +3 -0
  64. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Site Characteristics Database/MANIFEST-000001 +0 -0
  65. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Sync Data/LevelDB/LOCK +0 -0
  66. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Sync Data/LevelDB/LOG +3 -0
  67. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Sync Data/LevelDB/MANIFEST-000001 +0 -0
  68. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Top Sites +0 -0
  69. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Vpn Tokens +0 -0
  70. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Web Data +0 -0
  71. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/Web Data-journal +0 -0
  72. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/WebStorage/QuotaManager +0 -0
  73. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/WebStorage/QuotaManager-journal +0 -0
  74. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/heavy_ad_intervention_opt_out.db +0 -0
  75. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/shared_proto_db/LOCK +0 -0
  76. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/shared_proto_db/LOG +3 -0
  77. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/shared_proto_db/MANIFEST-000001 +0 -0
  78. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/shared_proto_db/metadata/LOCK +0 -0
  79. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/shared_proto_db/metadata/LOG +3 -0
  80. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Default/shared_proto_db/metadata/MANIFEST-000001 +0 -0
  81. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/DeferredBrowserMetrics/BrowserMetrics-69CAD063-BE24.pma +0 -0
  82. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Local State +1 -0
  83. package/launcher/bin/mailx-app.exe.WebView2/EBWebView/Variations +1 -0
  84. package/launcher/bin/mailx-app.old.exe +0 -0
  85. package/package.json +1 -1
  86. package/packages/mailx-api/index.js +79 -26
  87. package/packages/mailx-core/index.d.ts +129 -0
  88. package/packages/mailx-core/index.js +323 -0
  89. package/packages/mailx-core/ipc.d.ts +13 -0
  90. package/packages/mailx-core/ipc.js +56 -0
  91. package/packages/mailx-core/package.json +18 -0
  92. package/packages/mailx-imap/index.d.ts +5 -1
  93. package/packages/mailx-imap/index.js +76 -14
  94. package/packages/mailx-server/index.js +42 -31
  95. package/packages/mailx-server/package.json +1 -2
  96. package/packages/mailx-settings/index.d.ts +1 -1
  97. package/packages/mailx-settings/index.js +21 -12
  98. package/packages/mailx-store/db.d.ts +5 -1
  99. package/packages/mailx-store/db.js +64 -12
  100. package/packages/mailx-store/file-store.d.ts +2 -8
  101. package/packages/mailx-store/file-store.js +7 -31
  102. package/packages/mailx-types/index.d.ts +3 -1
  103. package/.tswalk.json +0 -7396
  104. package/launcher/release.cmd +0 -4
  105. package/mailx.json +0 -9
  106. package/packages/mailx-api/node_modules/nodemailer/.ncurc.js +0 -9
  107. package/packages/mailx-api/node_modules/nodemailer/.prettierignore +0 -8
  108. package/packages/mailx-api/node_modules/nodemailer/.prettierrc +0 -12
  109. package/packages/mailx-api/node_modules/nodemailer/.prettierrc.js +0 -10
  110. package/packages/mailx-api/node_modules/nodemailer/.release-please-config.json +0 -9
  111. package/packages/mailx-api/node_modules/nodemailer/LICENSE +0 -16
  112. package/packages/mailx-api/node_modules/nodemailer/README.md +0 -86
  113. package/packages/mailx-api/node_modules/nodemailer/SECURITY.txt +0 -22
  114. package/packages/mailx-api/node_modules/nodemailer/eslint.config.js +0 -88
  115. package/packages/mailx-api/node_modules/nodemailer/lib/addressparser/index.js +0 -383
  116. package/packages/mailx-api/node_modules/nodemailer/lib/base64/index.js +0 -139
  117. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/index.js +0 -253
  118. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  119. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  120. package/packages/mailx-api/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  121. package/packages/mailx-api/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  122. package/packages/mailx-api/node_modules/nodemailer/lib/fetch/index.js +0 -280
  123. package/packages/mailx-api/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  124. package/packages/mailx-api/node_modules/nodemailer/lib/mail-composer/index.js +0 -629
  125. package/packages/mailx-api/node_modules/nodemailer/lib/mailer/index.js +0 -441
  126. package/packages/mailx-api/node_modules/nodemailer/lib/mailer/mail-message.js +0 -316
  127. package/packages/mailx-api/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  128. package/packages/mailx-api/node_modules/nodemailer/lib/mime-funcs/mime-types.js +0 -2113
  129. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/index.js +0 -1316
  130. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/last-newline.js +0 -33
  131. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/le-unix.js +0 -43
  132. package/packages/mailx-api/node_modules/nodemailer/lib/mime-node/le-windows.js +0 -52
  133. package/packages/mailx-api/node_modules/nodemailer/lib/nodemailer.js +0 -157
  134. package/packages/mailx-api/node_modules/nodemailer/lib/punycode/index.js +0 -460
  135. package/packages/mailx-api/node_modules/nodemailer/lib/qp/index.js +0 -227
  136. package/packages/mailx-api/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  137. package/packages/mailx-api/node_modules/nodemailer/lib/ses-transport/index.js +0 -234
  138. package/packages/mailx-api/node_modules/nodemailer/lib/shared/index.js +0 -754
  139. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  140. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  141. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1870
  142. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-pool/index.js +0 -652
  143. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +0 -259
  144. package/packages/mailx-api/node_modules/nodemailer/lib/smtp-transport/index.js +0 -421
  145. package/packages/mailx-api/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  146. package/packages/mailx-api/node_modules/nodemailer/lib/well-known/index.js +0 -47
  147. package/packages/mailx-api/node_modules/nodemailer/lib/well-known/services.json +0 -611
  148. package/packages/mailx-api/node_modules/nodemailer/lib/xoauth2/index.js +0 -427
  149. package/packages/mailx-api/node_modules/nodemailer/package.json +0 -47
  150. package/packages/mailx-imap/node_modules/nodemailer/.ncurc.js +0 -9
  151. package/packages/mailx-imap/node_modules/nodemailer/.prettierignore +0 -8
  152. package/packages/mailx-imap/node_modules/nodemailer/.prettierrc +0 -12
  153. package/packages/mailx-imap/node_modules/nodemailer/.prettierrc.js +0 -10
  154. package/packages/mailx-imap/node_modules/nodemailer/.release-please-config.json +0 -9
  155. package/packages/mailx-imap/node_modules/nodemailer/LICENSE +0 -16
  156. package/packages/mailx-imap/node_modules/nodemailer/README.md +0 -86
  157. package/packages/mailx-imap/node_modules/nodemailer/SECURITY.txt +0 -22
  158. package/packages/mailx-imap/node_modules/nodemailer/eslint.config.js +0 -88
  159. package/packages/mailx-imap/node_modules/nodemailer/lib/addressparser/index.js +0 -383
  160. package/packages/mailx-imap/node_modules/nodemailer/lib/base64/index.js +0 -139
  161. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/index.js +0 -253
  162. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  163. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  164. package/packages/mailx-imap/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  165. package/packages/mailx-imap/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  166. package/packages/mailx-imap/node_modules/nodemailer/lib/fetch/index.js +0 -280
  167. package/packages/mailx-imap/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  168. package/packages/mailx-imap/node_modules/nodemailer/lib/mail-composer/index.js +0 -629
  169. package/packages/mailx-imap/node_modules/nodemailer/lib/mailer/index.js +0 -441
  170. package/packages/mailx-imap/node_modules/nodemailer/lib/mailer/mail-message.js +0 -316
  171. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  172. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-funcs/mime-types.js +0 -2113
  173. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/index.js +0 -1316
  174. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/last-newline.js +0 -33
  175. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/le-unix.js +0 -43
  176. package/packages/mailx-imap/node_modules/nodemailer/lib/mime-node/le-windows.js +0 -52
  177. package/packages/mailx-imap/node_modules/nodemailer/lib/nodemailer.js +0 -157
  178. package/packages/mailx-imap/node_modules/nodemailer/lib/punycode/index.js +0 -460
  179. package/packages/mailx-imap/node_modules/nodemailer/lib/qp/index.js +0 -227
  180. package/packages/mailx-imap/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  181. package/packages/mailx-imap/node_modules/nodemailer/lib/ses-transport/index.js +0 -234
  182. package/packages/mailx-imap/node_modules/nodemailer/lib/shared/index.js +0 -754
  183. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  184. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  185. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1870
  186. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-pool/index.js +0 -652
  187. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +0 -259
  188. package/packages/mailx-imap/node_modules/nodemailer/lib/smtp-transport/index.js +0 -421
  189. package/packages/mailx-imap/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  190. package/packages/mailx-imap/node_modules/nodemailer/lib/well-known/index.js +0 -47
  191. package/packages/mailx-imap/node_modules/nodemailer/lib/well-known/services.json +0 -611
  192. package/packages/mailx-imap/node_modules/nodemailer/lib/xoauth2/index.js +0 -427
  193. package/packages/mailx-imap/node_modules/nodemailer/package.json +0 -47
  194. package/packages/mailx-send/node_modules/nodemailer/.ncurc.js +0 -9
  195. package/packages/mailx-send/node_modules/nodemailer/.prettierignore +0 -8
  196. package/packages/mailx-send/node_modules/nodemailer/.prettierrc +0 -12
  197. package/packages/mailx-send/node_modules/nodemailer/.prettierrc.js +0 -10
  198. package/packages/mailx-send/node_modules/nodemailer/.release-please-config.json +0 -9
  199. package/packages/mailx-send/node_modules/nodemailer/LICENSE +0 -16
  200. package/packages/mailx-send/node_modules/nodemailer/README.md +0 -86
  201. package/packages/mailx-send/node_modules/nodemailer/SECURITY.txt +0 -22
  202. package/packages/mailx-send/node_modules/nodemailer/eslint.config.js +0 -88
  203. package/packages/mailx-send/node_modules/nodemailer/lib/addressparser/index.js +0 -383
  204. package/packages/mailx-send/node_modules/nodemailer/lib/base64/index.js +0 -139
  205. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/index.js +0 -253
  206. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
  207. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
  208. package/packages/mailx-send/node_modules/nodemailer/lib/dkim/sign.js +0 -117
  209. package/packages/mailx-send/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
  210. package/packages/mailx-send/node_modules/nodemailer/lib/fetch/index.js +0 -280
  211. package/packages/mailx-send/node_modules/nodemailer/lib/json-transport/index.js +0 -82
  212. package/packages/mailx-send/node_modules/nodemailer/lib/mail-composer/index.js +0 -629
  213. package/packages/mailx-send/node_modules/nodemailer/lib/mailer/index.js +0 -441
  214. package/packages/mailx-send/node_modules/nodemailer/lib/mailer/mail-message.js +0 -316
  215. package/packages/mailx-send/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
  216. package/packages/mailx-send/node_modules/nodemailer/lib/mime-funcs/mime-types.js +0 -2113
  217. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/index.js +0 -1316
  218. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/last-newline.js +0 -33
  219. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/le-unix.js +0 -43
  220. package/packages/mailx-send/node_modules/nodemailer/lib/mime-node/le-windows.js +0 -52
  221. package/packages/mailx-send/node_modules/nodemailer/lib/nodemailer.js +0 -157
  222. package/packages/mailx-send/node_modules/nodemailer/lib/punycode/index.js +0 -460
  223. package/packages/mailx-send/node_modules/nodemailer/lib/qp/index.js +0 -227
  224. package/packages/mailx-send/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
  225. package/packages/mailx-send/node_modules/nodemailer/lib/ses-transport/index.js +0 -234
  226. package/packages/mailx-send/node_modules/nodemailer/lib/shared/index.js +0 -754
  227. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
  228. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
  229. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1870
  230. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-pool/index.js +0 -652
  231. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-pool/pool-resource.js +0 -259
  232. package/packages/mailx-send/node_modules/nodemailer/lib/smtp-transport/index.js +0 -421
  233. package/packages/mailx-send/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
  234. package/packages/mailx-send/node_modules/nodemailer/lib/well-known/index.js +0 -47
  235. package/packages/mailx-send/node_modules/nodemailer/lib/well-known/services.json +0 -611
  236. package/packages/mailx-send/node_modules/nodemailer/lib/xoauth2/index.js +0 -427
  237. package/packages/mailx-send/node_modules/nodemailer/package.json +0 -47
@@ -1,754 +0,0 @@
1
- /* eslint no-console: 0 */
2
-
3
- 'use strict';
4
-
5
- const urllib = require('url');
6
- const util = require('util');
7
- const fs = require('fs');
8
- const nmfetch = require('../fetch');
9
- const dns = require('dns');
10
- const net = require('net');
11
- const os = require('os');
12
-
13
- const DNS_TTL = 5 * 60 * 1000;
14
- const CACHE_CLEANUP_INTERVAL = 30 * 1000; // Minimum 30 seconds between cleanups
15
- const MAX_CACHE_SIZE = 1000; // Maximum number of entries in cache
16
-
17
- let lastCacheCleanup = 0;
18
- module.exports._lastCacheCleanup = () => lastCacheCleanup;
19
- module.exports._resetCacheCleanup = () => {
20
- lastCacheCleanup = 0;
21
- };
22
-
23
- let networkInterfaces;
24
- try {
25
- networkInterfaces = os.networkInterfaces();
26
- } catch (_err) {
27
- // fails on some systems
28
- }
29
-
30
- module.exports.networkInterfaces = networkInterfaces;
31
-
32
- const isFamilySupported = (family, allowInternal) => {
33
- let networkInterfaces = module.exports.networkInterfaces;
34
- if (!networkInterfaces) {
35
- // hope for the best
36
- return true;
37
- }
38
-
39
- const familySupported =
40
- // crux that replaces Object.values(networkInterfaces) as Object.values is not supported in nodejs v6
41
- Object.keys(networkInterfaces)
42
- .map(key => networkInterfaces[key])
43
- // crux that replaces .flat() as it is not supported in older Node versions (v10 and older)
44
- .reduce((acc, val) => acc.concat(val), [])
45
- .filter(i => !i.internal || allowInternal)
46
- .filter(i => i.family === 'IPv' + family || i.family === family).length > 0;
47
-
48
- return familySupported;
49
- };
50
-
51
- const resolver = (family, hostname, options, callback) => {
52
- options = options || {};
53
- const familySupported = isFamilySupported(family, options.allowInternalNetworkInterfaces);
54
-
55
- if (!familySupported) {
56
- return callback(null, []);
57
- }
58
-
59
- const resolver = dns.Resolver ? new dns.Resolver(options) : dns;
60
- resolver['resolve' + family](hostname, (err, addresses) => {
61
- if (err) {
62
- switch (err.code) {
63
- case dns.NODATA:
64
- case dns.NOTFOUND:
65
- case dns.NOTIMP:
66
- case dns.SERVFAIL:
67
- case dns.CONNREFUSED:
68
- case dns.REFUSED:
69
- case 'EAI_AGAIN':
70
- return callback(null, []);
71
- }
72
- return callback(err);
73
- }
74
- return callback(null, Array.isArray(addresses) ? addresses : [].concat(addresses || []));
75
- });
76
- };
77
-
78
- const dnsCache = (module.exports.dnsCache = new Map());
79
-
80
- const formatDNSValue = (value, extra) => {
81
- if (!value) {
82
- return Object.assign({}, extra || {});
83
- }
84
-
85
- return Object.assign(
86
- {
87
- servername: value.servername,
88
- host:
89
- !value.addresses || !value.addresses.length
90
- ? null
91
- : value.addresses.length === 1
92
- ? value.addresses[0]
93
- : value.addresses[Math.floor(Math.random() * value.addresses.length)]
94
- },
95
- extra || {}
96
- );
97
- };
98
-
99
- module.exports.resolveHostname = (options, callback) => {
100
- options = options || {};
101
-
102
- if (!options.host && options.servername) {
103
- options.host = options.servername;
104
- }
105
-
106
- if (!options.host || net.isIP(options.host)) {
107
- // nothing to do here
108
- let value = {
109
- addresses: [options.host],
110
- servername: options.servername || false
111
- };
112
- return callback(
113
- null,
114
- formatDNSValue(value, {
115
- cached: false
116
- })
117
- );
118
- }
119
-
120
- let cached;
121
- if (dnsCache.has(options.host)) {
122
- cached = dnsCache.get(options.host);
123
-
124
- // Lazy cleanup with time throttling
125
- const now = Date.now();
126
- if (now - lastCacheCleanup > CACHE_CLEANUP_INTERVAL) {
127
- lastCacheCleanup = now;
128
-
129
- // Clean up expired entries
130
- for (const [host, entry] of dnsCache.entries()) {
131
- if (entry.expires && entry.expires < now) {
132
- dnsCache.delete(host);
133
- }
134
- }
135
-
136
- // If cache is still too large, remove oldest entries
137
- if (dnsCache.size > MAX_CACHE_SIZE) {
138
- const toDelete = Math.floor(MAX_CACHE_SIZE * 0.1); // Remove 10% of entries
139
- const keys = Array.from(dnsCache.keys()).slice(0, toDelete);
140
- keys.forEach(key => dnsCache.delete(key));
141
- }
142
- }
143
-
144
- if (!cached.expires || cached.expires >= now) {
145
- return callback(
146
- null,
147
- formatDNSValue(cached.value, {
148
- cached: true
149
- })
150
- );
151
- }
152
- }
153
-
154
- resolver(4, options.host, options, (err, addresses) => {
155
- if (err) {
156
- if (cached) {
157
- dnsCache.set(options.host, {
158
- value: cached.value,
159
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
160
- });
161
-
162
- return callback(
163
- null,
164
- formatDNSValue(cached.value, {
165
- cached: true,
166
- error: err
167
- })
168
- );
169
- }
170
- return callback(err);
171
- }
172
-
173
- if (addresses && addresses.length) {
174
- let value = {
175
- addresses,
176
- servername: options.servername || options.host
177
- };
178
-
179
- dnsCache.set(options.host, {
180
- value,
181
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
182
- });
183
-
184
- return callback(
185
- null,
186
- formatDNSValue(value, {
187
- cached: false
188
- })
189
- );
190
- }
191
-
192
- resolver(6, options.host, options, (err, addresses) => {
193
- if (err) {
194
- if (cached) {
195
- dnsCache.set(options.host, {
196
- value: cached.value,
197
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
198
- });
199
-
200
- return callback(
201
- null,
202
- formatDNSValue(cached.value, {
203
- cached: true,
204
- error: err
205
- })
206
- );
207
- }
208
- return callback(err);
209
- }
210
-
211
- if (addresses && addresses.length) {
212
- let value = {
213
- addresses,
214
- servername: options.servername || options.host
215
- };
216
-
217
- dnsCache.set(options.host, {
218
- value,
219
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
220
- });
221
-
222
- return callback(
223
- null,
224
- formatDNSValue(value, {
225
- cached: false
226
- })
227
- );
228
- }
229
-
230
- try {
231
- dns.lookup(options.host, { all: true }, (err, addresses) => {
232
- if (err) {
233
- if (cached) {
234
- dnsCache.set(options.host, {
235
- value: cached.value,
236
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
237
- });
238
-
239
- return callback(
240
- null,
241
- formatDNSValue(cached.value, {
242
- cached: true,
243
- error: err
244
- })
245
- );
246
- }
247
- return callback(err);
248
- }
249
-
250
- let address = addresses
251
- ? addresses
252
- .filter(addr => isFamilySupported(addr.family))
253
- .map(addr => addr.address)
254
- .shift()
255
- : false;
256
-
257
- if (addresses && addresses.length && !address) {
258
- // there are addresses but none can be used
259
- console.warn(`Failed to resolve IPv${addresses[0].family} addresses with current network`);
260
- }
261
-
262
- if (!address && cached) {
263
- // nothing was found, fallback to cached value
264
- return callback(
265
- null,
266
- formatDNSValue(cached.value, {
267
- cached: true
268
- })
269
- );
270
- }
271
-
272
- let value = {
273
- addresses: address ? [address] : [options.host],
274
- servername: options.servername || options.host
275
- };
276
-
277
- dnsCache.set(options.host, {
278
- value,
279
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
280
- });
281
-
282
- return callback(
283
- null,
284
- formatDNSValue(value, {
285
- cached: false
286
- })
287
- );
288
- });
289
- } catch (_err) {
290
- if (cached) {
291
- dnsCache.set(options.host, {
292
- value: cached.value,
293
- expires: Date.now() + (options.dnsTtl || DNS_TTL)
294
- });
295
-
296
- return callback(
297
- null,
298
- formatDNSValue(cached.value, {
299
- cached: true,
300
- error: err
301
- })
302
- );
303
- }
304
- return callback(err);
305
- }
306
- });
307
- });
308
- };
309
- /**
310
- * Parses connection url to a structured configuration object
311
- *
312
- * @param {String} str Connection url
313
- * @return {Object} Configuration object
314
- */
315
- module.exports.parseConnectionUrl = str => {
316
- str = str || '';
317
- let options = {};
318
-
319
- [urllib.parse(str, true)].forEach(url => {
320
- let auth;
321
-
322
- switch (url.protocol) {
323
- case 'smtp:':
324
- options.secure = false;
325
- break;
326
- case 'smtps:':
327
- options.secure = true;
328
- break;
329
- case 'direct:':
330
- options.direct = true;
331
- break;
332
- }
333
-
334
- if (!isNaN(url.port) && Number(url.port)) {
335
- options.port = Number(url.port);
336
- }
337
-
338
- if (url.hostname) {
339
- options.host = url.hostname;
340
- }
341
-
342
- if (url.auth) {
343
- auth = url.auth.split(':');
344
-
345
- if (!options.auth) {
346
- options.auth = {};
347
- }
348
-
349
- options.auth.user = auth.shift();
350
- options.auth.pass = auth.join(':');
351
- }
352
-
353
- Object.keys(url.query || {}).forEach(key => {
354
- let obj = options;
355
- let lKey = key;
356
- let value = url.query[key];
357
-
358
- if (!isNaN(value)) {
359
- value = Number(value);
360
- }
361
-
362
- switch (value) {
363
- case 'true':
364
- value = true;
365
- break;
366
- case 'false':
367
- value = false;
368
- break;
369
- }
370
-
371
- // tls is nested object
372
- if (key.indexOf('tls.') === 0) {
373
- lKey = key.substr(4);
374
- if (!options.tls) {
375
- options.tls = {};
376
- }
377
- obj = options.tls;
378
- } else if (key.indexOf('.') >= 0) {
379
- // ignore nested properties besides tls
380
- return;
381
- }
382
-
383
- if (!(lKey in obj)) {
384
- obj[lKey] = value;
385
- }
386
- });
387
- });
388
-
389
- return options;
390
- };
391
-
392
- module.exports._logFunc = (logger, level, defaults, data, message, ...args) => {
393
- let entry = {};
394
-
395
- Object.keys(defaults || {}).forEach(key => {
396
- if (key !== 'level') {
397
- entry[key] = defaults[key];
398
- }
399
- });
400
-
401
- Object.keys(data || {}).forEach(key => {
402
- if (key !== 'level') {
403
- entry[key] = data[key];
404
- }
405
- });
406
-
407
- logger[level](entry, message, ...args);
408
- };
409
-
410
- /**
411
- * Returns a bunyan-compatible logger interface. Uses either provided logger or
412
- * creates a default console logger
413
- *
414
- * @param {Object} [options] Options object that might include 'logger' value
415
- * @return {Object} bunyan compatible logger
416
- */
417
- module.exports.getLogger = (options, defaults) => {
418
- options = options || {};
419
-
420
- let response = {};
421
- let levels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];
422
-
423
- if (!options.logger) {
424
- // use vanity logger
425
- levels.forEach(level => {
426
- response[level] = () => false;
427
- });
428
- return response;
429
- }
430
-
431
- let logger = options.logger;
432
-
433
- if (options.logger === true) {
434
- // create console logger
435
- logger = createDefaultLogger(levels);
436
- }
437
-
438
- levels.forEach(level => {
439
- response[level] = (data, message, ...args) => {
440
- module.exports._logFunc(logger, level, defaults, data, message, ...args);
441
- };
442
- });
443
-
444
- return response;
445
- };
446
-
447
- /**
448
- * Wrapper for creating a callback that either resolves or rejects a promise
449
- * based on input
450
- *
451
- * @param {Function} resolve Function to run if callback is called
452
- * @param {Function} reject Function to run if callback ends with an error
453
- */
454
- module.exports.callbackPromise = (resolve, reject) =>
455
- function () {
456
- let args = Array.from(arguments);
457
- let err = args.shift();
458
- if (err) {
459
- reject(err);
460
- } else {
461
- resolve(...args);
462
- }
463
- };
464
-
465
- module.exports.parseDataURI = uri => {
466
- if (typeof uri !== 'string') {
467
- return null;
468
- }
469
-
470
- // Early return for non-data URIs to avoid unnecessary processing
471
- if (!uri.startsWith('data:')) {
472
- return null;
473
- }
474
-
475
- // Find the first comma safely - this prevents ReDoS
476
- const commaPos = uri.indexOf(',');
477
- if (commaPos === -1) {
478
- return null;
479
- }
480
-
481
- const data = uri.substring(commaPos + 1);
482
- const metaStr = uri.substring('data:'.length, commaPos);
483
-
484
- let encoding;
485
- const metaEntries = metaStr.split(';');
486
-
487
- if (metaEntries.length > 0) {
488
- const lastEntry = metaEntries[metaEntries.length - 1].toLowerCase().trim();
489
- // Only recognize valid encoding types to prevent manipulation
490
- if (['base64', 'utf8', 'utf-8'].includes(lastEntry) && lastEntry.indexOf('=') === -1) {
491
- encoding = lastEntry;
492
- metaEntries.pop();
493
- }
494
- }
495
-
496
- const contentType = metaEntries.length > 0 ? metaEntries.shift() : 'application/octet-stream';
497
- const params = {};
498
-
499
- for (let i = 0; i < metaEntries.length; i++) {
500
- const entry = metaEntries[i];
501
- const sepPos = entry.indexOf('=');
502
- if (sepPos > 0) {
503
- // Ensure there's a key before the '='
504
- const key = entry.substring(0, sepPos).trim();
505
- const value = entry.substring(sepPos + 1).trim();
506
- if (key) {
507
- params[key] = value;
508
- }
509
- }
510
- }
511
-
512
- // Decode data based on encoding with proper error handling
513
- let bufferData;
514
- try {
515
- if (encoding === 'base64') {
516
- bufferData = Buffer.from(data, 'base64');
517
- } else {
518
- try {
519
- bufferData = Buffer.from(decodeURIComponent(data));
520
- } catch (_decodeError) {
521
- bufferData = Buffer.from(data);
522
- }
523
- }
524
- } catch (_bufferError) {
525
- bufferData = Buffer.alloc(0);
526
- }
527
-
528
- return {
529
- data: bufferData,
530
- encoding: encoding || null,
531
- contentType: contentType || 'application/octet-stream',
532
- params
533
- };
534
- };
535
-
536
- /**
537
- * Resolves a String or a Buffer value for content value. Useful if the value
538
- * is a Stream or a file or an URL. If the value is a Stream, overwrites
539
- * the stream object with the resolved value (you can't stream a value twice).
540
- *
541
- * This is useful when you want to create a plugin that needs a content value,
542
- * for example the `html` or `text` value as a String or a Buffer but not as
543
- * a file path or an URL.
544
- *
545
- * @param {Object} data An object or an Array you want to resolve an element for
546
- * @param {String|Number} key Property name or an Array index
547
- * @param {Function} callback Callback function with (err, value)
548
- */
549
- module.exports.resolveContent = (data, key, callback) => {
550
- let promise;
551
-
552
- if (!callback) {
553
- promise = new Promise((resolve, reject) => {
554
- callback = module.exports.callbackPromise(resolve, reject);
555
- });
556
- }
557
-
558
- let content = (data && data[key] && data[key].content) || data[key];
559
- let contentStream;
560
- let encoding = ((typeof data[key] === 'object' && data[key].encoding) || 'utf8')
561
- .toString()
562
- .toLowerCase()
563
- .replace(/[-_\s]/g, '');
564
-
565
- if (!content) {
566
- return callback(null, content);
567
- }
568
-
569
- if (typeof content === 'object') {
570
- if (typeof content.pipe === 'function') {
571
- return resolveStream(content, (err, value) => {
572
- if (err) {
573
- return callback(err);
574
- }
575
- // we can't stream twice the same content, so we need
576
- // to replace the stream object with the streaming result
577
- if (data[key].content) {
578
- data[key].content = value;
579
- } else {
580
- data[key] = value;
581
- }
582
- callback(null, value);
583
- });
584
- } else if (/^https?:\/\//i.test(content.path || content.href)) {
585
- contentStream = nmfetch(content.path || content.href);
586
- return resolveStream(contentStream, callback);
587
- } else if (/^data:/i.test(content.path || content.href)) {
588
- let parsedDataUri = module.exports.parseDataURI(content.path || content.href);
589
-
590
- if (!parsedDataUri || !parsedDataUri.data) {
591
- return callback(null, Buffer.from(0));
592
- }
593
- return callback(null, parsedDataUri.data);
594
- } else if (content.path) {
595
- return resolveStream(fs.createReadStream(content.path), callback);
596
- }
597
- }
598
-
599
- if (typeof data[key].content === 'string' && !['utf8', 'usascii', 'ascii'].includes(encoding)) {
600
- content = Buffer.from(data[key].content, encoding);
601
- }
602
-
603
- // default action, return as is
604
- setImmediate(() => callback(null, content));
605
-
606
- return promise;
607
- };
608
-
609
- /**
610
- * Copies properties from source objects to target objects
611
- */
612
- module.exports.assign = function (/* target, ... sources */) {
613
- let args = Array.from(arguments);
614
- let target = args.shift() || {};
615
-
616
- args.forEach(source => {
617
- Object.keys(source || {}).forEach(key => {
618
- if (['tls', 'auth'].includes(key) && source[key] && typeof source[key] === 'object') {
619
- // tls and auth are special keys that need to be enumerated separately
620
- // other objects are passed as is
621
- if (!target[key]) {
622
- // ensure that target has this key
623
- target[key] = {};
624
- }
625
- Object.keys(source[key]).forEach(subKey => {
626
- target[key][subKey] = source[key][subKey];
627
- });
628
- } else {
629
- target[key] = source[key];
630
- }
631
- });
632
- });
633
- return target;
634
- };
635
-
636
- module.exports.encodeXText = str => {
637
- // ! 0x21
638
- // + 0x2B
639
- // = 0x3D
640
- // ~ 0x7E
641
- if (!/[^\x21-\x2A\x2C-\x3C\x3E-\x7E]/.test(str)) {
642
- return str;
643
- }
644
- let buf = Buffer.from(str);
645
- let result = '';
646
- for (let i = 0, len = buf.length; i < len; i++) {
647
- let c = buf[i];
648
- if (c < 0x21 || c > 0x7e || c === 0x2b || c === 0x3d) {
649
- result += '+' + (c < 0x10 ? '0' : '') + c.toString(16).toUpperCase();
650
- } else {
651
- result += String.fromCharCode(c);
652
- }
653
- }
654
- return result;
655
- };
656
-
657
- /**
658
- * Streams a stream value into a Buffer
659
- *
660
- * @param {Object} stream Readable stream
661
- * @param {Function} callback Callback function with (err, value)
662
- */
663
- function resolveStream(stream, callback) {
664
- let responded = false;
665
- let chunks = [];
666
- let chunklen = 0;
667
-
668
- stream.on('error', err => {
669
- if (responded) {
670
- return;
671
- }
672
-
673
- responded = true;
674
- callback(err);
675
- });
676
-
677
- stream.on('readable', () => {
678
- let chunk;
679
- while ((chunk = stream.read()) !== null) {
680
- chunks.push(chunk);
681
- chunklen += chunk.length;
682
- }
683
- });
684
-
685
- stream.on('end', () => {
686
- if (responded) {
687
- return;
688
- }
689
- responded = true;
690
-
691
- let value;
692
-
693
- try {
694
- value = Buffer.concat(chunks, chunklen);
695
- } catch (E) {
696
- return callback(E);
697
- }
698
- callback(null, value);
699
- });
700
- }
701
-
702
- /**
703
- * Generates a bunyan-like logger that prints to console
704
- *
705
- * @returns {Object} Bunyan logger instance
706
- */
707
- function createDefaultLogger(levels) {
708
- let levelMaxLen = 0;
709
- let levelNames = new Map();
710
- levels.forEach(level => {
711
- if (level.length > levelMaxLen) {
712
- levelMaxLen = level.length;
713
- }
714
- });
715
-
716
- levels.forEach(level => {
717
- let levelName = level.toUpperCase();
718
- if (levelName.length < levelMaxLen) {
719
- levelName += ' '.repeat(levelMaxLen - levelName.length);
720
- }
721
- levelNames.set(level, levelName);
722
- });
723
-
724
- let print = (level, entry, message, ...args) => {
725
- let prefix = '';
726
- if (entry) {
727
- if (entry.tnx === 'server') {
728
- prefix = 'S: ';
729
- } else if (entry.tnx === 'client') {
730
- prefix = 'C: ';
731
- }
732
-
733
- if (entry.sid) {
734
- prefix = '[' + entry.sid + '] ' + prefix;
735
- }
736
-
737
- if (entry.cid) {
738
- prefix = '[#' + entry.cid + '] ' + prefix;
739
- }
740
- }
741
-
742
- message = util.format(message, ...args);
743
- message.split(/\r?\n/).forEach(line => {
744
- console.log('[%s] %s %s', new Date().toISOString().substr(0, 19).replace(/T/, ' '), levelNames.get(level), prefix + line);
745
- });
746
- };
747
-
748
- let logger = {};
749
- levels.forEach(level => {
750
- logger[level] = print.bind(null, level);
751
- });
752
-
753
- return logger;
754
- }