@bobfrankston/rmfmail 1.0.467

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 (330) hide show
  1. package/README.md +429 -0
  2. package/bin/build-icon-ico.js +283 -0
  3. package/bin/lean-accounts.js +172 -0
  4. package/bin/mailx.js +1580 -0
  5. package/bin/mailx.js.map +1 -0
  6. package/bin/mailx.ts +1549 -0
  7. package/bin/postinstall.js +39 -0
  8. package/bin/postinstall.js.map +1 -0
  9. package/bin/postinstall.ts +41 -0
  10. package/bin/tsconfig.json +10 -0
  11. package/client/.gitattributes +10 -0
  12. package/client/.msger-window.json +1 -0
  13. package/client/android.html +226 -0
  14. package/client/app.js +3400 -0
  15. package/client/app.js.map +1 -0
  16. package/client/app.ts +3190 -0
  17. package/client/components/address-book.js +199 -0
  18. package/client/components/address-book.js.map +1 -0
  19. package/client/components/address-book.ts +204 -0
  20. package/client/components/alarms.js +299 -0
  21. package/client/components/alarms.js.map +1 -0
  22. package/client/components/alarms.ts +276 -0
  23. package/client/components/calendar-sidebar.js +508 -0
  24. package/client/components/calendar-sidebar.js.map +1 -0
  25. package/client/components/calendar-sidebar.ts +474 -0
  26. package/client/components/calendar.js +217 -0
  27. package/client/components/calendar.js.map +1 -0
  28. package/client/components/calendar.ts +211 -0
  29. package/client/components/context-menu.js +80 -0
  30. package/client/components/context-menu.js.map +1 -0
  31. package/client/components/context-menu.ts +95 -0
  32. package/client/components/folder-picker.js +119 -0
  33. package/client/components/folder-picker.js.map +1 -0
  34. package/client/components/folder-picker.ts +127 -0
  35. package/client/components/folder-tree.js +1093 -0
  36. package/client/components/folder-tree.js.map +1 -0
  37. package/client/components/folder-tree.ts +1069 -0
  38. package/client/components/message-list.js +1140 -0
  39. package/client/components/message-list.js.map +1 -0
  40. package/client/components/message-list.ts +1129 -0
  41. package/client/components/message-viewer.js +1291 -0
  42. package/client/components/message-viewer.js.map +1 -0
  43. package/client/components/message-viewer.ts +1257 -0
  44. package/client/components/outbox-view.js +104 -0
  45. package/client/components/outbox-view.js.map +1 -0
  46. package/client/components/outbox-view.ts +102 -0
  47. package/client/components/tasks.js +261 -0
  48. package/client/components/tasks.js.map +1 -0
  49. package/client/components/tasks.ts +234 -0
  50. package/client/compose/compose.css +560 -0
  51. package/client/compose/compose.html +52 -0
  52. package/client/compose/compose.js +1289 -0
  53. package/client/compose/compose.js.map +1 -0
  54. package/client/compose/compose.ts +1231 -0
  55. package/client/compose/editor.js +616 -0
  56. package/client/compose/editor.js.map +1 -0
  57. package/client/compose/editor.ts +599 -0
  58. package/client/compose/ghost-text.js +122 -0
  59. package/client/compose/ghost-text.js.map +1 -0
  60. package/client/compose/ghost-text.ts +140 -0
  61. package/client/favicon.svg +11 -0
  62. package/client/icon.ico +0 -0
  63. package/client/icon.png +0 -0
  64. package/client/index.html +230 -0
  65. package/client/lib/android-bootstrap.js +9 -0
  66. package/client/lib/android-bootstrap.js.map +1 -0
  67. package/client/lib/android-bootstrap.ts +9 -0
  68. package/client/lib/api-client.js +378 -0
  69. package/client/lib/api-client.js.map +1 -0
  70. package/client/lib/api-client.ts +439 -0
  71. package/client/lib/local-service.js +603 -0
  72. package/client/lib/local-service.js.map +1 -0
  73. package/client/lib/local-service.ts +646 -0
  74. package/client/lib/local-store.js +214 -0
  75. package/client/lib/local-store.js.map +1 -0
  76. package/client/lib/local-store.ts +283 -0
  77. package/client/lib/mailxapi.js +304 -0
  78. package/client/lib/message-state.js +132 -0
  79. package/client/lib/message-state.js.map +1 -0
  80. package/client/lib/message-state.ts +160 -0
  81. package/client/package.json +16 -0
  82. package/client/styles/components.css +2049 -0
  83. package/client/styles/layout.css +332 -0
  84. package/client/styles/variables.css +85 -0
  85. package/client/tsconfig.json +19 -0
  86. package/package.json +124 -0
  87. package/packages/mailx-api/.gitattributes +10 -0
  88. package/packages/mailx-api/index.d.ts +10 -0
  89. package/packages/mailx-api/index.d.ts.map +1 -0
  90. package/packages/mailx-api/index.js +322 -0
  91. package/packages/mailx-api/index.js.map +1 -0
  92. package/packages/mailx-api/index.ts +283 -0
  93. package/packages/mailx-api/package.json +27 -0
  94. package/packages/mailx-api/tsconfig.json +9 -0
  95. package/packages/mailx-api/tsconfig.tsbuildinfo +1 -0
  96. package/packages/mailx-compose/.gitattributes +10 -0
  97. package/packages/mailx-compose/index.d.ts +21 -0
  98. package/packages/mailx-compose/index.d.ts.map +1 -0
  99. package/packages/mailx-compose/index.js +61 -0
  100. package/packages/mailx-compose/index.js.map +1 -0
  101. package/packages/mailx-compose/index.ts +85 -0
  102. package/packages/mailx-compose/package.json +18 -0
  103. package/packages/mailx-compose/tsconfig.json +9 -0
  104. package/packages/mailx-core/index.d.ts +139 -0
  105. package/packages/mailx-core/index.d.ts.map +1 -0
  106. package/packages/mailx-core/index.js +403 -0
  107. package/packages/mailx-core/index.js.map +1 -0
  108. package/packages/mailx-core/index.ts +424 -0
  109. package/packages/mailx-core/ipc.d.ts +13 -0
  110. package/packages/mailx-core/ipc.d.ts.map +1 -0
  111. package/packages/mailx-core/ipc.js +56 -0
  112. package/packages/mailx-core/ipc.js.map +1 -0
  113. package/packages/mailx-core/ipc.ts +62 -0
  114. package/packages/mailx-core/package.json +18 -0
  115. package/packages/mailx-core/tsconfig.json +9 -0
  116. package/packages/mailx-host/.gitattributes +10 -0
  117. package/packages/mailx-host/index.d.ts +21 -0
  118. package/packages/mailx-host/index.d.ts.map +1 -0
  119. package/packages/mailx-host/index.js +29 -0
  120. package/packages/mailx-host/index.js.map +1 -0
  121. package/packages/mailx-host/index.ts +38 -0
  122. package/packages/mailx-host/package.json +23 -0
  123. package/packages/mailx-host/tsconfig.json +9 -0
  124. package/packages/mailx-host/types-shim.d.ts +14 -0
  125. package/packages/mailx-imap/.gitattributes +10 -0
  126. package/packages/mailx-imap/index.d.ts +442 -0
  127. package/packages/mailx-imap/index.d.ts.map +1 -0
  128. package/packages/mailx-imap/index.js +3684 -0
  129. package/packages/mailx-imap/index.js.map +1 -0
  130. package/packages/mailx-imap/index.ts +3652 -0
  131. package/packages/mailx-imap/package-lock.json +131 -0
  132. package/packages/mailx-imap/package.json +28 -0
  133. package/packages/mailx-imap/providers/gmail-api.d.ts +8 -0
  134. package/packages/mailx-imap/providers/gmail-api.d.ts.map +1 -0
  135. package/packages/mailx-imap/providers/gmail-api.js +8 -0
  136. package/packages/mailx-imap/providers/gmail-api.js.map +1 -0
  137. package/packages/mailx-imap/providers/gmail-api.ts +8 -0
  138. package/packages/mailx-imap/providers/outlook-api.ts +7 -0
  139. package/packages/mailx-imap/providers/types.d.ts +9 -0
  140. package/packages/mailx-imap/providers/types.d.ts.map +1 -0
  141. package/packages/mailx-imap/providers/types.js +9 -0
  142. package/packages/mailx-imap/providers/types.js.map +1 -0
  143. package/packages/mailx-imap/providers/types.ts +9 -0
  144. package/packages/mailx-imap/tsconfig.json +9 -0
  145. package/packages/mailx-imap/tsconfig.tsbuildinfo +1 -0
  146. package/packages/mailx-send/.gitattributes +10 -0
  147. package/packages/mailx-send/README.md +217 -0
  148. package/packages/mailx-send/cli-queue.d.ts +11 -0
  149. package/packages/mailx-send/cli-queue.d.ts.map +1 -0
  150. package/packages/mailx-send/cli-queue.js +59 -0
  151. package/packages/mailx-send/cli-queue.js.map +1 -0
  152. package/packages/mailx-send/cli-queue.ts +62 -0
  153. package/packages/mailx-send/cli-send.d.ts +17 -0
  154. package/packages/mailx-send/cli-send.d.ts.map +1 -0
  155. package/packages/mailx-send/cli-send.js +75 -0
  156. package/packages/mailx-send/cli-send.js.map +1 -0
  157. package/packages/mailx-send/cli-send.ts +83 -0
  158. package/packages/mailx-send/cli.d.ts +22 -0
  159. package/packages/mailx-send/cli.d.ts.map +1 -0
  160. package/packages/mailx-send/cli.js +115 -0
  161. package/packages/mailx-send/cli.js.map +1 -0
  162. package/packages/mailx-send/cli.ts +126 -0
  163. package/packages/mailx-send/index.d.ts +77 -0
  164. package/packages/mailx-send/index.d.ts.map +1 -0
  165. package/packages/mailx-send/index.js +264 -0
  166. package/packages/mailx-send/index.js.map +1 -0
  167. package/packages/mailx-send/index.ts +333 -0
  168. package/packages/mailx-send/mailsend/README.md +133 -0
  169. package/packages/mailx-send/mailsend/cli.d.ts +12 -0
  170. package/packages/mailx-send/mailsend/cli.d.ts.map +1 -0
  171. package/packages/mailx-send/mailsend/cli.js +70 -0
  172. package/packages/mailx-send/mailsend/cli.js.map +1 -0
  173. package/packages/mailx-send/mailsend/cli.ts +81 -0
  174. package/packages/mailx-send/mailsend/index.d.ts +77 -0
  175. package/packages/mailx-send/mailsend/index.d.ts.map +1 -0
  176. package/packages/mailx-send/mailsend/index.js +264 -0
  177. package/packages/mailx-send/mailsend/index.js.map +1 -0
  178. package/packages/mailx-send/mailsend/index.ts +333 -0
  179. package/packages/mailx-send/mailsend/package-lock.json +65 -0
  180. package/packages/mailx-send/mailsend/package.json +26 -0
  181. package/packages/mailx-send/mailsend/tsconfig.json +21 -0
  182. package/packages/mailx-send/package-lock.json +65 -0
  183. package/packages/mailx-send/package.json +37 -0
  184. package/packages/mailx-send/tsconfig.json +21 -0
  185. package/packages/mailx-server/.gitattributes +10 -0
  186. package/packages/mailx-server/index.d.ts +8 -0
  187. package/packages/mailx-server/index.d.ts.map +1 -0
  188. package/packages/mailx-server/index.js +397 -0
  189. package/packages/mailx-server/index.js.map +1 -0
  190. package/packages/mailx-server/index.ts +429 -0
  191. package/packages/mailx-server/package.json +28 -0
  192. package/packages/mailx-server/tsconfig.json +9 -0
  193. package/packages/mailx-server/tsconfig.tsbuildinfo +1 -0
  194. package/packages/mailx-service/google-sync.d.ts +96 -0
  195. package/packages/mailx-service/google-sync.d.ts.map +1 -0
  196. package/packages/mailx-service/google-sync.js +153 -0
  197. package/packages/mailx-service/google-sync.js.map +1 -0
  198. package/packages/mailx-service/google-sync.ts +238 -0
  199. package/packages/mailx-service/index.d.ts +366 -0
  200. package/packages/mailx-service/index.d.ts.map +1 -0
  201. package/packages/mailx-service/index.js +2589 -0
  202. package/packages/mailx-service/index.js.map +1 -0
  203. package/packages/mailx-service/index.ts +2512 -0
  204. package/packages/mailx-service/jsonrpc.d.ts +25 -0
  205. package/packages/mailx-service/jsonrpc.d.ts.map +1 -0
  206. package/packages/mailx-service/jsonrpc.js +238 -0
  207. package/packages/mailx-service/jsonrpc.js.map +1 -0
  208. package/packages/mailx-service/jsonrpc.ts +268 -0
  209. package/packages/mailx-service/package.json +22 -0
  210. package/packages/mailx-service/tsconfig.json +9 -0
  211. package/packages/mailx-settings/.gitattributes +10 -0
  212. package/packages/mailx-settings/cloud.d.ts +47 -0
  213. package/packages/mailx-settings/cloud.d.ts.map +1 -0
  214. package/packages/mailx-settings/cloud.js +408 -0
  215. package/packages/mailx-settings/cloud.js.map +1 -0
  216. package/packages/mailx-settings/cloud.ts +393 -0
  217. package/packages/mailx-settings/index.d.ts +140 -0
  218. package/packages/mailx-settings/index.d.ts.map +1 -0
  219. package/packages/mailx-settings/index.js +872 -0
  220. package/packages/mailx-settings/index.js.map +1 -0
  221. package/packages/mailx-settings/index.ts +908 -0
  222. package/packages/mailx-settings/package.json +20 -0
  223. package/packages/mailx-settings/tsconfig.json +9 -0
  224. package/packages/mailx-settings/tsconfig.tsbuildinfo +1 -0
  225. package/packages/mailx-store/.gitattributes +10 -0
  226. package/packages/mailx-store/db.d.ts +346 -0
  227. package/packages/mailx-store/db.d.ts.map +1 -0
  228. package/packages/mailx-store/db.js +1796 -0
  229. package/packages/mailx-store/db.js.map +1 -0
  230. package/packages/mailx-store/db.ts +2007 -0
  231. package/packages/mailx-store/file-store.d.ts +36 -0
  232. package/packages/mailx-store/file-store.d.ts.map +1 -0
  233. package/packages/mailx-store/file-store.js +80 -0
  234. package/packages/mailx-store/file-store.js.map +1 -0
  235. package/packages/mailx-store/file-store.ts +82 -0
  236. package/packages/mailx-store/index.d.ts +7 -0
  237. package/packages/mailx-store/index.d.ts.map +1 -0
  238. package/packages/mailx-store/index.js +7 -0
  239. package/packages/mailx-store/index.js.map +1 -0
  240. package/packages/mailx-store/index.ts +7 -0
  241. package/packages/mailx-store/package.json +19 -0
  242. package/packages/mailx-store/tsconfig.json +9 -0
  243. package/packages/mailx-store/tsconfig.tsbuildinfo +1 -0
  244. package/packages/mailx-store-web/android-bootstrap.d.ts +16 -0
  245. package/packages/mailx-store-web/android-bootstrap.d.ts.map +1 -0
  246. package/packages/mailx-store-web/android-bootstrap.js +1247 -0
  247. package/packages/mailx-store-web/android-bootstrap.js.map +1 -0
  248. package/packages/mailx-store-web/android-bootstrap.ts +1262 -0
  249. package/packages/mailx-store-web/db.d.ts +132 -0
  250. package/packages/mailx-store-web/db.d.ts.map +1 -0
  251. package/packages/mailx-store-web/db.js +642 -0
  252. package/packages/mailx-store-web/db.js.map +1 -0
  253. package/packages/mailx-store-web/db.ts +756 -0
  254. package/packages/mailx-store-web/gmail-api-web.d.ts +11 -0
  255. package/packages/mailx-store-web/gmail-api-web.d.ts.map +1 -0
  256. package/packages/mailx-store-web/gmail-api-web.js +11 -0
  257. package/packages/mailx-store-web/gmail-api-web.js.map +1 -0
  258. package/packages/mailx-store-web/gmail-api-web.ts +11 -0
  259. package/packages/mailx-store-web/imap-web-provider.d.ts +33 -0
  260. package/packages/mailx-store-web/imap-web-provider.d.ts.map +1 -0
  261. package/packages/mailx-store-web/imap-web-provider.js +140 -0
  262. package/packages/mailx-store-web/imap-web-provider.js.map +1 -0
  263. package/packages/mailx-store-web/imap-web-provider.ts +156 -0
  264. package/packages/mailx-store-web/index.d.ts +10 -0
  265. package/packages/mailx-store-web/index.d.ts.map +1 -0
  266. package/packages/mailx-store-web/index.js +10 -0
  267. package/packages/mailx-store-web/index.js.map +1 -0
  268. package/packages/mailx-store-web/index.ts +10 -0
  269. package/packages/mailx-store-web/main-thread-host.d.ts +15 -0
  270. package/packages/mailx-store-web/main-thread-host.d.ts.map +1 -0
  271. package/packages/mailx-store-web/main-thread-host.js +292 -0
  272. package/packages/mailx-store-web/main-thread-host.js.map +1 -0
  273. package/packages/mailx-store-web/main-thread-host.ts +322 -0
  274. package/packages/mailx-store-web/package.json +23 -0
  275. package/packages/mailx-store-web/provider-types.d.ts +7 -0
  276. package/packages/mailx-store-web/provider-types.d.ts.map +1 -0
  277. package/packages/mailx-store-web/provider-types.js +7 -0
  278. package/packages/mailx-store-web/provider-types.js.map +1 -0
  279. package/packages/mailx-store-web/provider-types.ts +7 -0
  280. package/packages/mailx-store-web/sql-wasm-esm.js +10 -0
  281. package/packages/mailx-store-web/sql.js.d.ts +29 -0
  282. package/packages/mailx-store-web/sync-manager.d.ts +68 -0
  283. package/packages/mailx-store-web/sync-manager.d.ts.map +1 -0
  284. package/packages/mailx-store-web/sync-manager.js +506 -0
  285. package/packages/mailx-store-web/sync-manager.js.map +1 -0
  286. package/packages/mailx-store-web/sync-manager.ts +508 -0
  287. package/packages/mailx-store-web/tsconfig.json +10 -0
  288. package/packages/mailx-store-web/web-jsonrpc.d.ts +20 -0
  289. package/packages/mailx-store-web/web-jsonrpc.d.ts.map +1 -0
  290. package/packages/mailx-store-web/web-jsonrpc.js +102 -0
  291. package/packages/mailx-store-web/web-jsonrpc.js.map +1 -0
  292. package/packages/mailx-store-web/web-jsonrpc.ts +116 -0
  293. package/packages/mailx-store-web/web-message-store.d.ts +16 -0
  294. package/packages/mailx-store-web/web-message-store.d.ts.map +1 -0
  295. package/packages/mailx-store-web/web-message-store.js +89 -0
  296. package/packages/mailx-store-web/web-message-store.js.map +1 -0
  297. package/packages/mailx-store-web/web-message-store.ts +97 -0
  298. package/packages/mailx-store-web/web-service.d.ts +111 -0
  299. package/packages/mailx-store-web/web-service.d.ts.map +1 -0
  300. package/packages/mailx-store-web/web-service.js +542 -0
  301. package/packages/mailx-store-web/web-service.js.map +1 -0
  302. package/packages/mailx-store-web/web-service.ts +616 -0
  303. package/packages/mailx-store-web/web-settings.d.ts +83 -0
  304. package/packages/mailx-store-web/web-settings.d.ts.map +1 -0
  305. package/packages/mailx-store-web/web-settings.js +491 -0
  306. package/packages/mailx-store-web/web-settings.js.map +1 -0
  307. package/packages/mailx-store-web/web-settings.ts +522 -0
  308. package/packages/mailx-store-web/worker-bundle.js +6838 -0
  309. package/packages/mailx-store-web/worker-entry.d.ts +8 -0
  310. package/packages/mailx-store-web/worker-entry.d.ts.map +1 -0
  311. package/packages/mailx-store-web/worker-entry.js +187 -0
  312. package/packages/mailx-store-web/worker-entry.js.map +1 -0
  313. package/packages/mailx-store-web/worker-entry.ts +215 -0
  314. package/packages/mailx-store-web/worker-tcp-transport.d.ts +28 -0
  315. package/packages/mailx-store-web/worker-tcp-transport.d.ts.map +1 -0
  316. package/packages/mailx-store-web/worker-tcp-transport.js +98 -0
  317. package/packages/mailx-store-web/worker-tcp-transport.js.map +1 -0
  318. package/packages/mailx-store-web/worker-tcp-transport.ts +101 -0
  319. package/packages/mailx-types/.gitattributes +10 -0
  320. package/packages/mailx-types/index.d.ts +319 -0
  321. package/packages/mailx-types/index.d.ts.map +1 -0
  322. package/packages/mailx-types/index.js +243 -0
  323. package/packages/mailx-types/index.js.map +1 -0
  324. package/packages/mailx-types/index.ts +498 -0
  325. package/packages/mailx-types/package.json +16 -0
  326. package/packages/mailx-types/tsconfig.json +9 -0
  327. package/packages/mailx-types/tsconfig.tsbuildinfo +1 -0
  328. package/todo.json +13 -0
  329. package/tsconfig.base.json +31 -0
  330. package/tsconfig.json +9 -0
@@ -0,0 +1,333 @@
1
+ /**
2
+ * @bobfrankston/mailsend
3
+ * Queue-based mail sender. Each account has its own queue directory.
4
+ * Messages queued as .ltr (RFC 822) files, sent via SMTP with retry.
5
+ * Supports password and OAuth2 (Gmail) authentication.
6
+ *
7
+ * Directory structure:
8
+ * {baseDir}/{accountId}/queue/ — pending .ltr files
9
+ * {baseDir}/{accountId}/sent/ — sent messages (optional, YYYY/MM/DD)
10
+ * {baseDir}/{accountId}/fail/ — failed messages for retry
11
+ */
12
+
13
+ import * as fs from "node:fs";
14
+ import * as path from "node:path";
15
+ import { createTransport, type Transporter } from "nodemailer";
16
+
17
+ // ── Types ──
18
+
19
+ export interface SmtpConfig {
20
+ host: string;
21
+ port: number;
22
+ secure?: boolean;
23
+ auth: "password" | "oauth2";
24
+ user: string;
25
+ password?: string;
26
+ /** Default From address, e.g. "Bob Frankston <bob@iecc.com>" */
27
+ from?: string;
28
+ tokenProvider?: () => Promise<string>;
29
+ }
30
+
31
+ export interface MailMessage {
32
+ from: string;
33
+ to: string[];
34
+ cc?: string[];
35
+ bcc?: string[];
36
+ subject: string;
37
+ html?: string;
38
+ text?: string;
39
+ inReplyTo?: string;
40
+ references?: string;
41
+ accountId?: string;
42
+ }
43
+
44
+ export interface MailSendConfig {
45
+ /** Base directory for all queues */
46
+ baseDir: string;
47
+ /** SMTP configs keyed by account ID */
48
+ accounts: Record<string, SmtpConfig>;
49
+ /** Log sent messages to sent/ subdirectory */
50
+ logSent?: boolean;
51
+ /** Retry interval in ms (default: 5 minutes) */
52
+ retryIntervalMs?: number;
53
+ /** Default account ID */
54
+ defaultAccount?: string;
55
+ }
56
+
57
+ // ── File helpers ──
58
+
59
+ function generateFilename(): string {
60
+ const now = new Date();
61
+ const pad2 = (n: number) => String(n).padStart(2, "0");
62
+ const ts = `${now.getFullYear()}${pad2(now.getMonth() + 1)}${pad2(now.getDate())}_${pad2(now.getHours())}${pad2(now.getMinutes())}${pad2(now.getSeconds())}`;
63
+ const seq = String(Math.floor(Math.random() * 10000)).padStart(4, "0");
64
+ return `${ts}-${seq}.ltr`;
65
+ }
66
+
67
+ function datePath(): string {
68
+ const dt = new Date();
69
+ const pad2 = (n: number) => String(n).padStart(2, "0");
70
+ return `${dt.getFullYear()}/${pad2(dt.getMonth() + 1)}/${pad2(dt.getDate())}`;
71
+ }
72
+
73
+ function moveToDateDir(filePath: string, destBase: string): void {
74
+ const dest = path.join(destBase, datePath());
75
+ fs.mkdirSync(dest, { recursive: true });
76
+ fs.renameSync(filePath, path.join(dest, path.basename(filePath)));
77
+ }
78
+
79
+ function listLtr(dir: string): string[] {
80
+ if (!fs.existsSync(dir)) return [];
81
+ return fs.readdirSync(dir).filter(f => f.endsWith(".ltr")).sort();
82
+ }
83
+
84
+ function walkLtrCount(dir: string): number {
85
+ if (!fs.existsSync(dir)) return 0;
86
+ let count = 0;
87
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
88
+ if (entry.isDirectory()) count += walkLtrCount(path.join(dir, entry.name));
89
+ else if (entry.name.endsWith(".ltr")) count++;
90
+ }
91
+ return count;
92
+ }
93
+
94
+ function walkLtrFiles(dir: string): string[] {
95
+ if (!fs.existsSync(dir)) return [];
96
+ const files: string[] = [];
97
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
98
+ const full = path.join(dir, entry.name);
99
+ if (entry.isDirectory()) files.push(...walkLtrFiles(full));
100
+ else if (entry.name.endsWith(".ltr")) files.push(full);
101
+ }
102
+ return files;
103
+ }
104
+
105
+ // ── RFC 822 builder ──
106
+
107
+ export function buildRfc822(msg: MailMessage): string {
108
+ const lines: string[] = [];
109
+ lines.push(`From: ${msg.from}`);
110
+ lines.push(`To: ${msg.to.join(", ")}`);
111
+ if (msg.cc?.length) lines.push(`Cc: ${msg.cc.join(", ")}`);
112
+ if (msg.bcc?.length) lines.push(`Bcc: ${msg.bcc.join(", ")}`);
113
+ lines.push(`Subject: ${msg.subject}`);
114
+ lines.push(`Date: ${new Date().toUTCString()}`);
115
+ if (msg.inReplyTo) lines.push(`In-Reply-To: ${msg.inReplyTo}`);
116
+ if (msg.references) lines.push(`References: ${msg.references}`);
117
+ if (msg.accountId) lines.push(`X-MailSend-Account: ${msg.accountId}`);
118
+ lines.push(`MIME-Version: 1.0`);
119
+
120
+ if (msg.html) {
121
+ lines.push(`Content-Type: text/html; charset=UTF-8`);
122
+ lines.push(`Content-Transfer-Encoding: 8bit`);
123
+ lines.push("");
124
+ lines.push(msg.html);
125
+ } else {
126
+ lines.push(`Content-Type: text/plain; charset=UTF-8`);
127
+ lines.push(`Content-Transfer-Encoding: 8bit`);
128
+ lines.push("");
129
+ lines.push(msg.text || "");
130
+ }
131
+
132
+ return lines.join("\r\n");
133
+ }
134
+
135
+ // ── Transport cache ──
136
+
137
+ const transports: Map<string, Transporter> = new Map();
138
+
139
+ function getTransport(config: SmtpConfig): Transporter {
140
+ const key = `${config.host}:${config.port}:${config.user}`;
141
+ let transport = transports.get(key);
142
+ if (!transport) {
143
+ const opts: any = {
144
+ host: config.host,
145
+ port: config.port,
146
+ secure: config.secure ?? (config.port === 465),
147
+ tls: { rejectUnauthorized: false },
148
+ };
149
+
150
+ if (config.auth === "password") {
151
+ opts.auth = { user: config.user, pass: config.password };
152
+ } else if (config.auth === "oauth2") {
153
+ opts.auth = { type: "OAuth2", user: config.user };
154
+ }
155
+
156
+ transport = createTransport(opts);
157
+ transports.set(key, transport);
158
+ }
159
+ return transport;
160
+ }
161
+
162
+ // ── MailSender ──
163
+
164
+ let singleton: MailSender | null = null;
165
+
166
+ export class MailSender {
167
+ private config: MailSendConfig;
168
+ private processing = false;
169
+ private retryTimer: ReturnType<typeof setInterval> | null = null;
170
+
171
+ constructor(config: MailSendConfig) {
172
+ this.config = config;
173
+ // Ensure base directory exists
174
+ fs.mkdirSync(config.baseDir, { recursive: true });
175
+ }
176
+
177
+ private accountDir(accountId: string): string {
178
+ return path.join(this.config.baseDir, accountId);
179
+ }
180
+
181
+ private queueDir(accountId: string): string {
182
+ const dir = path.join(this.accountDir(accountId), "queue");
183
+ fs.mkdirSync(dir, { recursive: true });
184
+ return dir;
185
+ }
186
+
187
+ private sentDir(accountId: string): string {
188
+ return path.join(this.accountDir(accountId), "sent");
189
+ }
190
+
191
+ private failDir(accountId: string): string {
192
+ const dir = path.join(this.accountDir(accountId), "fail");
193
+ fs.mkdirSync(dir, { recursive: true });
194
+ return dir;
195
+ }
196
+
197
+ /** Queue a message. Returns the filename. */
198
+ queueMessage(msg: MailMessage): string {
199
+ const accountId = msg.accountId || this.config.defaultAccount;
200
+ if (!accountId) throw new Error("No accountId and no defaultAccount configured");
201
+ msg.accountId = accountId;
202
+
203
+ const content = buildRfc822(msg);
204
+ const filename = generateFilename();
205
+ fs.writeFileSync(path.join(this.queueDir(accountId), filename), content);
206
+
207
+ // Process immediately (non-blocking)
208
+ this.processQueue(accountId).catch(e =>
209
+ console.error(`[mailsend] Process error: ${e.message}`)
210
+ );
211
+
212
+ return filename;
213
+ }
214
+
215
+ /** Process pending messages for one account */
216
+ async processQueue(accountId: string): Promise<void> {
217
+ if (this.processing) return;
218
+ this.processing = true;
219
+
220
+ try {
221
+ const smtpConfig = this.config.accounts[accountId];
222
+ if (!smtpConfig) {
223
+ console.error(`[mailsend] No SMTP config for: ${accountId}`);
224
+ return;
225
+ }
226
+
227
+ const files = listLtr(this.queueDir(accountId));
228
+ for (const file of files) {
229
+ await this.sendFile(path.join(this.queueDir(accountId), file), accountId, smtpConfig);
230
+ }
231
+ } finally {
232
+ this.processing = false;
233
+ }
234
+ }
235
+
236
+ /** Process all account queues */
237
+ async processAllQueues(): Promise<void> {
238
+ for (const accountId of Object.keys(this.config.accounts)) {
239
+ await this.processQueue(accountId);
240
+ }
241
+ }
242
+
243
+ private async sendFile(filePath: string, accountId: string, smtpConfig: SmtpConfig): Promise<boolean> {
244
+ const content = fs.readFileSync(filePath, "utf-8");
245
+
246
+ try {
247
+ const transport = getTransport(smtpConfig);
248
+
249
+ if (smtpConfig.auth === "oauth2" && smtpConfig.tokenProvider) {
250
+ const token = await smtpConfig.tokenProvider();
251
+ (transport as any).options.auth.accessToken = token;
252
+ }
253
+
254
+ const result = await transport.sendMail({ raw: content });
255
+
256
+ if (result.rejected?.length > 0) {
257
+ console.error(`[mailsend] Rejected: ${result.rejected.join(", ")} — ${path.basename(filePath)}`);
258
+ moveToDateDir(filePath, this.failDir(accountId));
259
+ return false;
260
+ }
261
+
262
+ console.log(`[mailsend] Sent: ${path.basename(filePath)} → ${result.accepted?.join(", ")} (${result.messageId})`);
263
+
264
+ if (this.config.logSent) {
265
+ moveToDateDir(filePath, this.sentDir(accountId));
266
+ } else {
267
+ fs.unlinkSync(filePath);
268
+ }
269
+ return true;
270
+ } catch (e: any) {
271
+ console.error(`[mailsend] Error: ${path.basename(filePath)}: ${e.message}`);
272
+ moveToDateDir(filePath, this.failDir(accountId));
273
+ return false;
274
+ }
275
+ }
276
+
277
+ /** Start background worker — retries failed, processes queues */
278
+ startWorker(): void {
279
+ if (this.retryTimer) return;
280
+ const interval = this.config.retryIntervalMs || 300000;
281
+
282
+ this.retryTimer = setInterval(async () => {
283
+ for (const accountId of Object.keys(this.config.accounts)) {
284
+ this.retryFailed(accountId);
285
+ }
286
+ await this.processAllQueues();
287
+ }, interval);
288
+ }
289
+
290
+ private retryFailed(accountId: string): void {
291
+ const failFiles = walkLtrFiles(this.failDir(accountId));
292
+ const queueDir = this.queueDir(accountId);
293
+ for (const file of failFiles) {
294
+ fs.renameSync(file, path.join(queueDir, path.basename(file)));
295
+ }
296
+ }
297
+
298
+ stopWorker(): void {
299
+ if (this.retryTimer) {
300
+ clearInterval(this.retryTimer);
301
+ this.retryTimer = null;
302
+ }
303
+ }
304
+
305
+ /** Get queue status per account */
306
+ getStatus(): Record<string, { pending: number; failed: number }> {
307
+ const result: Record<string, { pending: number; failed: number }> = {};
308
+ for (const accountId of Object.keys(this.config.accounts)) {
309
+ result[accountId] = {
310
+ pending: listLtr(this.queueDir(accountId)).length,
311
+ failed: walkLtrCount(this.failDir(accountId)),
312
+ };
313
+ }
314
+ return result;
315
+ }
316
+ }
317
+
318
+ // ── Singleton API ──
319
+
320
+ export function initMailSend(config: MailSendConfig): MailSender {
321
+ singleton = new MailSender(config);
322
+ singleton.startWorker();
323
+ return singleton;
324
+ }
325
+
326
+ export function getMailSender(): MailSender | null {
327
+ return singleton;
328
+ }
329
+
330
+ export function queueMessage(msg: MailMessage): string {
331
+ if (!singleton) throw new Error("mailsend not initialized — call initMailSend() first");
332
+ return singleton.queueMessage(msg);
333
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@bobfrankston/mailsend",
3
+ "version": "0.1.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@bobfrankston/mailsend",
9
+ "version": "0.1.0",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@bobfrankston/oauthsupport": "file:../../projects/oauth/oauthsupport",
13
+ "nodemailer": "^7.0.0"
14
+ },
15
+ "bin": {
16
+ "mailsend": "cli.js"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^22.0.0",
20
+ "@types/nodemailer": "^6.4.0"
21
+ }
22
+ },
23
+ "../../projects/oauth/oauthsupport": {},
24
+ "node_modules/@bobfrankston/oauthsupport": {
25
+ "resolved": "../../projects/oauth/oauthsupport",
26
+ "link": true
27
+ },
28
+ "node_modules/@types/node": {
29
+ "version": "22.19.15",
30
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.15.tgz",
31
+ "integrity": "sha512-F0R/h2+dsy5wJAUe3tAU6oqa2qbWY5TpNfL/RGmo1y38hiyO1w3x2jPtt76wmuaJI4DQnOBu21cNXQ2STIUUWg==",
32
+ "dev": true,
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "undici-types": "~6.21.0"
36
+ }
37
+ },
38
+ "node_modules/@types/nodemailer": {
39
+ "version": "6.4.23",
40
+ "resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.23.tgz",
41
+ "integrity": "sha512-aFV3/NsYFLSx9mbb5gtirBSXJnAlrusoKNuPbxsASWc7vrKLmIrTQRpdcxNcSFL3VW2A2XpeLEavwb2qMi6nlQ==",
42
+ "dev": true,
43
+ "license": "MIT",
44
+ "dependencies": {
45
+ "@types/node": "*"
46
+ }
47
+ },
48
+ "node_modules/nodemailer": {
49
+ "version": "7.0.13",
50
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.13.tgz",
51
+ "integrity": "sha512-PNDFSJdP+KFgdsG3ZzMXCgquO7I6McjY2vlqILjtJd0hy8wEvtugS9xKRF2NWlPNGxvLCXlTNIae4serI7dinw==",
52
+ "license": "MIT-0",
53
+ "engines": {
54
+ "node": ">=6.0.0"
55
+ }
56
+ },
57
+ "node_modules/undici-types": {
58
+ "version": "6.21.0",
59
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
60
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
61
+ "dev": true,
62
+ "license": "MIT"
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@bobfrankston/mailsend",
3
+ "version": "0.1.0",
4
+ "description": "Queue-based mail sender with SMTP and OAuth2 support",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "bin": {
9
+ "mailsend": "cli.js"
10
+ },
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "release": "npmglobalize"
14
+ },
15
+ "keywords": ["email", "smtp", "queue", "oauth2", "gmail"],
16
+ "author": "Bob Frankston",
17
+ "license": "MIT",
18
+ "dependencies": {
19
+ "nodemailer": "^7.0.0",
20
+ "@bobfrankston/oauthsupport": "file:../../projects/oauth/oauthsupport"
21
+ },
22
+ "devDependencies": {
23
+ "@types/nodemailer": "^6.4.0",
24
+ "@types/node": "^22.0.0"
25
+ }
26
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "allowSyntheticDefaultImports": true,
7
+ "esModuleInterop": true,
8
+ "strict": true,
9
+ "strictNullChecks": false,
10
+ "noImplicitAny": true,
11
+ "skipLibCheck": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "outDir": ".",
16
+ "rootDir": ".",
17
+ "newLine": "lf"
18
+ },
19
+ "include": ["*.ts"],
20
+ "exclude": ["node_modules", "prev", "cruft"]
21
+ }
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@bobfrankston/mailsend",
3
+ "version": "0.1.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@bobfrankston/mailsend",
9
+ "version": "0.1.1",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@bobfrankston/oauthsupport": "file:../../projects/oauth/oauthsupport",
13
+ "nodemailer": "^7.0.0"
14
+ },
15
+ "bin": {
16
+ "mailsend": "cli.js"
17
+ },
18
+ "devDependencies": {
19
+ "@types/node": "^22.0.0",
20
+ "@types/nodemailer": "^6.4.0"
21
+ }
22
+ },
23
+ "../../projects/oauth/oauthsupport": {},
24
+ "node_modules/@bobfrankston/oauthsupport": {
25
+ "resolved": "../../projects/oauth/oauthsupport",
26
+ "link": true
27
+ },
28
+ "node_modules/@types/node": {
29
+ "version": "22.19.15",
30
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-22.19.15.tgz",
31
+ "integrity": "sha512-F0R/h2+dsy5wJAUe3tAU6oqa2qbWY5TpNfL/RGmo1y38hiyO1w3x2jPtt76wmuaJI4DQnOBu21cNXQ2STIUUWg==",
32
+ "dev": true,
33
+ "license": "MIT",
34
+ "dependencies": {
35
+ "undici-types": "~6.21.0"
36
+ }
37
+ },
38
+ "node_modules/@types/nodemailer": {
39
+ "version": "6.4.23",
40
+ "resolved": "https://registry.npmjs.org/@types/nodemailer/-/nodemailer-6.4.23.tgz",
41
+ "integrity": "sha512-aFV3/NsYFLSx9mbb5gtirBSXJnAlrusoKNuPbxsASWc7vrKLmIrTQRpdcxNcSFL3VW2A2XpeLEavwb2qMi6nlQ==",
42
+ "dev": true,
43
+ "license": "MIT",
44
+ "dependencies": {
45
+ "@types/node": "*"
46
+ }
47
+ },
48
+ "node_modules/nodemailer": {
49
+ "version": "7.0.13",
50
+ "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.13.tgz",
51
+ "integrity": "sha512-PNDFSJdP+KFgdsG3ZzMXCgquO7I6McjY2vlqILjtJd0hy8wEvtugS9xKRF2NWlPNGxvLCXlTNIae4serI7dinw==",
52
+ "license": "MIT-0",
53
+ "engines": {
54
+ "node": ">=6.0.0"
55
+ }
56
+ },
57
+ "node_modules/undici-types": {
58
+ "version": "6.21.0",
59
+ "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
60
+ "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
61
+ "dev": true,
62
+ "license": "MIT"
63
+ }
64
+ }
65
+ }
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@bobfrankston/mailx-send",
3
+ "version": "0.1.1",
4
+ "description": "Queue-based mail sender with SMTP and OAuth2 support",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "types": "index.d.ts",
8
+ "bin": {
9
+ "mailsend": "cli-send.js",
10
+ "mailq": "cli-queue.js"
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "release": "npmglobalize"
15
+ },
16
+ "keywords": [
17
+ "email",
18
+ "smtp",
19
+ "queue",
20
+ "oauth2",
21
+ "gmail"
22
+ ],
23
+ "author": "Bob Frankston",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "nodemailer": "^7.0.0",
27
+ "@bobfrankston/oauthsupport": "file:../../../../../projects/oauth/oauthsupport"
28
+ },
29
+ "devDependencies": {
30
+ "@types/nodemailer": "^6.4.0",
31
+ "@types/node": "^22.0.0"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/BobFrankston/mailx-send.git"
36
+ }
37
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "allowSyntheticDefaultImports": true,
7
+ "esModuleInterop": true,
8
+ "strict": true,
9
+ "strictNullChecks": false,
10
+ "noImplicitAny": true,
11
+ "skipLibCheck": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "outDir": ".",
16
+ "rootDir": ".",
17
+ "newLine": "lf"
18
+ },
19
+ "include": ["*.ts"],
20
+ "exclude": ["node_modules", "prev", "cruft"]
21
+ }
@@ -0,0 +1,10 @@
1
+ # Force LF line endings for all text files
2
+ * text=auto eol=lf
3
+
4
+ # Ensure these are always LF
5
+ *.ts text eol=lf
6
+ *.js text eol=lf
7
+ *.json text eol=lf
8
+ *.md text eol=lf
9
+ *.yml text eol=lf
10
+ *.yaml text eol=lf
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @bobfrankston/mailx-server
3
+ * Express server: serves client, mounts API, manages WebSocket push.
4
+ */
5
+ declare const app: import("express-serve-static-core").Express;
6
+ declare function start(): Promise<void>;
7
+ export { app, start };
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAoEH,QAAA,MAAM,GAAG,6CAAY,CAAC;AAmOtB,iBAAe,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAyFpC;AAyCD,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC"}