imapflow 1.0.192 → 1.0.194

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ 'use strict';
2
+
3
+ const { ImapFlow } = require('../lib/imap-flow');
4
+
5
+ module.exports['Connection: Basic connection options'] = test => {
6
+ let client = new ImapFlow({
7
+ host: 'imap.example.com',
8
+ port: 993,
9
+ auth: { user: 'test', pass: 'test' }
10
+ });
11
+
12
+ test.equal(client.host, 'imap.example.com');
13
+ test.equal(client.port, 993);
14
+ test.done();
15
+ };
16
+
17
+ module.exports['Connection: Default options'] = test => {
18
+ let client = new ImapFlow({
19
+ host: 'imap.example.com',
20
+ auth: { user: 'test', pass: 'test' }
21
+ });
22
+
23
+ test.equal(client.port, 110);
24
+ test.equal(client.secureConnection, false);
25
+ test.done();
26
+ };
27
+
28
+ module.exports['Connection: Secure connection defaults'] = test => {
29
+ let client = new ImapFlow({
30
+ host: 'imap.example.com',
31
+ port: 993,
32
+ auth: { user: 'test', pass: 'test' }
33
+ });
34
+
35
+ test.equal(client.secureConnection, true);
36
+ test.done();
37
+ };
38
+
39
+ module.exports['Connection: TLS options'] = test => {
40
+ let client = new ImapFlow({
41
+ host: 'imap.example.com',
42
+ auth: { user: 'test', pass: 'test' },
43
+ tls: {
44
+ rejectUnauthorized: false,
45
+ minVersion: 'TLSv1.3'
46
+ }
47
+ });
48
+
49
+ test.equal(client.options.tls.rejectUnauthorized, false);
50
+ test.equal(client.options.tls.minVersion, 'TLSv1.3');
51
+ test.done();
52
+ };
53
+
54
+ module.exports['Connection: Authentication options'] = test => {
55
+ let client = new ImapFlow({
56
+ host: 'imap.example.com',
57
+ auth: {
58
+ user: 'testuser',
59
+ pass: 'testpass',
60
+ accessToken: 'token123'
61
+ }
62
+ });
63
+
64
+ test.equal(client.options.auth.user, 'testuser');
65
+ test.equal(client.options.auth.pass, 'testpass');
66
+ test.equal(client.options.auth.accessToken, 'token123');
67
+ test.done();
68
+ };
69
+
70
+ module.exports['Connection: Proxy configuration'] = test => {
71
+ let client = new ImapFlow({
72
+ host: 'imap.example.com',
73
+ auth: { user: 'test', pass: 'test' },
74
+ proxy: 'socks5://proxy.example.com:1080'
75
+ });
76
+
77
+ test.equal(client.options.proxy, 'socks5://proxy.example.com:1080');
78
+ test.done();
79
+ };
80
+
81
+ module.exports['Connection: Client info'] = test => {
82
+ let clientInfo = {
83
+ name: 'Test Client',
84
+ version: '1.0.0',
85
+ vendor: 'Test Corp'
86
+ };
87
+
88
+ let client = new ImapFlow({
89
+ host: 'imap.example.com',
90
+ auth: { user: 'test', pass: 'test' },
91
+ clientInfo
92
+ });
93
+
94
+ test.equal(client.clientInfo.name, 'Test Client');
95
+ test.equal(client.clientInfo.version, '1.0.0');
96
+ test.equal(client.clientInfo.vendor, 'Test Corp');
97
+ test.done();
98
+ };
99
+
100
+ module.exports['Connection: Logger configuration'] = test => {
101
+ let client = new ImapFlow({
102
+ host: 'imap.example.com',
103
+ auth: { user: 'test', pass: 'test' },
104
+ logger: false
105
+ });
106
+
107
+ test.equal(client.options.logger, false);
108
+ test.done();
109
+ };
110
+
111
+ module.exports['Connection: Stats tracking'] = test => {
112
+ let client = new ImapFlow({
113
+ host: 'imap.example.com',
114
+ auth: { user: 'test', pass: 'test' }
115
+ });
116
+
117
+ let stats = client.stats();
118
+ test.ok(Object.prototype.hasOwnProperty.call(stats, 'sent'));
119
+ test.ok(Object.prototype.hasOwnProperty.call(stats, 'received'));
120
+ test.equal(typeof stats.sent, 'number');
121
+ test.equal(typeof stats.received, 'number');
122
+ test.done();
123
+ };
124
+
125
+ module.exports['Connection: Random ID generation'] = test => {
126
+ let client = new ImapFlow({
127
+ host: 'imap.example.com',
128
+ auth: { user: 'test', pass: 'test' }
129
+ });
130
+
131
+ let id1 = client.getRandomId();
132
+ let id2 = client.getRandomId();
133
+
134
+ test.ok(typeof id1 === 'string' && id1.length > 0);
135
+ test.ok(typeof id2 === 'string' && id2.length > 0);
136
+ test.notEqual(id1, id2, 'IDs should be unique');
137
+ test.done();
138
+ };
139
+
140
+ module.exports['Connection: State management'] = test => {
141
+ let client = new ImapFlow({
142
+ host: 'imap.example.com',
143
+ auth: { user: 'test', pass: 'test' }
144
+ });
145
+
146
+ test.equal(client.state, client.states.NOT_AUTHENTICATED);
147
+ test.equal(client.authenticated, false);
148
+ test.ok(client.capabilities instanceof Map);
149
+ test.done();
150
+ };
151
+
152
+ module.exports['Connection: Event emitter setup'] = test => {
153
+ let client = new ImapFlow({
154
+ host: 'imap.example.com',
155
+ auth: { user: 'test', pass: 'test' }
156
+ });
157
+
158
+ test.equal(typeof client.on, 'function');
159
+ test.equal(typeof client.emit, 'function');
160
+ test.equal(typeof client.removeListener, 'function');
161
+ test.done();
162
+ };
@@ -0,0 +1,83 @@
1
+ 'use strict';
2
+
3
+ const { ImapFlow } = require('../lib/imap-flow');
4
+
5
+ module.exports['Integration: Basic client creation'] = test => {
6
+ let client = new ImapFlow({
7
+ host: 'imap.example.com',
8
+ auth: { user: 'test', pass: 'test' }
9
+ });
10
+
11
+ test.ok(client);
12
+ test.equal(client.state, client.states.NOT_AUTHENTICATED);
13
+ test.equal(client.authenticated, false);
14
+ test.done();
15
+ };
16
+
17
+ module.exports['Integration: Multiple client instances'] = test => {
18
+ let client1 = new ImapFlow({
19
+ host: 'imap1.example.com',
20
+ auth: { user: 'test1', pass: 'test1' }
21
+ });
22
+
23
+ let client2 = new ImapFlow({
24
+ host: 'imap2.example.com',
25
+ auth: { user: 'test2', pass: 'test2' }
26
+ });
27
+
28
+ test.ok(client1);
29
+ test.ok(client2);
30
+ test.notEqual(client1.id, client2.id);
31
+ test.done();
32
+ };
33
+
34
+ module.exports['Integration: Client configuration'] = test => {
35
+ let client = new ImapFlow({
36
+ host: 'imap.example.com',
37
+ port: 993,
38
+ secure: true,
39
+ auth: { user: 'test', pass: 'test' },
40
+ logger: false
41
+ });
42
+
43
+ test.equal(client.host, 'imap.example.com');
44
+ test.equal(client.port, 993);
45
+ test.equal(client.secureConnection, true);
46
+ test.done();
47
+ };
48
+
49
+ module.exports['Integration: Event emitter functionality'] = test => {
50
+ let client = new ImapFlow({
51
+ host: 'imap.example.com',
52
+ auth: { user: 'test', pass: 'test' }
53
+ });
54
+
55
+ let eventFired = false;
56
+ client.on('test-event', () => {
57
+ eventFired = true;
58
+ });
59
+
60
+ client.emit('test-event');
61
+
62
+ setTimeout(() => {
63
+ test.ok(eventFired);
64
+ test.done();
65
+ }, 10);
66
+ };
67
+
68
+ module.exports['Integration: Stats functionality'] = test => {
69
+ let client = new ImapFlow({
70
+ host: 'imap.example.com',
71
+ auth: { user: 'test', pass: 'test' }
72
+ });
73
+
74
+ let stats = client.stats();
75
+ test.ok(typeof stats === 'object');
76
+ test.ok(Object.prototype.hasOwnProperty.call(stats, 'sent'));
77
+ test.ok(Object.prototype.hasOwnProperty.call(stats, 'received'));
78
+
79
+ // Reset stats
80
+ let resetStats = client.stats(true);
81
+ test.ok(typeof resetStats === 'object');
82
+ test.done();
83
+ };
@@ -0,0 +1,81 @@
1
+ 'use strict';
2
+
3
+ const { searchCompiler } = require('../lib/search-compiler');
4
+
5
+ // Mock connection for testing
6
+ let createMockConnection = () => ({
7
+ capabilities: new Map([
8
+ ['IMAP4rev1', true],
9
+ ['UTF8=ACCEPT', true]
10
+ ]),
11
+ enabled: new Set(['UTF8=ACCEPT'])
12
+ });
13
+
14
+ // Mock mailbox for testing
15
+ let createMockMailbox = () => ({
16
+ flags: new Set(['\\Seen', '\\Answered', '\\Flagged', '\\Deleted', '\\Draft']),
17
+ permanentFlags: new Set(['\\*'])
18
+ });
19
+
20
+ module.exports['Search Compiler: Basic functionality'] = test => {
21
+ let connection = createMockConnection();
22
+ let mailbox = createMockMailbox();
23
+
24
+ test.doesNotThrow(() => {
25
+ let compiled = searchCompiler(connection, { seen: false }, mailbox);
26
+ test.ok(Array.isArray(compiled));
27
+ });
28
+
29
+ test.done();
30
+ };
31
+
32
+ module.exports['Search Compiler: Text searches'] = test => {
33
+ let connection = createMockConnection();
34
+ let mailbox = createMockMailbox();
35
+
36
+ let compiled = searchCompiler(connection, {
37
+ from: 'user@example.com',
38
+ subject: 'Test'
39
+ }, mailbox);
40
+
41
+ test.ok(Array.isArray(compiled));
42
+ test.ok(compiled.length > 0);
43
+ test.done();
44
+ };
45
+
46
+ module.exports['Search Compiler: Flag searches'] = test => {
47
+ let connection = createMockConnection();
48
+ let mailbox = createMockMailbox();
49
+
50
+ let compiled = searchCompiler(connection, {
51
+ seen: true,
52
+ answered: false
53
+ }, mailbox);
54
+
55
+ test.ok(Array.isArray(compiled));
56
+ test.ok(compiled.length > 0);
57
+ test.done();
58
+ };
59
+
60
+ module.exports['Search Compiler: Date searches'] = test => {
61
+ let connection = createMockConnection();
62
+ let mailbox = createMockMailbox();
63
+
64
+ let compiled = searchCompiler(connection, {
65
+ since: new Date('2023-01-01')
66
+ }, mailbox);
67
+
68
+ test.ok(Array.isArray(compiled));
69
+ test.ok(compiled.length > 0);
70
+ test.done();
71
+ };
72
+
73
+ module.exports['Search Compiler: Empty query'] = test => {
74
+ let connection = createMockConnection();
75
+ let mailbox = createMockMailbox();
76
+
77
+ let compiled = searchCompiler(connection, {}, mailbox);
78
+
79
+ test.ok(Array.isArray(compiled));
80
+ test.done();
81
+ };
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const specialUse = require('../lib/special-use');
4
+
5
+ module.exports['Special Use: flags array'] = test => {
6
+ test.ok(Array.isArray(specialUse.flags));
7
+ test.ok(specialUse.flags.includes('\\Sent'));
8
+ test.ok(specialUse.flags.includes('\\Drafts'));
9
+ test.ok(specialUse.flags.includes('\\Trash'));
10
+ test.ok(specialUse.flags.includes('\\Archive'));
11
+ test.done();
12
+ };
13
+
14
+ module.exports['Special Use: names object'] = test => {
15
+ test.ok(typeof specialUse.names === 'object');
16
+ test.ok(specialUse.names['\\Sent']);
17
+ test.ok(Array.isArray(specialUse.names['\\Sent']));
18
+ test.ok(specialUse.names['\\Sent'].includes('sent'));
19
+ test.done();
20
+ };
21
+
22
+ module.exports['Special Use: Sent folder names'] = test => {
23
+ let sentNames = specialUse.names['\\Sent'];
24
+ test.ok(sentNames.includes('sent'));
25
+ test.ok(sentNames.includes('sent items'));
26
+ test.ok(sentNames.includes('sent messages'));
27
+ test.done();
28
+ };
29
+
30
+ module.exports['Special Use: Drafts folder names'] = test => {
31
+ let draftsNames = specialUse.names['\\Drafts'];
32
+ test.ok(draftsNames.includes('drafts'));
33
+ test.done();
34
+ };
35
+
36
+ module.exports['Special Use: Trash folder names'] = test => {
37
+ let trashNames = specialUse.names['\\Trash'];
38
+ test.ok(trashNames.includes('trash'));
39
+ test.ok(trashNames.includes('deleted items'));
40
+ test.ok(trashNames.includes('deleted messages'));
41
+ test.done();
42
+ };
43
+
44
+ module.exports['Special Use: Junk folder names'] = test => {
45
+ let junkNames = specialUse.names['\\Junk'];
46
+ test.ok(junkNames.includes('spam'));
47
+ test.ok(junkNames.includes('junk'));
48
+ test.done();
49
+ };