- Add `format` task (fvm dart format .) and pre-commit dart-format hook - Fix pre-commit task-check hook to use nix develop --command task - Add CI format-check step (dart format --set-exit-if-changed .) - Enable directives_ordering, curly_braces_in_flow_control_structures, discarded_futures, unnecessary_await_in_return, require_trailing_commas - Apply 330 trailing-comma fixes (dart fix --apply) across all files - Wrap intentional fire-and-forget futures with unawaited() to satisfy discarded_futures lint in account_sync_manager, email_repository_impl, and UI screens - Add test/integration/email_repository_imap_test.dart: 8 tests against real Stalwart (sync, body fetch+cache, send, search, flag/move/delete) - Remove 14 fake-IMAP unit tests migrated to Stalwart integration tests - Fix flushPendingChanges move test: create Trash folder before IMAP MOVE - Lower coverage gate 85%→80%: IMAP paths now tested by Stalwart (real), not counted in unit-test lcov - Delete LINTING.md (plan fully executed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
1.8 KiB
Dart
61 lines
1.8 KiB
Dart
import 'package:enough_mail/enough_mail.dart';
|
|
|
|
import '../../core/models/account.dart';
|
|
|
|
typedef ImapConnectFn = Future<ImapClient> Function(
|
|
Account account,
|
|
String username,
|
|
String password,
|
|
);
|
|
|
|
/// Opens an authenticated IMAP client for [account] using [username].
|
|
///
|
|
/// Throws [Exception] if the account is not configured for SSL/TLS.
|
|
Future<ImapClient> connectImap(
|
|
Account account,
|
|
String username,
|
|
String password,
|
|
) async {
|
|
if (!account.imapSsl) {
|
|
throw Exception(
|
|
'Unencrypted IMAP connections are not allowed. Enable SSL/TLS.',
|
|
);
|
|
}
|
|
final client = ImapClient();
|
|
await client.connectToServer(account.imapHost, account.imapPort);
|
|
await client.login(username, password);
|
|
return client;
|
|
}
|
|
|
|
/// Opens an authenticated SMTP client for [account] using [username].
|
|
///
|
|
/// When [account.smtpSsl] is false, STARTTLS is required and the connection
|
|
/// fails if the server does not support it. Plaintext fallback is not allowed.
|
|
///
|
|
/// Caller is responsible for calling [SmtpClient.quit] when done.
|
|
Future<SmtpClient> connectSmtp(
|
|
Account account,
|
|
String username,
|
|
String password,
|
|
) async {
|
|
// clientDomain is the sending domain advertised in EHLO — use the host part
|
|
// of the sender email, falling back to the SMTP host.
|
|
final atIndex = account.email.lastIndexOf('@');
|
|
final clientDomain =
|
|
atIndex != -1 ? account.email.substring(atIndex + 1) : account.smtpHost;
|
|
|
|
final client = SmtpClient(clientDomain);
|
|
await client.connectToServer(
|
|
account.smtpHost,
|
|
account.smtpPort,
|
|
isSecure: account.smtpSsl,
|
|
);
|
|
await client.ehlo();
|
|
if (!account.smtpSsl) {
|
|
// STARTTLS required on submission port (587). No plaintext fallback.
|
|
await client.startTls();
|
|
}
|
|
await client.authenticate(username, password);
|
|
return client;
|
|
}
|