Files
sharedinbox/lib/core/models/mailbox.dart
T
Thomas Güttler 8d268f1165 Implement multi-account search and improve repository fakes
- Extended search to support global queries across all accounts.
- Updated SearchScreen to handle optional account context and unified results.
- Centralized mailbox comparison logic in Mailbox model.
- Added copyWith to Account model.
- Fixed race conditions and incorrect overrides in unit, widget, and integration tests.
- Reached 80% unit test coverage.
2026-05-08 01:01:18 +02:00

36 lines
1.2 KiB
Dart

/// A mailbox / folder within an account (maps to an IMAP mailbox).
class Mailbox {
final String id; // "<accountId>:<path>"
final String accountId;
final String path; // e.g. "INBOX", "Sent", "INBOX/Work"
final String name; // last path component
final int unreadCount;
final int totalCount;
// JMAP role (RFC 8621) or mapped from IMAP special-use (RFC 6154).
// e.g. "inbox", "sent", "drafts", "junk", "trash", "archive"
final String? role;
const Mailbox({
required this.id,
required this.accountId,
required this.path,
required this.name,
required this.unreadCount,
required this.totalCount,
this.role,
});
}
/// Sorts mailboxes by role priority (Inbox first, etc) then alphabetically by path.
int compareMailboxes(Mailbox a, Mailbox b) {
const roleOrder = ['inbox', 'drafts', 'sent', 'archive', 'junk', 'trash'];
if (a.role != b.role) {
final idxA = a.role == null ? 99 : roleOrder.indexOf(a.role!);
final idxB = b.role == null ? 99 : roleOrder.indexOf(b.role!);
if (idxA != idxB) {
return (idxA == -1 ? 99 : idxA).compareTo(idxB == -1 ? 99 : idxB);
}
}
return a.path.toLowerCase().compareTo(b.path.toLowerCase());
}