react-native-email-imap-smtp 0.3.11 → 0.3.12

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/index.ts"],"names":[],"mappings":"AAiHA,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../server/src/index.ts"],"names":[],"mappings":"AAiHA,OAAO,OAAO,MAAM,SAAS,CAAC;AAO9B,QAAA,MAAM,GAAG,EAAE,OAAO,CAAC,OAAmB,CAAC;AACvC,QAAA,MAAM,MAAM,mHAAoB,CAAC;AAscjC,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.11",
3
+ "version": "0.3.12",
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",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
- "react-native-email-imap-smtp-source": "./src/index.tsx",
12
+ "react-native-email-imap-smtp-source": "./sr/index.tsx",
13
13
  "types": "./lib/typescript/src/index.d.ts",
14
14
  "default": "./lib/module/index.js"
15
15
  },
package/server/bin.mjs CHANGED
@@ -7,9 +7,14 @@
7
7
  // email-imap-proxy 默认:分离模式(启动后退出,代理后台运行)
8
8
  // email-imap-proxy --foreground 前台模式(保持运行,Ctrl+C 停止)
9
9
  // email-imap-proxy -f 同上
10
+ // email-imap-proxy --window 新开终端窗口显示日志(推荐)
11
+ // email-imap-proxy -w 同上
10
12
  // email-imap-proxy --port 3987 指定端口
11
13
  // email-imap-proxy --silent 静默模式
12
14
  //
15
+ // 关闭代理:
16
+ // 关闭日志窗口即可(如果使用 --window)或直接关闭终端
17
+ //
13
18
  // 与 dev server 一起使用:
14
19
  // email-imap-proxy & vite ← Windows/Linux 通吃
15
20
  // email-imap-proxy & webpack serve
@@ -23,6 +28,8 @@
23
28
  // await startEmailProxy();
24
29
  // ============================================================
25
30
 
31
+ import { spawn } from 'child_process';
32
+ import { fileURLToPath } from 'url';
26
33
  import { startEmailProxy } from './proxy.mjs';
27
34
 
28
35
  // ─── 解析命令行参数 ─────────────────────────────────────
@@ -31,10 +38,40 @@ const args = process.argv.slice(2);
31
38
  const portIndex = args.indexOf('--port');
32
39
  const port = portIndex >= 0 ? parseInt(args[portIndex + 1], 10) : parseInt(process.env.PROXY_PORT ?? '3987', 10);
33
40
  const silent = args.includes('--silent') || process.env.PROXY_SILENT === '1';
34
- // 分离模式为默认行为(解决 Windows & 不阻塞)
35
41
  const foreground = args.includes('--foreground') || args.includes('-f');
42
+ const openWindow = args.includes('--window') || args.includes('-w');
43
+
44
+ // 将当前终端 PID 传给代理服务器,用于父终端存活检测
45
+ // 仅当未被外部传入时设置(--window 模式会显式传入原始终端 PID)
46
+ if (!process.env.PROXY_WATCH_PPID) {
47
+ process.env.PROXY_WATCH_PPID = String(process.ppid);
48
+ }
49
+
50
+ // ─── --window 模式 ──────────────────────────────────────
51
+ // 在新终端窗口中运行代理(foreground 模式),方便查看调试日志
52
+
53
+ if (openWindow && !foreground) {
54
+ const scriptPath = fileURLToPath(import.meta.url);
55
+ const nodeExe = process.execPath;
56
+ // process.ppid 是当前终端(cmd.exe/shell)的 PID
57
+ const termPid = process.ppid;
58
+
59
+ if (process.platform === 'win32') {
60
+ const cmd = `start "Email Proxy :${port}" cmd /c "set PROXY_WATCH_PPID=${termPid}&& \\"${nodeExe}\\" \\"${scriptPath}\\" --foreground --port ${port}"`;
61
+ spawn('cmd', ['/c', cmd], { stdio: 'ignore', detached: true, windowsHide: false }).unref();
62
+ } else {
63
+ spawn('open', ['-a', 'Terminal', scriptPath, '--args', '--foreground', `--port=${port}`], {
64
+ stdio: 'ignore', detached: true,
65
+ env: { ...process.env, PROXY_WATCH_PPID: String(termPid) }
66
+ }).unref();
67
+ }
68
+
69
+ console.log(`[email-proxy] 启动代理 :${port}`);
70
+ console.log(`[email-proxy] 日志窗口已打开,关闭此终端即可停止`);
71
+ process.exit(0);
72
+ }
36
73
 
37
- // ─── 启动 ───────────────────────────────────────────────
74
+ // ─── 正常启动 ───────────────────────────────────────────────
38
75
 
39
76
  startEmailProxy({ port, silent, detach: !foreground }).then((handle) => {
40
77
  handle.onStderr((msg) => {
@@ -531,6 +531,44 @@ function broadcastNotification(sessionId: string, notification: any): void {
531
531
  }
532
532
  }
533
533
 
534
+ // ══════════════════════════════════════════════════════════════
535
+ // 父终端检测 — 自动关闭
536
+ // ══════════════════════════════════════════════════════════════
537
+ // 当 PROXY_WATCH_PPID 环境变量设置时,定时检测该进程是否存活。
538
+ // 如果启动代理的网页终端(如 Vite/Webpack 终端)已关闭,
539
+ // 服务器自动退出,避免残留进程。
540
+ // ══════════════════════════════════════════════════════════════
541
+
542
+ const watchPid = process.env.PROXY_WATCH_PPID
543
+ ? parseInt(process.env.PROXY_WATCH_PPID, 10)
544
+ : 0;
545
+
546
+ if (watchPid > 0) {
547
+ let cleanExit = false;
548
+ const timer = setInterval(() => {
549
+ try {
550
+ process.kill(watchPid, 0);
551
+ } catch {
552
+ // 父进程已不存在,自动关闭服务器
553
+ cleanExit = true;
554
+ clearInterval(timer);
555
+ console.log('[email-proxy] 父终端已关闭,正在停止服务...');
556
+
557
+ for (const id of imap.getAllSessionIds()) {
558
+ try { imap.disconnect(id); } catch {}
559
+ }
560
+ for (const id of smtp.getAllSessionIds()) {
561
+ try { smtp.disconnect(id); } catch {}
562
+ }
563
+
564
+ server.close(() => process.exit(0));
565
+ setTimeout(() => process.exit(0), 3000);
566
+ }
567
+ }, 3000);
568
+
569
+ process.on('exit', () => { if (!cleanExit) clearInterval(timer); });
570
+ }
571
+
534
572
  // ══════════════════════════════════════════════════════════════
535
573
  // 启动 (程序化 API)
536
574
  // ══════════════════════════════════════════════════════════════