From 3445ca41064bdb2ae0b68aff3f2789909212886e Mon Sep 17 00:00:00 2001 From: Hwi Kim <166241069+littlebit0@users.noreply.github.com> Date: Sun, 22 Nov 2026 00:46:29 +0900 Subject: [PATCH 1/3] =?UTF-8?q?IMAP=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=ED=9B=84=20=EC=84=9C=EB=B2=84=20CAPABILITY=EB=A5=BC=20?= =?UTF-8?q?=EA=B3=84=EC=A0=95=EC=97=90=20=EC=A0=80=EC=9E=A5=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EA=B3=84=EC=A0=95=20=ED=99=94=EB=A9=B4=EC=97=90=20?= =?UTF-8?q?=EC=88=98=EC=8B=A0=20=EB=B0=A9=EC=8B=9D=20=ED=91=9C=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/core/i18n/language_controller.dart | 5 +++ .../lib/features/accounts/accounts_page.dart | 17 +++++++++ apps/client/lib/services/mail_api_client.dart | 12 ++++++ apps/client/test/widget_test.dart | 37 +++++++++++++++++++ apps/server/package.json | 2 +- apps/server/src/domain/types.ts | 10 +++++ apps/server/src/mail/ImapReceiver.ts | 9 +++++ apps/server/src/mail/imapCapabilities.ts | 16 ++++++++ apps/server/src/workers/MailSyncWorker.ts | 3 ++ apps/server/test/imapCapabilities.test.ts | 23 ++++++++++++ 10 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 apps/server/src/mail/imapCapabilities.ts create mode 100644 apps/server/test/imapCapabilities.test.ts diff --git a/apps/client/lib/core/i18n/language_controller.dart b/apps/client/lib/core/i18n/language_controller.dart index 443bb5f..c19bfa5 100644 --- a/apps/client/lib/core/i18n/language_controller.dart +++ b/apps/client/lib/core/i18n/language_controller.dart @@ -196,6 +196,11 @@ class AppStrings { String get statusError => _ko ? '오류' : 'Error'; String get lastSynced => _ko ? '마지막 동기화' : 'Last synced'; String get neverSynced => _ko ? '아직 없음' : 'Never'; + String get receiveMode => _ko ? '수신 방식' : 'Receive mode'; + String get receiveRealtime => _ko ? '실시간(IDLE)' : 'Realtime (IDLE)'; + String get receivePolling => _ko ? '주기 확인' : 'Periodic check'; + String get receiveUnknown => _ko ? '확인 전' : 'Not checked yet'; + String get capabilitiesChecked => _ko ? '확인' : 'checked'; String get protocol => _ko ? '수신 방식' : 'Protocol'; String get authMode => _ko ? '인증 방식' : 'Auth mode'; String authModeLabel(String mode) => switch (mode) { diff --git a/apps/client/lib/features/accounts/accounts_page.dart b/apps/client/lib/features/accounts/accounts_page.dart index bc7cd23..32b4f00 100644 --- a/apps/client/lib/features/accounts/accounts_page.dart +++ b/apps/client/lib/features/accounts/accounts_page.dart @@ -454,6 +454,13 @@ class _AccountDetail extends ConsumerWidget { ? strings.neverSynced : account.lastSyncedAtLabel, ), + if (account.incomingProtocol == 'imap') ...[ + const SizedBox(height: 8), + _InfoRow( + label: strings.receiveMode, + value: _receiveModeLabel(account, strings), + ), + ], if (account.syncError != null) ...[ const SizedBox(height: 12), Text( @@ -466,6 +473,16 @@ class _AccountDetail extends ConsumerWidget { } } +String _receiveModeLabel(MailAccountSummary account, AppStrings strings) { + final idle = account.idleSupported; + if (idle == null) return strings.receiveUnknown; + final mode = idle ? strings.receiveRealtime : strings.receivePolling; + final checked = account.capabilitiesCheckedAtLabel; + return checked.isEmpty + ? mode + : '$mode · ${strings.capabilitiesChecked} $checked'; +} + class _InfoRow extends StatelessWidget { const _InfoRow({ required this.label, diff --git a/apps/client/lib/services/mail_api_client.dart b/apps/client/lib/services/mail_api_client.dart index 721252c..250bfc7 100644 --- a/apps/client/lib/services/mail_api_client.dart +++ b/apps/client/lib/services/mail_api_client.dart @@ -338,6 +338,8 @@ class MailAccountSummary { this.syncErrorCode, required this.initialSync, required this.lastSyncedAtLabel, + this.idleSupported, + this.capabilitiesCheckedAtLabel = '', }); final String id; @@ -351,7 +353,14 @@ class MailAccountSummary { final InitialSyncOption? initialSync; final String lastSyncedAtLabel; + /// Null until the server has logged in and read the IMAP capabilities. + final bool? idleSupported; + final String capabilitiesCheckedAtLabel; + factory MailAccountSummary.fromJson(Map json) { + final capabilities = json['incomingCapabilities'] is Map + ? json['incomingCapabilities'] as Map + : null; return MailAccountSummary( id: json['id'] as String, providerId: json['providerId'] as String, @@ -366,6 +375,9 @@ class MailAccountSummary { json['initialSync'] as Map) : null, lastSyncedAtLabel: _formatReceivedAt(json['lastSyncedAt'] as String?), + idleSupported: capabilities?['idle'] as bool?, + capabilitiesCheckedAtLabel: + _formatReceivedAt(capabilities?['checkedAt'] as String?), ); } } diff --git a/apps/client/test/widget_test.dart b/apps/client/test/widget_test.dart index 52f8487..d4d1709 100644 --- a/apps/client/test/widget_test.dart +++ b/apps/client/test/widget_test.dart @@ -136,6 +136,43 @@ void main() { await tester.pumpWidget(const SizedBox()); }); + testWidgets('shows the receive mode from IMAP capabilities', + (WidgetTester tester) async { + final json = { + 'id': 'a', + 'providerId': 'naver', + 'emailAddress': 'a@example.com', + 'incomingProtocol': 'imap', + }; + final polling = MailAccountSummary.fromJson({ + ...json, + 'incomingCapabilities': { + 'idle': false, + 'checkedAt': '2020-01-01T00:00:00Z' + }, + }); + final unknown = MailAccountSummary.fromJson(json); + expect(polling.idleSupported, isFalse); + expect(unknown.idleSupported, isNull); + + await tester.binding.setSurfaceSize(const Size(1200, 800)); + addTearDown(() => tester.binding.setSurfaceSize(null)); + await tester.pumpWidget( + ProviderScope( + overrides: [ + accountsProvider.overrideWith((ref) async => [polling]), + providersProvider.overrideWith((ref) async => const []), + ], + child: const DailyPostBoxApp(), + ), + ); + await tester.pumpAndSettle(); + await tester.tap(find.text('계정관리').first); + await tester.pumpAndSettle(); + + expect(find.textContaining('주기 확인'), findsOneWidget); + }); + testWidgets('keeps the syncing mailbox when an account refresh fails', (WidgetTester tester) async { const account = MailAccountSummary( diff --git a/apps/server/package.json b/apps/server/package.json index 982da57..39b9f40 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "tsx src/server.ts", - "test": "tsx --test test/imapSequenceRanges.test.ts test/mailSyncWorker.test.ts test/accountValidate.test.ts test/accountReconnect.test.ts test/oauthTokenManager.test.ts test/apnsPushNotifier.test.ts", + "test": "tsx --test test/imapSequenceRanges.test.ts test/mailSyncWorker.test.ts test/accountValidate.test.ts test/accountReconnect.test.ts test/oauthTokenManager.test.ts test/apnsPushNotifier.test.ts test/imapCapabilities.test.ts", "typecheck": "tsc --noEmit", "start": "node dist/server.js", "build": "tsc" diff --git a/apps/server/src/domain/types.ts b/apps/server/src/domain/types.ts index ad7152b..22e5499 100644 --- a/apps/server/src/domain/types.ts +++ b/apps/server/src/domain/types.ts @@ -32,6 +32,15 @@ export interface MailProviderConfig { }; } +export interface IncomingCapabilities { + idle: boolean; + move: boolean; + specialUse: boolean; + condstore: boolean; + /** ISO time of the login that reported these capabilities. */ + checkedAt: string; +} + export interface MailAccount { id: string; userId: string; @@ -49,6 +58,7 @@ export interface MailAccount { limit: number | "all"; }; lastSyncedAt?: Date; + incomingCapabilities?: IncomingCapabilities; connectionOverride?: { incoming?: { host: string; diff --git a/apps/server/src/mail/ImapReceiver.ts b/apps/server/src/mail/ImapReceiver.ts index 4160d89..83e9543 100644 --- a/apps/server/src/mail/ImapReceiver.ts +++ b/apps/server/src/mail/ImapReceiver.ts @@ -18,6 +18,7 @@ import { } from "./imapSequenceRanges.js"; import { isAuthenticationFailure } from "./authenticationFailure.js"; import { extractMessageLinks } from "./messageLinks.js"; +import { detectImapCapabilities } from "./imapCapabilities.js"; export class ImapReceiver implements MailReceiver { private static readonly maxBodyBytes = 2 * 1024 * 1024; @@ -31,6 +32,7 @@ export class ImapReceiver implements MailReceiver { const client = await this.createClient(account); try { await client.connect(); + this.recordCapabilities(account, client); } finally { await client.logout().catch(() => undefined); } @@ -208,6 +210,7 @@ export class ImapReceiver implements MailReceiver { try { await client.connect(); + this.recordCapabilities(account, client); await client.mailboxOpen(mailbox); } catch (error) { stopped = true; @@ -266,6 +269,11 @@ export class ImapReceiver implements MailReceiver { return client; } + // Callers persist the account, so the result survives restarts. + private recordCapabilities(account: MailAccount, client: ImapFlow): void { + account.incomingCapabilities = detectImapCapabilities(client.capabilities); + } + private async withConnectedClient( account: MailAccount, operation: (client: ImapFlow) => Promise @@ -273,6 +281,7 @@ export class ImapReceiver implements MailReceiver { const client = await this.createClient(account); try { await client.connect(); + this.recordCapabilities(account, client); return await operation(client); } finally { await client.logout().catch(() => undefined); diff --git a/apps/server/src/mail/imapCapabilities.ts b/apps/server/src/mail/imapCapabilities.ts new file mode 100644 index 0000000..7f7a2ac --- /dev/null +++ b/apps/server/src/mail/imapCapabilities.ts @@ -0,0 +1,16 @@ +import type { IncomingCapabilities } from "../domain/types.js"; + +/** Reads the post-login CAPABILITY set exposed by imapflow (`client.capabilities`). */ +export function detectImapCapabilities( + capabilities: ReadonlyMap, + now = new Date() +): IncomingCapabilities { + const has = (name: string) => capabilities.has(name); + return { + idle: has("IDLE"), + move: has("MOVE"), + specialUse: has("SPECIAL-USE"), + condstore: has("CONDSTORE"), + checkedAt: now.toISOString() + }; +} diff --git a/apps/server/src/workers/MailSyncWorker.ts b/apps/server/src/workers/MailSyncWorker.ts index 06f543a..1921276 100644 --- a/apps/server/src/workers/MailSyncWorker.ts +++ b/apps/server/src/workers/MailSyncWorker.ts @@ -219,6 +219,9 @@ export class MailSyncWorker { scheduleReconnect ); reconnectDelay = this.options.imapReconnectBaseDelayMs; + if (account.incomingCapabilities) { + await this.accounts.updateAccount(account).catch(() => undefined); + } } catch (error) { scheduleReconnect(error instanceof Error ? error : new Error(String(error))); } diff --git a/apps/server/test/imapCapabilities.test.ts b/apps/server/test/imapCapabilities.test.ts new file mode 100644 index 0000000..f73556c --- /dev/null +++ b/apps/server/test/imapCapabilities.test.ts @@ -0,0 +1,23 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { detectImapCapabilities } from "../src/mail/imapCapabilities.js"; + +test("detects IMAP capabilities from the CAPABILITY set", () => { + const now = new Date("2026-11-22T00:00:00.000Z"); + const result = detectImapCapabilities( + new Map([["IMAP4REV1", true], ["IDLE", true], ["MOVE", true]]), + now + ); + assert.deepEqual(result, { + idle: true, + move: true, + specialUse: false, + condstore: false, + checkedAt: now.toISOString() + }); +}); + +test("reports no IDLE when the server does not advertise it", () => { + const result = detectImapCapabilities(new Map([["IMAP4REV1", true]])); + assert.equal(result.idle, false); +}); From c97102ea4e9e04b54a0acc2365a91bd080c23235 Mon Sep 17 00:00:00 2001 From: Hwi Kim <166241069+littlebit0@users.noreply.github.com> Date: Sun, 22 Nov 2026 00:49:55 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EC=8B=A4=EC=A0=9C=EB=A1=9C=20IDLE=EC=9D=84?= =?UTF-8?q?=20=EC=93=B0=EB=8A=94=20=EA=B2=BD=EC=9A=B0=EC=97=90=EB=A7=8C=20?= =?UTF-8?q?idle=20=EC=88=98=EC=8B=A0=20=EB=B0=A9=EC=8B=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EA=B8=B0=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서버가 IDLE을 광고해도 provider가 supportsIdle=false(custom 등)이면 watch()가 IDLE을 쓰지 않으므로 incomingCapabilities.idle을 false로 저장한다. --- apps/server/src/mail/ImapReceiver.ts | 5 ++++- apps/server/test/imapCapabilities.test.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/server/src/mail/ImapReceiver.ts b/apps/server/src/mail/ImapReceiver.ts index 83e9543..f4748f1 100644 --- a/apps/server/src/mail/ImapReceiver.ts +++ b/apps/server/src/mail/ImapReceiver.ts @@ -271,7 +271,10 @@ export class ImapReceiver implements MailReceiver { // Callers persist the account, so the result survives restarts. private recordCapabilities(account: MailAccount, client: ImapFlow): void { - account.incomingCapabilities = detectImapCapabilities(client.capabilities); + const detected = detectImapCapabilities(client.capabilities); + // watch() refuses providers without supportsIdle, so "idle" means IDLE is actually used. + detected.idle &&= getProvider(account.providerId).incoming.supportsIdle; + account.incomingCapabilities = detected; } private async withConnectedClient( diff --git a/apps/server/test/imapCapabilities.test.ts b/apps/server/test/imapCapabilities.test.ts index f73556c..5302d7d 100644 --- a/apps/server/test/imapCapabilities.test.ts +++ b/apps/server/test/imapCapabilities.test.ts @@ -21,3 +21,17 @@ test("reports no IDLE when the server does not advertise it", () => { const result = detectImapCapabilities(new Map([["IMAP4REV1", true]])); assert.equal(result.idle, false); }); + +test("ImapReceiver records idle=false for providers that never run IDLE", async () => { + const { ImapReceiver } = await import("../src/mail/ImapReceiver.js"); + const receiver = new ImapReceiver({} as never, {} as never) as unknown as { + recordCapabilities(account: unknown, client: unknown): void; + }; + const client = { capabilities: new Map([["IDLE", true]]) }; + const custom: { providerId: string; incomingCapabilities?: { idle: boolean } } = { providerId: "custom" }; + const gmail: typeof custom = { providerId: "gmail" }; + receiver.recordCapabilities(custom, client); + receiver.recordCapabilities(gmail, client); + assert.equal(custom.incomingCapabilities?.idle, false); + assert.equal(gmail.incomingCapabilities?.idle, true); +}); From 307f4d5339944f6615a15ce110852ae65f7fd342 Mon Sep 17 00:00:00 2001 From: Hwi Kim <166241069+littlebit0@users.noreply.github.com> Date: Fri, 27 Nov 2026 02:03:04 +0900 Subject: [PATCH 3/3] =?UTF-8?q?IDLE=20=EA=B8=B0=EB=A1=9D=20=ED=8C=90?= =?UTF-8?q?=EC=A0=95=EC=9D=84=20=EA=B3=84=EC=A0=95=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EA=B8=B0=EC=A4=80(supportsImapIdle)=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=A7=9E=EC=B6=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit main의 폴링 대체(PR 24)는 계정 재정의까지 반영해 IDLE 사용 여부를 정한다. 수신 방식 기록도 같은 기준을 쓴다. --- apps/server/src/mail/ImapReceiver.ts | 4 ++-- apps/server/test/imapCapabilities.test.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/server/src/mail/ImapReceiver.ts b/apps/server/src/mail/ImapReceiver.ts index 9494b38..39dde00 100644 --- a/apps/server/src/mail/ImapReceiver.ts +++ b/apps/server/src/mail/ImapReceiver.ts @@ -296,8 +296,8 @@ export class ImapReceiver implements MailReceiver { // Callers persist the account, so the result survives restarts. private recordCapabilities(account: MailAccount, client: ImapFlow): void { const detected = detectImapCapabilities(client.capabilities); - // watch() refuses providers without supportsIdle, so "idle" means IDLE is actually used. - detected.idle &&= getProvider(account.providerId).incoming.supportsIdle; + // watch() refuses accounts without supportsImapIdle, so "idle" means IDLE is actually used. + detected.idle &&= supportsImapIdle(account); account.incomingCapabilities = detected; } diff --git a/apps/server/test/imapCapabilities.test.ts b/apps/server/test/imapCapabilities.test.ts index 5302d7d..e9733dd 100644 --- a/apps/server/test/imapCapabilities.test.ts +++ b/apps/server/test/imapCapabilities.test.ts @@ -28,8 +28,11 @@ test("ImapReceiver records idle=false for providers that never run IDLE", async recordCapabilities(account: unknown, client: unknown): void; }; const client = { capabilities: new Map([["IDLE", true]]) }; - const custom: { providerId: string; incomingCapabilities?: { idle: boolean } } = { providerId: "custom" }; - const gmail: typeof custom = { providerId: "gmail" }; + const custom: { providerId: string; incomingProtocol: string; incomingCapabilities?: { idle: boolean } } = { + providerId: "custom", + incomingProtocol: "imap" + }; + const gmail: typeof custom = { providerId: "gmail", incomingProtocol: "imap" }; receiver.recordCapabilities(custom, client); receiver.recordCapabilities(gmail, client); assert.equal(custom.incomingCapabilities?.idle, false);