@xemahq/biomes-platform-imap 0.5.0 → 0.7.0

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.
@@ -1,11 +1,72 @@
1
1
  import { type OutboundActionHandler } from '@xemahq/biome-sdk/adapter';
2
2
  import { EmailTlsMode } from '@xemahq/contracts/connector';
3
- import { type ImapAttachment, type MessageBody, type MimePartNode } from './imap-message-parts.js';
4
- export { DEFAULT_ATTACHMENT_SIZE_LIMIT, type ImapAttachment, type MessageBody, } from './imap-message-parts.js';
3
+ import { type ImapAttachment, MAIL_BODYSTRUCTURE_TOO_DEEP, type MessageBody, type MimePartNode } from './imap-message-parts.js';
4
+ import { type MailEventLog } from './mail-dial-guard.js';
5
+ export { DEFAULT_ATTACHMENT_SIZE_LIMIT, type ImapAttachment, MAIL_BODYSTRUCTURE_TOO_DEEP, MailBodyStructureTooDeepError, MAX_BODYSTRUCTURE_DEPTH, type MessageBody, } from './imap-message-parts.js';
6
+ export { MAIL_INBOUND_TOO_LARGE, MailInboundTooLargeError } from './mail-dial-guard.js';
5
7
  export declare const IMAP_FETCH_ACTION = "fetch";
6
8
  export declare const IMAP_FETCH_BY_UID_ACTION = "fetch-by-uid";
7
9
  export declare const IMAP_SEARCH_ACTION = "search";
8
10
  export declare const IMAP_MARK_ACTION = "mark";
11
+ export declare const MAIL_MESSAGE_TOO_LARGE: "MAIL_MESSAGE_TOO_LARGE";
12
+ export declare const MAIL_FETCH_TOO_LARGE: "MAIL_FETCH_TOO_LARGE";
13
+ export declare const MAIL_MESSAGE_SIZE_MISMATCH: "MAIL_MESSAGE_SIZE_MISMATCH";
14
+ export declare const MAIL_UNREQUESTED_RESPONSE: "MAIL_UNREQUESTED_RESPONSE";
15
+ export declare const MAIL_SEARCH_TOO_LARGE: "MAIL_SEARCH_TOO_LARGE";
16
+ export declare const MAIL_LIST_TOO_LARGE: "MAIL_LIST_TOO_LARGE";
17
+ export declare const MAIL_SEARCH_FAILED: "MAIL_SEARCH_FAILED";
18
+ export declare const MAIL_UNEXPECTED_RESPONSE: "MAIL_UNEXPECTED_RESPONSE";
19
+ export declare class MailMessageTooLargeError extends Error {
20
+ readonly uid: string;
21
+ readonly limit: number;
22
+ readonly code: "MAIL_MESSAGE_TOO_LARGE";
23
+ constructor(uid: string, limit: number);
24
+ }
25
+ export declare class MailFetchTooLargeError extends Error {
26
+ readonly limit: number;
27
+ readonly code: "MAIL_FETCH_TOO_LARGE";
28
+ constructor(limit: number);
29
+ }
30
+ export declare class MailUnrequestedResponseError extends Error {
31
+ readonly requested: number;
32
+ readonly code: "MAIL_UNREQUESTED_RESPONSE";
33
+ constructor(requested: number);
34
+ }
35
+ export declare class MailListTooLargeError extends Error {
36
+ readonly limit: number;
37
+ readonly code: "MAIL_LIST_TOO_LARGE";
38
+ constructor(limit: number);
39
+ }
40
+ export declare class MailSearchFailedError extends Error {
41
+ readonly code: "MAIL_SEARCH_FAILED";
42
+ constructor();
43
+ }
44
+ export declare class MailSearchTooLargeError extends Error {
45
+ readonly limit: number;
46
+ readonly code: "MAIL_SEARCH_TOO_LARGE";
47
+ constructor(limit: number);
48
+ }
49
+ export declare class MailUnexpectedResponseError extends Error {
50
+ readonly detail: string;
51
+ readonly code: "MAIL_UNEXPECTED_RESPONSE";
52
+ constructor(detail: string);
53
+ }
54
+ export interface ImapLimits {
55
+ readonly maxMessageBytes: number;
56
+ readonly maxFetchBytes: number;
57
+ readonly maxSearchBytes: number;
58
+ readonly maxListBytes: number;
59
+ readonly maxReceivedBytes: number;
60
+ }
61
+ export declare const DEFAULT_IMAP_LIMITS: ImapLimits;
62
+ export declare function resolveImapLimits(overrides?: {
63
+ readonly [K in keyof ImapLimits]?: number | undefined;
64
+ }): ImapLimits;
65
+ export interface RefusedMessage {
66
+ readonly code: typeof MAIL_MESSAGE_TOO_LARGE | typeof MAIL_MESSAGE_SIZE_MISMATCH | typeof MAIL_FETCH_TOO_LARGE | typeof MAIL_LIST_TOO_LARGE | typeof MAIL_BODYSTRUCTURE_TOO_DEEP;
67
+ readonly size: number;
68
+ readonly limit: number;
69
+ }
9
70
  export interface ImapSearchCriteria {
10
71
  readonly unseen?: boolean;
11
72
  readonly flagged?: boolean;
@@ -32,7 +93,6 @@ export interface MessageEnvelope {
32
93
  export interface ImapTransportConfig {
33
94
  readonly host: string;
34
95
  readonly port: number;
35
- readonly secure: boolean;
36
96
  readonly username: string;
37
97
  readonly password: string;
38
98
  }
@@ -55,6 +115,10 @@ export interface ImapMessage {
55
115
  };
56
116
  readonly bodyStructure?: MimePartNode;
57
117
  }
118
+ export interface ImapDownloadOptions {
119
+ readonly uid: true;
120
+ readonly maxBytes?: number;
121
+ }
58
122
  export interface ImapMailboxLock {
59
123
  release(): void;
60
124
  }
@@ -75,18 +139,13 @@ export interface ImapClientLike {
75
139
  fetch(range: string, query: Readonly<Record<string, unknown>>, options: {
76
140
  uid: true;
77
141
  }): AsyncIterable<ImapMessage>;
78
- fetchOne(range: string, query: Readonly<Record<string, unknown>>, options: {
79
- uid: true;
80
- }): Promise<ImapMessage | false>;
81
- download(range: string, part: string | undefined, options: {
82
- uid: true;
83
- }): Promise<ImapDownloadResult>;
142
+ download(range: string, part: string | undefined, options: ImapDownloadOptions): Promise<ImapDownloadResult>;
84
143
  messageFlagsAdd(range: string, flags: readonly string[], options: {
85
144
  uid: true;
86
145
  }): Promise<boolean>;
87
146
  }
88
147
  export type ImapClientFactory = (config: ImapTransportConfig) => ImapClientLike;
89
- export declare function resolveImapSecure(tlsMode: EmailTlsMode, port: number): boolean;
148
+ export declare function checkImapTlsMode(tlsMode: EmailTlsMode, port: number): string | undefined;
90
149
  export declare function readImapTransportConfig(hints: Readonly<Record<string, string>>): {
91
150
  ok: true;
92
151
  config: ImapTransportConfig;
@@ -102,13 +161,17 @@ export interface BodyFetchOptions {
102
161
  readonly includeAttachments: boolean;
103
162
  readonly attachmentSizeLimit: number;
104
163
  }
164
+ export type FetchedMessage = MessageEnvelope & MessageBody & {
165
+ readonly refused?: RefusedMessage;
166
+ };
105
167
  export interface FetchSinceMarkerResult {
106
168
  readonly mailbox: string;
107
169
  readonly uidValidity: string;
108
170
  readonly criteriaHash: string;
109
171
  readonly markerReset: boolean;
110
- readonly messages: readonly (MessageEnvelope & MessageBody)[];
172
+ readonly messages: readonly FetchedMessage[];
111
173
  readonly highestUidSeen: string;
174
+ readonly byteLimitReached: boolean;
112
175
  readonly attachments?: readonly ImapAttachment[];
113
176
  }
114
177
  export declare function fetchSinceMarker(client: ImapClientLike, params: {
@@ -118,6 +181,7 @@ export declare function fetchSinceMarker(client: ImapClientLike, params: {
118
181
  readonly sinceUid: number;
119
182
  readonly expectedUidValidity?: string;
120
183
  readonly body: BodyFetchOptions;
184
+ readonly limits?: Partial<ImapLimits>;
121
185
  }): Promise<FetchSinceMarkerResult>;
122
186
  export interface FetchByUidResult extends MessageEnvelope, MessageBody {
123
187
  readonly uidValidity: string;
@@ -132,6 +196,15 @@ export type FetchByUidOutcome = {
132
196
  readonly uidValidity: string;
133
197
  } | {
134
198
  readonly kind: 'not-found';
199
+ } | {
200
+ readonly kind: 'too-large';
201
+ readonly refused: RefusedMessage;
202
+ } | {
203
+ readonly kind: 'size-mismatch';
204
+ readonly refused: RefusedMessage;
205
+ } | {
206
+ readonly kind: 'malformed';
207
+ readonly refused: RefusedMessage;
135
208
  };
136
209
  export declare function fetchByUid(client: ImapClientLike, params: {
137
210
  readonly mailbox: string;
@@ -140,6 +213,7 @@ export declare function fetchByUid(client: ImapClientLike, params: {
140
213
  readonly markSeen: boolean;
141
214
  readonly includeAttachments: boolean;
142
215
  readonly attachmentSizeLimit: number;
216
+ readonly limits?: Partial<ImapLimits>;
143
217
  }): Promise<FetchByUidOutcome>;
144
218
  export interface SearchResult {
145
219
  readonly mailbox: string;
@@ -151,6 +225,7 @@ export declare function searchEmails(client: ImapClientLike, params: {
151
225
  readonly criteria: ImapSearchCriteria;
152
226
  readonly limit: number;
153
227
  readonly sort: 'oldest' | 'newest';
228
+ readonly limits?: Partial<ImapLimits>;
154
229
  }): Promise<SearchResult>;
155
230
  export interface MarkResult {
156
231
  readonly mailbox: string;
@@ -163,8 +238,13 @@ export declare function markMessages(client: ImapClientLike, params: {
163
238
  readonly uid: string;
164
239
  readonly flags: readonly string[];
165
240
  }): Promise<MarkResult>;
166
- export declare function makeFetchAction(factory: ImapClientFactory): OutboundActionHandler;
167
- export declare function makeFetchByUidAction(factory: ImapClientFactory): OutboundActionHandler;
168
- export declare function makeSearchAction(factory: ImapClientFactory): OutboundActionHandler;
169
- export declare function makeMarkAction(factory: ImapClientFactory): OutboundActionHandler;
241
+ export interface ImapActionOptions {
242
+ readonly limits?: Partial<ImapLimits>;
243
+ readonly operationMs?: number;
244
+ readonly log?: MailEventLog;
245
+ }
246
+ export declare function makeFetchAction(factory: ImapClientFactory, options?: ImapActionOptions): OutboundActionHandler;
247
+ export declare function makeFetchByUidAction(factory: ImapClientFactory, options?: ImapActionOptions): OutboundActionHandler;
248
+ export declare function makeSearchAction(factory: ImapClientFactory, options?: ImapActionOptions): OutboundActionHandler;
249
+ export declare function makeMarkAction(factory: ImapClientFactory, options?: ImapActionOptions): OutboundActionHandler;
170
250
  //# sourceMappingURL=imap-fetch.d.ts.map
@@ -38,7 +38,14 @@ export interface FlatAttachment {
38
38
  readonly size: number;
39
39
  readonly partId: string;
40
40
  }
41
- export declare function flattenAttachmentParts(node: MimePartNode, parentId?: string): FlatAttachment[];
41
+ export declare const MAX_BODYSTRUCTURE_DEPTH = 32;
42
+ export declare const MAIL_BODYSTRUCTURE_TOO_DEEP: "MAIL_BODYSTRUCTURE_TOO_DEEP";
43
+ export declare class MailBodyStructureTooDeepError extends Error {
44
+ readonly limit: number;
45
+ readonly code: "MAIL_BODYSTRUCTURE_TOO_DEEP";
46
+ constructor(limit: number);
47
+ }
48
+ export declare function flattenAttachmentParts(node: MimePartNode, parentId?: string, depth?: number): FlatAttachment[];
42
49
  export declare function extractBodies(raw: string): MessageBody;
43
50
  export declare function extractReferences(raw: string): string[] | undefined;
44
51
  export declare function parseSource(raw: string): ParsedSource;