Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/client/lib/core/i18n/language_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,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) {
Expand Down
17 changes: 17 additions & 0 deletions apps/client/lib/features/accounts/accounts_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,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(
Expand All @@ -477,6 +484,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;
Comment thread
littlebit0 marked this conversation as resolved.
Resolved
final checked = account.capabilitiesCheckedAtLabel;
return checked.isEmpty
? mode
: '$mode · ${strings.capabilitiesChecked} $checked';
}

class _InfoRow extends StatelessWidget {
const _InfoRow({
required this.label,
Expand Down
12 changes: 12 additions & 0 deletions apps/client/lib/services/mail_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ class MailAccountSummary {
this.syncErrorCode,
required this.initialSync,
required this.lastSyncedAtLabel,
this.idleSupported,
this.capabilitiesCheckedAtLabel = '',
this.notificationsEnabled = true,
});

Expand All @@ -486,7 +488,14 @@ class MailAccountSummary {
final String lastSyncedAtLabel;
final bool notificationsEnabled;

/// Null until the server has logged in and read the IMAP capabilities.
final bool? idleSupported;
final String capabilitiesCheckedAtLabel;

factory MailAccountSummary.fromJson(Map<String, dynamic> json) {
final capabilities = json['incomingCapabilities'] is Map<String, dynamic>
? json['incomingCapabilities'] as Map<String, dynamic>
: null;
return MailAccountSummary(
id: json['id'] as String,
providerId: json['providerId'] as String,
Expand All @@ -501,6 +510,9 @@ class MailAccountSummary {
json['initialSync'] as Map<String, dynamic>)
: null,
lastSyncedAtLabel: _formatReceivedAt(json['lastSyncedAt'] as String?),
idleSupported: capabilities?['idle'] as bool?,
capabilitiesCheckedAtLabel:
_formatReceivedAt(capabilities?['checkedAt'] as String?),
notificationsEnabled: json['notificationsEnabled'] as bool? ?? true,
);
}
Expand Down
37 changes: 37 additions & 0 deletions apps/client/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"dev": "tsx src/server.ts",
"test": "tsx --test test/imapSequenceRanges.test.ts test/mailSyncWorker.test.ts test/messageFlags.test.ts test/accountValidate.test.ts test/accountReconnect.test.ts test/searchQuery.test.ts test/oauthTokenManager.test.ts test/apnsPushNotifier.test.ts test/attachments.test.ts test/attachmentAccess.test.ts test/mailSearchAccess.test.ts test/replyRecipients.test.ts test/existsQueue.test.ts test/pop3Unsupported.test.ts test/deletedAccountSync.test.ts test/oauthSessionExpiry.test.ts test/noopPushNotifier.test.ts test/serverExposure.test.ts test/uidValidity.test.ts test/accountScopedMessage.test.ts test/customServerAccount.test.ts",
"test": "tsx --test test/imapSequenceRanges.test.ts test/mailSyncWorker.test.ts test/messageFlags.test.ts test/accountValidate.test.ts test/accountReconnect.test.ts test/searchQuery.test.ts test/oauthTokenManager.test.ts test/apnsPushNotifier.test.ts test/imapCapabilities.test.ts test/attachments.test.ts test/attachmentAccess.test.ts test/mailSearchAccess.test.ts test/replyRecipients.test.ts test/existsQueue.test.ts test/pop3Unsupported.test.ts test/deletedAccountSync.test.ts test/oauthSessionExpiry.test.ts test/noopPushNotifier.test.ts test/serverExposure.test.ts test/uidValidity.test.ts test/accountScopedMessage.test.ts test/customServerAccount.test.ts",
"typecheck": "tsc --noEmit",
"start": "node dist/server.js",
"build": "tsc"
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/domain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,6 +58,7 @@ export interface MailAccount {
limit: number | "all";
};
lastSyncedAt?: Date;
incomingCapabilities?: IncomingCapabilities;
// Missing means on, so accounts stored before this field keep notifying.
notificationsEnabled?: boolean;
// Every message up to this UID was checked by a completed sync, in the
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/mail/ImapReceiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
rawAttachmentFetch
} from "./attachments.js";
import { extractMessageLinks } from "./messageLinks.js";
import { detectImapCapabilities } from "./imapCapabilities.js";
import { createExistsQueue } from "./existsQueue.js";

export type { ImapSyncCursor } from "./imapSequenceRanges.js";
Expand All @@ -60,6 +61,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);
}
Expand Down Expand Up @@ -383,6 +385,7 @@ export class ImapReceiver implements MailReceiver {

try {
await client.connect();
this.recordCapabilities(account, client);
await client.mailboxOpen(mailbox);
} catch (error) {
stopped = true;
Expand Down Expand Up @@ -436,13 +439,22 @@ export class ImapReceiver implements MailReceiver {
return client;
}

// Callers persist the account, so the result survives restarts.
private recordCapabilities(account: MailAccount, client: ImapFlow): void {
const detected = detectImapCapabilities(client.capabilities);
// watch() refuses accounts without supportsImapIdle, so "idle" means IDLE is actually used.
detected.idle &&= supportsImapIdle(account);
account.incomingCapabilities = detected;
}

private async withConnectedClient<T>(
account: MailAccount,
operation: (client: ImapFlow) => Promise<T>
): Promise<T> {
const client = await this.createClient(account);
try {
await client.connect();
this.recordCapabilities(account, client);
return await operation(client);
} finally {
await client.logout().catch(() => undefined);
Expand Down
16 changes: 16 additions & 0 deletions apps/server/src/mail/imapCapabilities.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>,
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()
};
}
3 changes: 3 additions & 0 deletions apps/server/src/workers/MailSyncWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ export class MailSyncWorker {
scheduleReconnect
);
reconnectDelay = this.options.imapReconnectBaseDelayMs;
if (account.incomingCapabilities) {
await this.accounts.updateAccount(account).catch(() => undefined);
}
// Mail that arrived while disconnected raised no IDLE event. A sync
// already running may have taken its UID snapshot before the outage,
// so a fresh one starts after it instead of joining it.
Expand Down
40 changes: 40 additions & 0 deletions apps/server/test/imapCapabilities.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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<string, unknown>([["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);
});

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; 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);
assert.equal(gmail.incomingCapabilities?.idle, true);
});
Loading