tossinbox 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/cli.js +116 -1
- package/dist/core/index.js +3 -2
- package/dist/core/otp.js +28 -2
- package/dist/core/providers/mailtm.js +137 -118
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ $ tossinbox toss
|
|
|
55
55
|
| Documented exit codes | 0–4 | none | no |
|
|
56
56
|
| MCP server for agents | yes, built in | no | no |
|
|
57
57
|
| Runs headless / in CI | yes | no | partial |
|
|
58
|
-
| Upstream alive | mail.tm + GuerrillaMail | varies | many wrap the dead 1secmail |
|
|
58
|
+
| Upstream alive | mail.tm + mail.gw + GuerrillaMail | varies | many wrap the dead 1secmail |
|
|
59
59
|
| Ads, trackers, popups | none | the business model | none |
|
|
60
60
|
|
|
61
61
|
Checked September 2026. If a cell is wrong, open an issue and win the argument.
|
|
@@ -111,6 +111,7 @@ tossinbox wait --code --json
|
|
|
111
111
|
| `list` | List messages (`-a address`) |
|
|
112
112
|
| `read <id>` | Read a full message, including any detected code |
|
|
113
113
|
| `wait` | Poll until a message arrives (`-f sender`, `-s subject`, `-c` extract code, `-t timeout` max 600s) |
|
|
114
|
+
| `watch` | Stream new messages until Ctrl-C — only new arrivals; `--json` = one JSON object per line (NDJSON) |
|
|
114
115
|
| `inboxes` | List locally saved inboxes |
|
|
115
116
|
| `toss` | Delete an inbox server-side and remove it from local state (`--all` for every inbox) |
|
|
116
117
|
| `clear` | Remove all inboxes from local state only |
|
|
@@ -215,6 +216,7 @@ machine-readable and kept up to date.
|
|
|
215
216
|
| Provider | API key | Notes |
|
|
216
217
|
|---|---|---|
|
|
217
218
|
| `mailtm` (default) | not required | mail.tm — reliable, fast |
|
|
219
|
+
| `mailgw` | not required | mail.gw — mail.tm-compatible API on independent infrastructure |
|
|
218
220
|
| `guerrillamail` | not required | GuerrillaMail — classic fallback |
|
|
219
221
|
|
|
220
222
|
Adding a provider means implementing a small interface (`createInbox`,
|
|
@@ -223,7 +225,7 @@ Adding a provider means implementing a small interface (`createInbox`,
|
|
|
223
225
|
## FAQ
|
|
224
226
|
|
|
225
227
|
**Is it really free?**
|
|
226
|
-
Yes. MIT-licensed, and
|
|
228
|
+
Yes. MIT-licensed, and all three upstream providers are free with no API keys.
|
|
227
229
|
|
|
228
230
|
**Can it send email?**
|
|
229
231
|
No — receive-only by design. TossInbox exists for privacy and testing and
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command, CommanderError } from "commander";
|
|
3
|
-
import { DEFAULT_PROVIDER, getProvider, listProviders, listSavedInboxes, removeInbox, clearInboxes, resolveInbox, saveInbox, statePath, waitForMessage, htmlToText, ProviderError, } from "./core/index.js";
|
|
3
|
+
import { DEFAULT_PROVIDER, getProvider, listProviders, listSavedInboxes, removeInbox, clearInboxes, resolveInbox, saveInbox, statePath, waitForMessage, sleep, htmlToText, ProviderError, } from "./core/index.js";
|
|
4
4
|
import { VERSION } from "./version.js";
|
|
5
5
|
/* Documented exit codes:
|
|
6
6
|
* 0 success
|
|
@@ -212,6 +212,121 @@ program
|
|
|
212
212
|
fail(err);
|
|
213
213
|
}
|
|
214
214
|
});
|
|
215
|
+
program
|
|
216
|
+
.command("watch")
|
|
217
|
+
.description("Stream new messages as they arrive — prints each message (and its code when found) and keeps polling until Ctrl-C")
|
|
218
|
+
.option("-a, --address <address>", "inbox address (defaults to the most recent inbox)")
|
|
219
|
+
.option("-f, --from <sender>", "only report messages from this sender (substring)")
|
|
220
|
+
.option("-s, --subject <text>", "only report messages whose subject contains this text")
|
|
221
|
+
.option("-i, --interval <seconds>", "poll interval in seconds", "5")
|
|
222
|
+
.action(async (opts) => {
|
|
223
|
+
try {
|
|
224
|
+
const intervalSeconds = Number(opts.interval);
|
|
225
|
+
if (!Number.isFinite(intervalSeconds) || intervalSeconds < 1 || intervalSeconds > 60) {
|
|
226
|
+
fail(new Error(`Invalid --interval "${opts.interval}" (expected seconds between 1 and 60)`), EXIT_USAGE);
|
|
227
|
+
}
|
|
228
|
+
const inbox = await resolveInbox(opts.address);
|
|
229
|
+
if (!inbox)
|
|
230
|
+
fail(new Error("No saved inbox found. Run: tossinbox spawn"), EXIT_NOT_FOUND);
|
|
231
|
+
const provider = providerOrExit(inbox.provider);
|
|
232
|
+
const matches = (m) => {
|
|
233
|
+
if (opts.from) {
|
|
234
|
+
const hay = `${m.from} ${m.fromName ?? ""}`.toLowerCase();
|
|
235
|
+
if (!hay.includes(opts.from.toLowerCase()))
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
if (opts.subject && !m.subject.toLowerCase().includes(opts.subject.toLowerCase()))
|
|
239
|
+
return false;
|
|
240
|
+
return true;
|
|
241
|
+
};
|
|
242
|
+
// Snapshot what is already in the inbox so only NEW arrivals are
|
|
243
|
+
// reported — re-watching an inbox after a wait must not replay history.
|
|
244
|
+
const seen = new Set();
|
|
245
|
+
try {
|
|
246
|
+
for (const m of await provider.listMessages(inbox))
|
|
247
|
+
seen.add(m.id);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// A failed first poll should not blind the watcher — start empty.
|
|
251
|
+
}
|
|
252
|
+
let stopped = false;
|
|
253
|
+
const stop = () => {
|
|
254
|
+
stopped = true;
|
|
255
|
+
};
|
|
256
|
+
process.on("SIGINT", stop);
|
|
257
|
+
process.on("SIGTERM", stop);
|
|
258
|
+
if (jsonMode()) {
|
|
259
|
+
// Streaming mode: one compact JSON object per line (NDJSON).
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
console.error(`👀 watching ${inbox.address} — Ctrl-C to stop`);
|
|
263
|
+
}
|
|
264
|
+
while (!stopped) {
|
|
265
|
+
let summaries;
|
|
266
|
+
try {
|
|
267
|
+
summaries = await provider.listMessages(inbox);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// Transient provider/network errors: keep polling until stopped.
|
|
271
|
+
}
|
|
272
|
+
if (summaries) {
|
|
273
|
+
for (const summary of summaries) {
|
|
274
|
+
if (seen.has(summary.id) || !matches(summary))
|
|
275
|
+
continue;
|
|
276
|
+
seen.add(summary.id);
|
|
277
|
+
// One retry — a transient read error must not swallow a message
|
|
278
|
+
// that may have taken minutes to arrive.
|
|
279
|
+
let message;
|
|
280
|
+
try {
|
|
281
|
+
message = await provider.readMessage(inbox, summary.id);
|
|
282
|
+
}
|
|
283
|
+
catch {
|
|
284
|
+
await sleep(1500);
|
|
285
|
+
try {
|
|
286
|
+
message = await provider.readMessage(inbox, summary.id);
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
// Report from the summary rather than dropping the event.
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (jsonMode()) {
|
|
293
|
+
const event = {
|
|
294
|
+
ok: true,
|
|
295
|
+
event: "message",
|
|
296
|
+
inbox: inbox.address,
|
|
297
|
+
provider: inbox.provider,
|
|
298
|
+
id: summary.id,
|
|
299
|
+
from: summary.from,
|
|
300
|
+
fromName: summary.fromName,
|
|
301
|
+
subject: summary.subject,
|
|
302
|
+
createdAt: summary.createdAt,
|
|
303
|
+
code: message?.code,
|
|
304
|
+
text: message?.text ?? (message?.html ? htmlToText(message.html) : undefined),
|
|
305
|
+
};
|
|
306
|
+
console.log(JSON.stringify(event));
|
|
307
|
+
}
|
|
308
|
+
else if (message) {
|
|
309
|
+
printMessageHuman(message, false);
|
|
310
|
+
}
|
|
311
|
+
else {
|
|
312
|
+
console.log(`✔ new message: ${summary.subject}`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Sleep in small slices so Ctrl-C feels instant.
|
|
317
|
+
const deadline = Date.now() + intervalSeconds * 1000;
|
|
318
|
+
while (!stopped && Date.now() < deadline) {
|
|
319
|
+
await sleep(Math.min(200, deadline - Date.now()));
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (!jsonMode())
|
|
323
|
+
console.error("✔ watch stopped");
|
|
324
|
+
exitWith(EXIT_OK);
|
|
325
|
+
}
|
|
326
|
+
catch (err) {
|
|
327
|
+
fail(err);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
215
330
|
program
|
|
216
331
|
.command("inboxes")
|
|
217
332
|
.description("List locally saved inboxes")
|
package/dist/core/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { mailTm } from "./providers/mailtm.js";
|
|
1
|
+
import { mailTm, mailGw } from "./providers/mailtm.js";
|
|
2
2
|
import { guerrillaMail } from "./providers/guerrillamail.js";
|
|
3
3
|
export * from "./types.js";
|
|
4
4
|
export { extractCode, htmlToText } from "./otp.js";
|
|
5
5
|
export * from "./state.js";
|
|
6
|
-
export { waitForMessage } from "./wait.js";
|
|
6
|
+
export { waitForMessage, sleep } from "./wait.js";
|
|
7
7
|
export const providers = {
|
|
8
8
|
[mailTm.name]: mailTm,
|
|
9
|
+
[mailGw.name]: mailGw,
|
|
9
10
|
[guerrillaMail.name]: guerrillaMail,
|
|
10
11
|
};
|
|
11
12
|
export const DEFAULT_PROVIDER = mailTm.name;
|
package/dist/core/otp.js
CHANGED
|
@@ -6,8 +6,34 @@
|
|
|
6
6
|
* looks like a code (4-8 digits, or 5-8 uppercase alphanumeric chars
|
|
7
7
|
* containing both letters and digits).
|
|
8
8
|
* 2. Fall back to the first standalone 4-8 digit number in the text.
|
|
9
|
+
*
|
|
10
|
+
* Keywords cover English plus the languages verification mail actually
|
|
11
|
+
* arrives in: Arabic, French, Spanish, German, Portuguese, Italian, Russian,
|
|
12
|
+
* Turkish, Chinese, Japanese, and Korean. Latin-script words use \b
|
|
13
|
+
* boundaries; scripts where \b is meaningless (Arabic, Cyrillic, CJK) match
|
|
14
|
+
* bare, same as the existing Arabic handling.
|
|
9
15
|
*/
|
|
10
|
-
const CODE_KEYWORDS = /\b(?:code|otp|passcode|pin|password.?code|verification|verify|confirm|activation|active.?code|one.?time)\b
|
|
16
|
+
const CODE_KEYWORDS = /\b(?:code|otp|passcode|pin|password.?code|verification|verify|confirm|activation|active.?code|one.?time|code.?de.?confirmation)\b/ // en + fr "code de confirmation"
|
|
17
|
+
.source +
|
|
18
|
+
"|" +
|
|
19
|
+
[
|
|
20
|
+
// Arabic
|
|
21
|
+
"رمز", "كود", "تفعيل", "تحقق", "الرمز",
|
|
22
|
+
// French
|
|
23
|
+
"vérification", "vérifier", "confirmer", "confirmation",
|
|
24
|
+
// Spanish / Portuguese / Italian (shared words folded)
|
|
25
|
+
"código", "verificación", "verificar", "confirme", "confirmação", "verificação",
|
|
26
|
+
"codice", "verifica", "conferma",
|
|
27
|
+
// German
|
|
28
|
+
"bestätigung", "verifizierung", "bestätigungscode",
|
|
29
|
+
// Russian (Cyrillic — no \b)
|
|
30
|
+
"код", "подтверждение", "верификация",
|
|
31
|
+
// Turkish
|
|
32
|
+
"doğrulama", "onay.?kodu",
|
|
33
|
+
// Chinese / Japanese / Korean (CJK — no \b)
|
|
34
|
+
"验证码", "校验码", "确认码", "確認コード", "認証コード", "検証コード", "認証番号", "인증코드", "인증 번호",
|
|
35
|
+
].join("|");
|
|
36
|
+
const CODE_KEYWORDS_RE = new RegExp(CODE_KEYWORDS, "i");
|
|
11
37
|
export function htmlToText(html) {
|
|
12
38
|
return html
|
|
13
39
|
.replace(/<style[\s\S]*?<\/style>/gi, " ")
|
|
@@ -33,7 +59,7 @@ export function extractCode(input) {
|
|
|
33
59
|
const lines = text.split(/\r?\n/);
|
|
34
60
|
// 1) Keyword line -> prefer a code-shaped token on that line
|
|
35
61
|
for (const line of lines) {
|
|
36
|
-
if (!
|
|
62
|
+
if (!CODE_KEYWORDS_RE.test(line))
|
|
37
63
|
continue;
|
|
38
64
|
// Case-insensitive on purpose: many services send lowercase codes (f4x9k2).
|
|
39
65
|
const tokens = line.match(/(?<![\w-])[A-Za-z0-9]{4,10}(?![\w-])/g);
|
|
@@ -3,7 +3,6 @@ import { ProviderError } from "../types.js";
|
|
|
3
3
|
import { extractCode } from "../otp.js";
|
|
4
4
|
import { networkError } from "../net.js";
|
|
5
5
|
import { VERSION } from "../../version.js";
|
|
6
|
-
const BASE = "https://api.mail.tm";
|
|
7
6
|
const REQUEST_TIMEOUT_MS = 20_000;
|
|
8
7
|
function randomString(length, alphabet) {
|
|
9
8
|
const bytes = randomBytes(length);
|
|
@@ -28,128 +27,148 @@ function headers(token) {
|
|
|
28
27
|
h.Authorization = `Bearer ${token}`;
|
|
29
28
|
return h;
|
|
30
29
|
}
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const init = {
|
|
42
|
-
method,
|
|
43
|
-
headers: { ...headers(options.token), ...(options.body ? { "Content-Type": "application/json" } : {}) },
|
|
44
|
-
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
45
|
-
};
|
|
46
|
-
let res = await fetchJson(url, init);
|
|
47
|
-
if (res.status === 429) {
|
|
48
|
-
await new Promise((r) => setTimeout(r, 1200));
|
|
49
|
-
res = await fetchJson(url, init);
|
|
30
|
+
/** mail.tm and mail.gw expose the identical API (mail.gw is an independent
|
|
31
|
+
* infrastructure running the same software), so one factory serves both.
|
|
32
|
+
* Every request gets a hard timeout and raw network failures are translated
|
|
33
|
+
* into readable, actionable ProviderErrors naming the right provider. */
|
|
34
|
+
function createMailTmLikeProvider(config) {
|
|
35
|
+
const { name: providerName, base, host } = config;
|
|
36
|
+
function fetchJson(url, init) {
|
|
37
|
+
return fetch(url, { ...init, signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) }).catch((err) => {
|
|
38
|
+
throw networkError(err, providerName, host, REQUEST_TIMEOUT_MS);
|
|
39
|
+
});
|
|
50
40
|
}
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
41
|
+
/** These APIs allow ~8 requests per second; retry once on 429. */
|
|
42
|
+
async function request(method, url, options = {}) {
|
|
43
|
+
const init = {
|
|
44
|
+
method,
|
|
45
|
+
headers: { ...headers(options.token), ...(options.body ? { "Content-Type": "application/json" } : {}) },
|
|
46
|
+
body: options.body ? JSON.stringify(options.body) : undefined,
|
|
47
|
+
};
|
|
48
|
+
let res = await fetchJson(url, init);
|
|
49
|
+
if (res.status === 429) {
|
|
50
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
51
|
+
res = await fetchJson(url, init);
|
|
61
52
|
}
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
55
|
+
async function parseJson(res) {
|
|
56
|
+
if (!res.ok) {
|
|
57
|
+
// 5xx = the upstream itself is failing — say so and point at the fix.
|
|
58
|
+
if (res.status >= 500) {
|
|
59
|
+
throw new ProviderError(providerName, `HTTP ${res.status} from ${host} — provider is down or having trouble; retry, or switch with --provider`, res.status);
|
|
60
|
+
}
|
|
61
|
+
let detail = "";
|
|
62
|
+
try {
|
|
63
|
+
const body = (await res.json());
|
|
64
|
+
const msg = body["hydra:description"] ?? body.message ?? body.detail;
|
|
65
|
+
if (typeof msg === "string")
|
|
66
|
+
detail = `: ${msg}`;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// ignore body parse errors
|
|
70
|
+
}
|
|
71
|
+
throw new ProviderError(providerName, `HTTP ${res.status}${detail}`, res.status);
|
|
64
72
|
}
|
|
65
|
-
|
|
73
|
+
return (await res.json());
|
|
66
74
|
}
|
|
67
|
-
return
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
/** These APIs return a plain array with Accept: application/json and a hydra
|
|
76
|
+
* collection with Accept: application/ld+json — normalize both. */
|
|
77
|
+
async function parseCollection(res) {
|
|
78
|
+
const data = await parseJson(res);
|
|
79
|
+
if (Array.isArray(data))
|
|
80
|
+
return data;
|
|
81
|
+
if (data && typeof data === "object") {
|
|
82
|
+
const obj = data;
|
|
83
|
+
const member = obj["hydra:member"] ?? obj.member;
|
|
84
|
+
if (Array.isArray(member))
|
|
85
|
+
return member;
|
|
86
|
+
}
|
|
87
|
+
throw new ProviderError(providerName, "Unexpected collection response shape");
|
|
80
88
|
}
|
|
81
|
-
|
|
89
|
+
return {
|
|
90
|
+
name: providerName,
|
|
91
|
+
description: config.description,
|
|
92
|
+
async createInbox(options) {
|
|
93
|
+
const domainsRes = await request("GET", `${base}/domains?page=1`);
|
|
94
|
+
const domains = await parseCollection(domainsRes);
|
|
95
|
+
const domain = domains.find((d) => d.isActive && !d.isPrivate)?.domain;
|
|
96
|
+
if (!domain) {
|
|
97
|
+
throw new ProviderError(providerName, `No active public domain available on ${host}`);
|
|
98
|
+
}
|
|
99
|
+
const address = `${randomUser()}@${domain}`;
|
|
100
|
+
const password = randomPassword();
|
|
101
|
+
const accountRes = await request("POST", `${base}/accounts`, { body: { address, password } });
|
|
102
|
+
const account = await parseJson(accountRes);
|
|
103
|
+
const tokenRes = await request("POST", `${base}/token`, { body: { address, password } });
|
|
104
|
+
const auth = await parseJson(tokenRes);
|
|
105
|
+
const inbox = {
|
|
106
|
+
provider: providerName,
|
|
107
|
+
address: account.address || address,
|
|
108
|
+
label: options?.label,
|
|
109
|
+
token: auth.token,
|
|
110
|
+
password,
|
|
111
|
+
accountId: account.id || auth.id,
|
|
112
|
+
createdAt: new Date().toISOString(),
|
|
113
|
+
};
|
|
114
|
+
return inbox;
|
|
115
|
+
},
|
|
116
|
+
async listMessages(inbox) {
|
|
117
|
+
if (!inbox.token)
|
|
118
|
+
throw new ProviderError(providerName, "Inbox is missing its API token");
|
|
119
|
+
const res = await request("GET", `${base}/messages?page=1`, { token: inbox.token });
|
|
120
|
+
const data = await parseCollection(res);
|
|
121
|
+
return data.map((m) => ({
|
|
122
|
+
id: m.id,
|
|
123
|
+
from: m.from?.address ?? "unknown",
|
|
124
|
+
fromName: m.from?.name,
|
|
125
|
+
subject: m.subject ?? "(no subject)",
|
|
126
|
+
intro: m.intro,
|
|
127
|
+
createdAt: m.createdAt,
|
|
128
|
+
}));
|
|
129
|
+
},
|
|
130
|
+
async readMessage(inbox, id) {
|
|
131
|
+
if (!inbox.token)
|
|
132
|
+
throw new ProviderError(providerName, "Inbox is missing its API token");
|
|
133
|
+
const res = await request("GET", `${base}/messages/${encodeURIComponent(id)}`, { token: inbox.token });
|
|
134
|
+
const m = await parseJson(res);
|
|
135
|
+
const html = m.html && m.html.length > 0 ? m.html.join("\n") : undefined;
|
|
136
|
+
const message = {
|
|
137
|
+
id: m.id,
|
|
138
|
+
from: m.from?.address ?? "unknown",
|
|
139
|
+
fromName: m.from?.name,
|
|
140
|
+
subject: m.subject ?? "(no subject)",
|
|
141
|
+
intro: m.intro,
|
|
142
|
+
createdAt: m.createdAt,
|
|
143
|
+
text: m.text,
|
|
144
|
+
html,
|
|
145
|
+
};
|
|
146
|
+
message.code = extractCode(message.text) ?? extractCode(message.html);
|
|
147
|
+
return message;
|
|
148
|
+
},
|
|
149
|
+
async destroyInbox(inbox) {
|
|
150
|
+
if (!inbox.token || !inbox.accountId)
|
|
151
|
+
return;
|
|
152
|
+
try {
|
|
153
|
+
await request("DELETE", `${base}/accounts/${encodeURIComponent(inbox.accountId)}`, {
|
|
154
|
+
token: inbox.token,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
// best effort: local removal always happens regardless
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
};
|
|
82
162
|
}
|
|
83
|
-
export const mailTm = {
|
|
163
|
+
export const mailTm = createMailTmLikeProvider({
|
|
84
164
|
name: "mailtm",
|
|
165
|
+
base: "https://api.mail.tm",
|
|
166
|
+
host: "api.mail.tm",
|
|
85
167
|
description: "mail.tm — free disposable email, no API key required",
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const address = `${randomUser()}@${domain}`;
|
|
94
|
-
const password = randomPassword();
|
|
95
|
-
const accountRes = await request("POST", `${BASE}/accounts`, { body: { address, password } });
|
|
96
|
-
const account = await parseJson(accountRes, this.name);
|
|
97
|
-
const tokenRes = await request("POST", `${BASE}/token`, { body: { address, password } });
|
|
98
|
-
const auth = await parseJson(tokenRes, this.name);
|
|
99
|
-
const inbox = {
|
|
100
|
-
provider: this.name,
|
|
101
|
-
address: account.address || address,
|
|
102
|
-
label: options?.label,
|
|
103
|
-
token: auth.token,
|
|
104
|
-
password,
|
|
105
|
-
accountId: account.id || auth.id,
|
|
106
|
-
createdAt: new Date().toISOString(),
|
|
107
|
-
};
|
|
108
|
-
return inbox;
|
|
109
|
-
},
|
|
110
|
-
async listMessages(inbox) {
|
|
111
|
-
if (!inbox.token)
|
|
112
|
-
throw new ProviderError(this.name, "Inbox is missing its API token");
|
|
113
|
-
const res = await request("GET", `${BASE}/messages?page=1`, { token: inbox.token });
|
|
114
|
-
const data = await parseCollection(res, this.name);
|
|
115
|
-
return data.map((m) => ({
|
|
116
|
-
id: m.id,
|
|
117
|
-
from: m.from?.address ?? "unknown",
|
|
118
|
-
fromName: m.from?.name,
|
|
119
|
-
subject: m.subject ?? "(no subject)",
|
|
120
|
-
intro: m.intro,
|
|
121
|
-
createdAt: m.createdAt,
|
|
122
|
-
}));
|
|
123
|
-
},
|
|
124
|
-
async readMessage(inbox, id) {
|
|
125
|
-
if (!inbox.token)
|
|
126
|
-
throw new ProviderError(this.name, "Inbox is missing its API token");
|
|
127
|
-
const res = await request("GET", `${BASE}/messages/${encodeURIComponent(id)}`, { token: inbox.token });
|
|
128
|
-
const m = await parseJson(res, this.name);
|
|
129
|
-
const html = m.html && m.html.length > 0 ? m.html.join("\n") : undefined;
|
|
130
|
-
const message = {
|
|
131
|
-
id: m.id,
|
|
132
|
-
from: m.from?.address ?? "unknown",
|
|
133
|
-
fromName: m.from?.name,
|
|
134
|
-
subject: m.subject ?? "(no subject)",
|
|
135
|
-
intro: m.intro,
|
|
136
|
-
createdAt: m.createdAt,
|
|
137
|
-
text: m.text,
|
|
138
|
-
html,
|
|
139
|
-
};
|
|
140
|
-
message.code = extractCode(message.text) ?? extractCode(message.html);
|
|
141
|
-
return message;
|
|
142
|
-
},
|
|
143
|
-
async destroyInbox(inbox) {
|
|
144
|
-
if (!inbox.token || !inbox.accountId)
|
|
145
|
-
return;
|
|
146
|
-
try {
|
|
147
|
-
await request("DELETE", `${BASE}/accounts/${encodeURIComponent(inbox.accountId)}`, {
|
|
148
|
-
token: inbox.token,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
// best effort: local removal always happens regardless
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
};
|
|
168
|
+
});
|
|
169
|
+
export const mailGw = createMailTmLikeProvider({
|
|
170
|
+
name: "mailgw",
|
|
171
|
+
base: "https://api.mail.gw",
|
|
172
|
+
host: "api.mail.gw",
|
|
173
|
+
description: "mail.gw — mail.tm-compatible API on independent infrastructure",
|
|
174
|
+
});
|
package/dist/version.js
CHANGED