react-native-email-imap-smtp 0.3.0 → 0.3.2
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import express from 'express';
|
|
2
|
+
declare const app: express.Express;
|
|
2
3
|
declare const server: import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>;
|
|
3
4
|
export interface ServerHandle {
|
|
4
5
|
port: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/index.ts"],"names":[],"mappings":"AAYA,OAAO,OAAO,MAAM,SAAS,CAAC;AAO9B,QAAA,MAAM,GAAG,EAAE,OAAO,CAAC,OAAmB,CAAC;AACvC,QAAA,MAAM,MAAM,mHAAoB,CAAC;AAgajC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED,wBAAsB,WAAW,CAC/B,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,YAAY,CAAC,CAuBvB;AAQD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-email-imap-smtp",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "The best of imap and smtp client of react native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
"types": "./lib/typescript/src/index.d.ts",
|
|
14
14
|
"default": "./lib/module/index.js"
|
|
15
15
|
},
|
|
16
|
+
"./server/proxy": {
|
|
17
|
+
"import": "./server/proxy.mjs",
|
|
18
|
+
"default": "./server/proxy.mjs"
|
|
19
|
+
},
|
|
20
|
+
"./server/bin": {
|
|
21
|
+
"import": "./server/bin.mjs",
|
|
22
|
+
"default": "./server/bin.mjs"
|
|
23
|
+
},
|
|
16
24
|
"./package.json": "./package.json"
|
|
17
25
|
},
|
|
18
26
|
"files": [
|
package/server/bin.mjs
CHANGED
|
@@ -1,29 +1,62 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// ============================================================
|
|
3
|
-
// CLI 入口 —
|
|
3
|
+
// CLI 入口 — email-imap-proxy
|
|
4
4
|
// ============================================================
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
5
|
+
//
|
|
6
|
+
// 用法:
|
|
7
|
+
// email-imap-proxy 默认:分离模式(启动后退出,代理后台运行)
|
|
8
|
+
// email-imap-proxy --foreground 前台模式(保持运行,Ctrl+C 停止)
|
|
9
|
+
// email-imap-proxy -f 同上
|
|
10
|
+
// email-imap-proxy --port 3987 指定端口
|
|
11
|
+
// email-imap-proxy --silent 静默模式
|
|
12
|
+
//
|
|
13
|
+
// 与 dev server 一起使用:
|
|
14
|
+
// email-imap-proxy & vite ← Windows/Linux 通吃
|
|
15
|
+
// email-imap-proxy & webpack serve
|
|
16
|
+
// email-imap-proxy & next dev
|
|
17
|
+
//
|
|
18
|
+
// # 或用 concurrently(跨平台)
|
|
19
|
+
// concurrently "email-imap-proxy" "vite"
|
|
20
|
+
//
|
|
21
|
+
// # 或集成到 Vite/Webpack 配置(不依赖 CLI)
|
|
22
|
+
// import { startEmailProxy } from 'react-native-email-imap-smtp/server/proxy';
|
|
23
|
+
// await startEmailProxy();
|
|
8
24
|
// ============================================================
|
|
9
25
|
|
|
10
26
|
import { startEmailProxy } from './proxy.mjs';
|
|
11
27
|
|
|
12
|
-
|
|
13
|
-
const silent = process.env.PROXY_SILENT === '1';
|
|
28
|
+
// ─── 解析命令行参数 ─────────────────────────────────────
|
|
14
29
|
|
|
15
|
-
|
|
30
|
+
const args = process.argv.slice(2);
|
|
31
|
+
const portIndex = args.indexOf('--port');
|
|
32
|
+
const port = portIndex >= 0 ? parseInt(args[portIndex + 1], 10) : parseInt(process.env.PROXY_PORT ?? '3987', 10);
|
|
33
|
+
const silent = args.includes('--silent') || process.env.PROXY_SILENT === '1';
|
|
34
|
+
// 分离模式为默认行为(解决 Windows & 不阻塞)
|
|
35
|
+
const foreground = args.includes('--foreground') || args.includes('-f');
|
|
36
|
+
|
|
37
|
+
// ─── 启动 ───────────────────────────────────────────────
|
|
38
|
+
|
|
39
|
+
startEmailProxy({ port, silent, detach: !foreground }).then((handle) => {
|
|
16
40
|
handle.onStderr((msg) => {
|
|
17
41
|
if (!silent && msg.includes('ready')) {
|
|
18
42
|
console.log(`[email-proxy] 代理服务器就绪 :${handle.port}`);
|
|
19
43
|
}
|
|
20
44
|
});
|
|
21
45
|
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
// 默认(分离模式):启动完成后父进程立即退出,代理在后台独立运行
|
|
47
|
+
if (!foreground) {
|
|
48
|
+
process.exit(0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 前台模式:保持进程存活,等待退出信号
|
|
52
|
+
const cleanup = async () => {
|
|
53
|
+
await handle.stop();
|
|
54
|
+
process.exit(0);
|
|
55
|
+
};
|
|
56
|
+
process.on('SIGINT', cleanup);
|
|
57
|
+
process.on('SIGTERM', cleanup);
|
|
58
|
+
|
|
59
|
+
// 保持事件循环活跃
|
|
60
|
+
const keepAlive = setInterval(() => {}, 2 ** 31 - 1);
|
|
61
|
+
process.on('exit', () => clearInterval(keepAlive));
|
|
29
62
|
});
|
package/server/proxy.mjs
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
// const handle = await startEmailProxy();
|
|
10
10
|
// // 用完: handle.stop()
|
|
11
11
|
//
|
|
12
|
-
// 也可作为 dev
|
|
12
|
+
// 也可作为 dev 命令的前置进程(CLI 默认分离模式,不阻塞后续命令):
|
|
13
13
|
// "dev": "email-imap-proxy & next dev"
|
|
14
|
+
// "dev": "email-imap-proxy & vite"
|
|
15
|
+
// "dev": "email-imap-proxy & webpack serve"
|
|
14
16
|
// ============================================================
|
|
15
17
|
|
|
16
18
|
import { spawn } from 'child_process';
|
|
@@ -25,6 +27,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
25
27
|
* @property {number} [port=3987] 代理服务端口
|
|
26
28
|
* @property {boolean} [silent=false] 静默模式
|
|
27
29
|
* @property {number} [timeout=30000] 启动超时(ms)
|
|
30
|
+
* @property {boolean} [detach=false] 分离模式:启动后父进程可退出,代理独立运行(解决 Windows & 兼容问题)
|
|
28
31
|
*/
|
|
29
32
|
|
|
30
33
|
/**
|
|
@@ -45,6 +48,7 @@ export async function startEmailProxy(options = {}) {
|
|
|
45
48
|
const port = options.port ?? 3987;
|
|
46
49
|
const silent = options.silent ?? false;
|
|
47
50
|
const timeout = options.timeout ?? 30000;
|
|
51
|
+
const detach = options.detach ?? false;
|
|
48
52
|
|
|
49
53
|
const serverDir = resolve(__dirname);
|
|
50
54
|
const entryFile = resolve(serverDir, 'lib/index.js');
|
|
@@ -72,6 +76,7 @@ export async function startEmailProxy(options = {}) {
|
|
|
72
76
|
stdio: ['ignore', silent ? 'ignore' : 'inherit', 'pipe'],
|
|
73
77
|
env: { ...process.env, PROXY_PORT: String(port) },
|
|
74
78
|
shell: true,
|
|
79
|
+
detached: detach,
|
|
75
80
|
});
|
|
76
81
|
|
|
77
82
|
let stderrCallback = null;
|
|
@@ -96,6 +101,11 @@ export async function startEmailProxy(options = {}) {
|
|
|
96
101
|
console.log(`[email-proxy] 代理服务器就绪 :${port}`);
|
|
97
102
|
}
|
|
98
103
|
|
|
104
|
+
// 分离模式下关闭子进程的 IPC 通道,允许父进程退出
|
|
105
|
+
if (detach) {
|
|
106
|
+
proc.unref();
|
|
107
|
+
}
|
|
108
|
+
|
|
99
109
|
return {
|
|
100
110
|
port,
|
|
101
111
|
stop: () =>
|
package/server/src/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { WebSocketServer, WebSocket } from 'ws';
|
|
|
17
17
|
import * as imap from './imapHandler';
|
|
18
18
|
import * as smtp from './smtpHandler';
|
|
19
19
|
|
|
20
|
-
const app = express();
|
|
20
|
+
const app: express.Express = express();
|
|
21
21
|
const server = createServer(app);
|
|
22
22
|
|
|
23
23
|
// ─── 配置 ───────────────────────────────────────────────────
|