MailHub v1.0.0: 跨平台邮箱客户端(纯 Dart IMAP/SMTP/MIME 协议栈)
- 登录: QQ/163/126/189/搜狐/Gmail/Outlook/Yahoo/iCloud/企业邮/自定义, 自动识别+测试连接 - 收信: IMAP 多文件夹同步/未读/星标/搜索(本地+服务器) - 读信: HTML渲染/CID内嵌图/原文查看/附件下载 - 写信: 收件人/抄送/密送/附件/富文本/草稿/回复转发 - 存储: SQLite + 系统安全存储(DPAPI/Keychain/Keystore) - 测试: 单元测试 + Mock IMAP/SMTP 服务器集成测试(23项全过) - 可迁移: Windows/Android/iOS/macOS/Linux 一套代码
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mail_hub/core/protocol/imap/imap_parser.dart';
|
||||
|
||||
void main() {
|
||||
group('IMAP 响应解析', () {
|
||||
test('FETCH 带字面量(HEADER + TEXT)', () {
|
||||
final header = 'Subject: test\r\nFrom: a@b.com\r\n';
|
||||
final text = 'Hello World!';
|
||||
final parts = [
|
||||
ImapPart('* 1 FETCH (UID 5 BODY[HEADER] {${header.length}}', header.codeUnits),
|
||||
ImapPart(' BODY[TEXT] {${text.length}}', text.codeUnits),
|
||||
ImapPart(' FLAGS (\\Seen))'),
|
||||
];
|
||||
final fd = ImapParser.parseFetch(parts)!;
|
||||
expect(fd.uid, 5);
|
||||
expect(fd.seen, true);
|
||||
expect(String.fromCharCodes(fd.bodies['HEADER']!), contains('Subject: test'));
|
||||
expect(String.fromCharCodes(fd.bodies['TEXT']!), 'Hello World!');
|
||||
});
|
||||
|
||||
test('FETCH 部分抓取 <0.100>', () {
|
||||
final parts = [
|
||||
ImapPart('* 2 FETCH (UID 9 BODY[TEXT]<0.100> {5}', 'hello'.codeUnits),
|
||||
ImapPart(')'),
|
||||
];
|
||||
final fd = ImapParser.parseFetch(parts)!;
|
||||
expect(fd.uid, 9);
|
||||
expect(String.fromCharCodes(fd.bodies['TEXT']!), 'hello');
|
||||
});
|
||||
|
||||
test('SEARCH 结果', () {
|
||||
final lines = ['* SEARCH 1 2 3', '* SEARCH 4 5'];
|
||||
expect(ImapParser.parseSearch(lines), [1, 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
test('LIST 文件夹', () {
|
||||
final lines = [
|
||||
r'* LIST (\HasNoChildren) "/" "INBOX"',
|
||||
r'* LIST (\HasChildren \Noselect) "/" "[Gmail]"',
|
||||
];
|
||||
final list = ImapParser.parseList(lines);
|
||||
expect(list.length, 2);
|
||||
expect(list[0].name, 'INBOX');
|
||||
expect(list[0].delim, '/');
|
||||
expect(list[1].attrs, contains(r'\Noselect'));
|
||||
});
|
||||
|
||||
test('STATUS 解析', () {
|
||||
final map = ImapParser.parseStatus(
|
||||
'* STATUS INBOX (MESSAGES 231 UNSEEN 4 UIDNEXT 44292)');
|
||||
expect(map!['MESSAGES'], 231);
|
||||
expect(map['UNSEEN'], 4);
|
||||
expect(map['UIDNEXT'], 44292);
|
||||
});
|
||||
|
||||
test('状态响应 OK/NO', () {
|
||||
final ok = ImapStatus.parse('a1 OK [READ-WRITE] SELECT completed');
|
||||
expect(ok.ok, true);
|
||||
expect(ok.responseCode, 'READ-WRITE');
|
||||
final no = ImapStatus.parse('a2 NO [AUTHENTICATIONFAILED] Invalid credentials');
|
||||
expect(no.ok, false);
|
||||
expect(no.responseCode, 'AUTHENTICATIONFAILED');
|
||||
});
|
||||
|
||||
test('INTERNALDATE 解析', () {
|
||||
final fd = ImapParser.parseFetch([
|
||||
ImapPart('* 1 FETCH (UID 5 INTERNALDATE "17-Aug-2026 08:23:45 +0800")'),
|
||||
])!;
|
||||
expect(fd.internalDate, isNotNull);
|
||||
expect(fd.internalDate!.year, 2026);
|
||||
expect(fd.internalDate!.month, 8);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user