@xemahq/biomes-platform-imap 0.6.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;
@@ -54,6 +115,10 @@ export interface ImapMessage {
54
115
  };
55
116
  readonly bodyStructure?: MimePartNode;
56
117
  }
118
+ export interface ImapDownloadOptions {
119
+ readonly uid: true;
120
+ readonly maxBytes?: number;
121
+ }
57
122
  export interface ImapMailboxLock {
58
123
  release(): void;
59
124
  }
@@ -74,12 +139,7 @@ export interface ImapClientLike {
74
139
  fetch(range: string, query: Readonly<Record<string, unknown>>, options: {
75
140
  uid: true;
76
141
  }): AsyncIterable<ImapMessage>;
77
- fetchOne(range: string, query: Readonly<Record<string, unknown>>, options: {
78
- uid: true;
79
- }): Promise<ImapMessage | false>;
80
- download(range: string, part: string | undefined, options: {
81
- uid: true;
82
- }): Promise<ImapDownloadResult>;
142
+ download(range: string, part: string | undefined, options: ImapDownloadOptions): Promise<ImapDownloadResult>;
83
143
  messageFlagsAdd(range: string, flags: readonly string[], options: {
84
144
  uid: true;
85
145
  }): Promise<boolean>;
@@ -101,13 +161,17 @@ export interface BodyFetchOptions {
101
161
  readonly includeAttachments: boolean;
102
162
  readonly attachmentSizeLimit: number;
103
163
  }
164
+ export type FetchedMessage = MessageEnvelope & MessageBody & {
165
+ readonly refused?: RefusedMessage;
166
+ };
104
167
  export interface FetchSinceMarkerResult {
105
168
  readonly mailbox: string;
106
169
  readonly uidValidity: string;
107
170
  readonly criteriaHash: string;
108
171
  readonly markerReset: boolean;
109
- readonly messages: readonly (MessageEnvelope & MessageBody)[];
172
+ readonly messages: readonly FetchedMessage[];
110
173
  readonly highestUidSeen: string;
174
+ readonly byteLimitReached: boolean;
111
175
  readonly attachments?: readonly ImapAttachment[];
112
176
  }
113
177
  export declare function fetchSinceMarker(client: ImapClientLike, params: {
@@ -117,6 +181,7 @@ export declare function fetchSinceMarker(client: ImapClientLike, params: {
117
181
  readonly sinceUid: number;
118
182
  readonly expectedUidValidity?: string;
119
183
  readonly body: BodyFetchOptions;
184
+ readonly limits?: Partial<ImapLimits>;
120
185
  }): Promise<FetchSinceMarkerResult>;
121
186
  export interface FetchByUidResult extends MessageEnvelope, MessageBody {
122
187
  readonly uidValidity: string;
@@ -131,6 +196,15 @@ export type FetchByUidOutcome = {
131
196
  readonly uidValidity: string;
132
197
  } | {
133
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;
134
208
  };
135
209
  export declare function fetchByUid(client: ImapClientLike, params: {
136
210
  readonly mailbox: string;
@@ -139,6 +213,7 @@ export declare function fetchByUid(client: ImapClientLike, params: {
139
213
  readonly markSeen: boolean;
140
214
  readonly includeAttachments: boolean;
141
215
  readonly attachmentSizeLimit: number;
216
+ readonly limits?: Partial<ImapLimits>;
142
217
  }): Promise<FetchByUidOutcome>;
143
218
  export interface SearchResult {
144
219
  readonly mailbox: string;
@@ -150,6 +225,7 @@ export declare function searchEmails(client: ImapClientLike, params: {
150
225
  readonly criteria: ImapSearchCriteria;
151
226
  readonly limit: number;
152
227
  readonly sort: 'oldest' | 'newest';
228
+ readonly limits?: Partial<ImapLimits>;
153
229
  }): Promise<SearchResult>;
154
230
  export interface MarkResult {
155
231
  readonly mailbox: string;
@@ -162,8 +238,13 @@ export declare function markMessages(client: ImapClientLike, params: {
162
238
  readonly uid: string;
163
239
  readonly flags: readonly string[];
164
240
  }): Promise<MarkResult>;
165
- export declare function makeFetchAction(factory: ImapClientFactory): OutboundActionHandler;
166
- export declare function makeFetchByUidAction(factory: ImapClientFactory): OutboundActionHandler;
167
- export declare function makeSearchAction(factory: ImapClientFactory): OutboundActionHandler;
168
- 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;
169
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;