@im-more/dsh-mail 0.0.0-stage → 0.1.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.
Files changed (66) hide show
  1. package/LICENSE +21 -0
  2. package/cordis.patch.yml +14 -0
  3. package/lib/index.js +1334 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/types/bot.d.ts +49 -0
  6. package/lib/types/bot.d.ts.map +1 -0
  7. package/lib/types/bot.js +189 -0
  8. package/lib/types/bot.js.map +1 -0
  9. package/lib/types/config.d.ts +51 -0
  10. package/lib/types/config.d.ts.map +1 -0
  11. package/lib/types/config.js +55 -0
  12. package/lib/types/config.js.map +1 -0
  13. package/lib/types/decode.d.ts +60 -0
  14. package/lib/types/decode.d.ts.map +1 -0
  15. package/lib/types/decode.js +195 -0
  16. package/lib/types/decode.js.map +1 -0
  17. package/lib/types/errors.d.ts +33 -0
  18. package/lib/types/errors.d.ts.map +1 -0
  19. package/lib/types/errors.js +156 -0
  20. package/lib/types/errors.js.map +1 -0
  21. package/lib/types/html.d.ts +30 -0
  22. package/lib/types/html.d.ts.map +1 -0
  23. package/lib/types/html.js +121 -0
  24. package/lib/types/html.js.map +1 -0
  25. package/lib/types/index.d.ts +11 -0
  26. package/lib/types/index.d.ts.map +1 -0
  27. package/lib/types/index.js +10 -0
  28. package/lib/types/index.js.map +1 -0
  29. package/lib/types/mail.d.ts +24 -0
  30. package/lib/types/mail.d.ts.map +1 -0
  31. package/lib/types/mail.js +26 -0
  32. package/lib/types/mail.js.map +1 -0
  33. package/lib/types/media.d.ts +52 -0
  34. package/lib/types/media.d.ts.map +1 -0
  35. package/lib/types/media.js +81 -0
  36. package/lib/types/media.js.map +1 -0
  37. package/lib/types/modes/html.d.ts +13 -0
  38. package/lib/types/modes/html.d.ts.map +1 -0
  39. package/lib/types/modes/html.js +70 -0
  40. package/lib/types/modes/html.js.map +1 -0
  41. package/lib/types/modes/shared.d.ts +114 -0
  42. package/lib/types/modes/shared.d.ts.map +1 -0
  43. package/lib/types/modes/shared.js +185 -0
  44. package/lib/types/modes/shared.js.map +1 -0
  45. package/lib/types/send.d.ts +26 -0
  46. package/lib/types/send.d.ts.map +1 -0
  47. package/lib/types/send.js +58 -0
  48. package/lib/types/send.js.map +1 -0
  49. package/lib/types/transport/imap.d.ts +95 -0
  50. package/lib/types/transport/imap.d.ts.map +1 -0
  51. package/lib/types/transport/imap.js +354 -0
  52. package/lib/types/transport/imap.js.map +1 -0
  53. package/package.json +70 -3
  54. package/src/bot.ts +264 -0
  55. package/src/config.ts +98 -0
  56. package/src/decode.ts +275 -0
  57. package/src/errors.ts +199 -0
  58. package/src/html.ts +137 -0
  59. package/src/index.ts +32 -0
  60. package/src/mail.ts +46 -0
  61. package/src/media.ts +102 -0
  62. package/src/modes/html.ts +105 -0
  63. package/src/modes/shared.ts +285 -0
  64. package/src/send.ts +87 -0
  65. package/src/transport/imap.ts +418 -0
  66. package/README.md +0 -3
@@ -0,0 +1,26 @@
1
+ import type { SendContext, SentPart, Target } from '@deepseek-ai/cordis-plugin-im-core';
2
+ import type { Config } from './config.ts';
3
+ import type { MediaStaging } from './media.ts';
4
+ import type { MailPayload } from './modes/shared.ts';
5
+ import type { SMTP } from './mail.ts';
6
+ /** Everything `sendPayload` needs from the adapter. */
7
+ export interface MailSendDeps {
8
+ readonly config: Config;
9
+ readonly staging: MediaStaging;
10
+ readonly smtp: SMTP;
11
+ }
12
+ /**
13
+ * Publish one logical message as one SMTP transaction.
14
+ *
15
+ * The staged bytes are read before sending and released only after the server accepted the message, so a failed or
16
+ * retried send still finds them. `confirmed` means the server answered `2xx` to `DATA` — the message left this host,
17
+ * not that its recipient ever receives it.
18
+ *
19
+ * @param deps - staging and the SMTP transport.
20
+ * @param payload - the serialized message.
21
+ * @param _target - the chat being published to (the payload already names its recipient).
22
+ * @param _ctx - send context (the quote is already part of the payload).
23
+ * @returns the published part; `id` is nodemailer's generated `Message-ID`.
24
+ */
25
+ export declare function sendPayload(deps: MailSendDeps, payload: MailPayload, _target: Target, _ctx: SendContext): Promise<SentPart>;
26
+ //# sourceMappingURL=send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../src/send.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,MAAM,EACP,MAAM,oCAAoC,CAAA;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AACpD,OAAO,KAAK,EAA2B,IAAI,EAAE,MAAM,WAAW,CAAA;AAE9D,uDAAuD;AACvD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;IAC9B,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAC/B,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,QAAQ,CAAC,CAkDnB"}
@@ -0,0 +1,58 @@
1
+ import { PlatformError } from '@deepseek-ai/cordis-plugin-im-core';
2
+ /**
3
+ * Publish one logical message as one SMTP transaction.
4
+ *
5
+ * The staged bytes are read before sending and released only after the server accepted the message, so a failed or
6
+ * retried send still finds them. `confirmed` means the server answered `2xx` to `DATA` — the message left this host,
7
+ * not that its recipient ever receives it.
8
+ *
9
+ * @param deps - staging and the SMTP transport.
10
+ * @param payload - the serialized message.
11
+ * @param _target - the chat being published to (the payload already names its recipient).
12
+ * @param _ctx - send context (the quote is already part of the payload).
13
+ * @returns the published part; `id` is nodemailer's generated `Message-ID`.
14
+ */
15
+ export async function sendPayload(deps, payload, _target, _ctx) {
16
+ const attachments = [];
17
+ for (const attachment of payload.attachments) {
18
+ const staged = deps.staging.get(attachment.key);
19
+ if (staged === undefined) {
20
+ throw new PlatformError('invalid', `mail: the attachment "${attachment.filename}" is no longer staged, nothing was sent`, { published: 'no' });
21
+ }
22
+ attachments.push({
23
+ filename: attachment.filename,
24
+ content: Buffer.from(staged.data),
25
+ contentType: attachment.contentType,
26
+ ...(attachment.cid === undefined ? {} : { cid: attachment.cid }),
27
+ });
28
+ }
29
+ const options = {
30
+ to: payload.to,
31
+ subject: payload.subject,
32
+ html: payload.html,
33
+ text: payload.text,
34
+ ...(payload.inReplyTo === undefined
35
+ ? {}
36
+ : { inReplyTo: payload.inReplyTo }),
37
+ ...(payload.references === undefined
38
+ ? {}
39
+ : { references: payload.references }),
40
+ ...(attachments.length === 0 ? {} : { attachments }),
41
+ };
42
+ const id = await deps.smtp.send(options);
43
+ // The server already accepted the body, so an answer without a Message-ID is a published outcome, not a refusal.
44
+ if (!id) {
45
+ throw new PlatformError('invalid', 'mail: the server accepted the message without a Message-ID', {
46
+ published: 'unknown',
47
+ });
48
+ }
49
+ for (const attachment of payload.attachments)
50
+ deps.staging.take(attachment.key);
51
+ return {
52
+ id,
53
+ kind: 'message',
54
+ time: Date.now(),
55
+ referrer: { address: payload.to, messageId: id, subject: payload.subject },
56
+ };
57
+ }
58
+ //# sourceMappingURL=send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"send.js","sourceRoot":"","sources":["../../src/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAkBlE;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAkB,EAClB,OAAoB,EACpB,OAAe,EACf,IAAiB;IAEjB,MAAM,WAAW,GAAiB,EAAE,CAAA;IACpC,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,MAAM,GAA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C,CAAA;IACxC,iHAAiH;IACjH,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,aAAa,CACrB,SAAS,EACT,4DAA4D,EAC5D;YACE,SAAS,EAAE,SAAS;SACrB,CACF,CAAA;IACH,CAAC;IACD,KAAK,MAAM,UAAU,IAAI,OAAO,CAAC,WAAW;QAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACnC,OAAO;QACL,EAAE;QACF,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE;QAChB,QAAQ,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE;KAC3E,CAAA;AACH,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * IMAP inbound transport: connection lifecycle, scanning, acknowledgement and reconnection.
3
+ *
4
+ * `node-imap` owns IDLE/NOOP keepalive internally, so this transport never sends a keepalive itself. It starts one
5
+ * `Connection` and reuses it for every reconnect (the library resets its own state and keeps listeners). Every
6
+ * `\\Seen` write happens only after the host accepted the message: a crash or a failed intake therefore leaves the
7
+ * message unread, and the next scan delivers it again (the host dedupes by `Message-ID`). A malformed message is the
8
+ * one exception: it is marked seen, because retrying it would fail forever.
9
+ */
10
+ import type { ParsedMail } from 'mailparser';
11
+ import type { Config } from '../config.ts';
12
+ import type { MailSource } from '../decode.ts';
13
+ /** The `source` field `node-imap` attaches to its errors (`'authentication'`, `'timeout'`, `'socket'`, …). */
14
+ export interface ImapError extends Error {
15
+ source?: string;
16
+ }
17
+ /** The logging surface the transport uses (a `ctx.logger`). */
18
+ export interface MailLogger {
19
+ info(...args: unknown[]): void;
20
+ warn(...args: unknown[]): void;
21
+ error(...args: unknown[]): void;
22
+ debug(...args: unknown[]): void;
23
+ }
24
+ /** What the transport needs from the adapter. */
25
+ export interface ImapTransportOptions {
26
+ config: Config;
27
+ logger: MailLogger;
28
+ /** Hand one parsed message to the host; rejection means "not accepted", so the message stays unseen. */
29
+ deliver(mail: ParsedMail, source: MailSource): Promise<void>;
30
+ /** The connection opened its mailbox and the first scan may run. */
31
+ onOnline(): void;
32
+ /** The connection is down and a reconnect is scheduled (`Status.RECONNECT`). */
33
+ onReconnect(): void;
34
+ /** A permanent failure (credentials, mailbox) ended the reconnect loop. */
35
+ onOffline(error: unknown): void;
36
+ }
37
+ /**
38
+ * The delay before the next connection attempt.
39
+ *
40
+ * The fast budget counts consecutive failures: the first `retry.times` dials wait `retry.interval`, later ones wait
41
+ * `retry.lazy`. A successful connection resets the count, so a flap is retried fast again.
42
+ *
43
+ * @param failures - consecutive failures before this attempt.
44
+ * @param retry - the configured retry budget and delays.
45
+ * @returns the delay in milliseconds.
46
+ */
47
+ export declare function reconnectDelay(failures: number, retry: Config['retry']): number;
48
+ /**
49
+ * The inbound connection of one account.
50
+ *
51
+ * `start()` resolves once the first attempt reached a stable state: the mailbox is open and the first scan runs in
52
+ * the background, or the failure was transient and the reconnect timer took over. A permanent failure (credentials,
53
+ * mailbox) rejects instead, so a misconfiguration is visible at startup.
54
+ */
55
+ export declare class ImapTransport {
56
+ private readonly options;
57
+ private imap;
58
+ private first;
59
+ private failures;
60
+ private connected;
61
+ private stopping;
62
+ private permanent;
63
+ private reconnectTimer;
64
+ private scanning;
65
+ private rescan;
66
+ private scanPromise;
67
+ private mailListenerAttached;
68
+ constructor(options: ImapTransportOptions);
69
+ /** Create the connection (once) and wait for the first attempt's stable outcome. */
70
+ start(): Promise<void>;
71
+ /** Abort the reconnect timer, log out and wait for an in-flight scan. */
72
+ stop(): Promise<void>;
73
+ /**
74
+ * Re-fetch one message by UID for the attachment route (`undefined` when the UID no longer exists).
75
+ * @param uid - the IMAP UID to fetch.
76
+ * @returns the parsed message.
77
+ */
78
+ fetch(uid: number): Promise<ParsedMail | undefined>;
79
+ private handleReady;
80
+ private handleError;
81
+ private handleClose;
82
+ private failPermanently;
83
+ private scheduleReconnect;
84
+ private clearReconnect;
85
+ /** Register the new-mail listener once: every reconnect reuses the connection and its listeners. */
86
+ private attachMailListener;
87
+ /** Run one scan; a request during a scan sets one "run again" flag instead of starting a second scan. */
88
+ private scan;
89
+ private scanOnce;
90
+ /** Parse one fetched message, hand it to the host and acknowledge it only when the host accepted it. */
91
+ private deliverMessage;
92
+ /** Write `\\Seen`; a failure only warns, because the host deduplicates the redelivery by `Message-ID`. */
93
+ private markSeen;
94
+ }
95
+ //# sourceMappingURL=imap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imap.d.ts","sourceRoot":"","sources":["../../../src/transport/imap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG5C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,8GAA8G;AAC9G,MAAM,WAAW,SAAU,SAAQ,KAAK;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,+DAA+D;AAC/D,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;CAChC;AAED,iDAAiD;AACjD,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,UAAU,CAAA;IAClB,wGAAwG;IACxG,OAAO,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,C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G;YAC1F,cAAc;IAqC5B,0GAA0G;YAC5F,QAAQ;CAkBvB"}
@@ -0,0 +1,354 @@
1
+ /**
2
+ * IMAP inbound transport: connection lifecycle, scanning, acknowledgement and reconnection.
3
+ *
4
+ * `node-imap` owns IDLE/NOOP keepalive internally, so this transport never sends a keepalive itself. It starts one
5
+ * `Connection` and reuses it for every reconnect (the library resets its own state and keeps listeners). Every
6
+ * `\\Seen` write happens only after the host accepted the message: a crash or a failed intake therefore leaves the
7
+ * message unread, and the next scan delivers it again (the host dedupes by `Message-ID`). A malformed message is the
8
+ * one exception: it is marked seen, because retrying it would fail forever.
9
+ */
10
+ import { simpleParser } from 'mailparser';
11
+ import NodeIMAP from 'node-imap';
12
+ /**
13
+ * The delay before the next connection attempt.
14
+ *
15
+ * The fast budget counts consecutive failures: the first `retry.times` dials wait `retry.interval`, later ones wait
16
+ * `retry.lazy`. A successful connection resets the count, so a flap is retried fast again.
17
+ *
18
+ * @param failures - consecutive failures before this attempt.
19
+ * @param retry - the configured retry budget and delays.
20
+ * @returns the delay in milliseconds.
21
+ */
22
+ export function reconnectDelay(failures, retry) {
23
+ return failures < retry.times ? retry.interval : retry.lazy;
24
+ }
25
+ /** The error message of a caught value. */
26
+ function messageOf(error) {
27
+ return error instanceof Error ? error.message : String(error);
28
+ }
29
+ /**
30
+ * Read and parse one fetched message. The body stream is piped into `simpleParser` as soon as it arrives (an unread
31
+ * stream would block the parser), so the result is a promise of either the parsed message, a parse error or neither
32
+ * when the server sent no body.
33
+ */
34
+ function readMessage(message) {
35
+ let uid;
36
+ let size = 0;
37
+ let parsing;
38
+ return new Promise((resolve) => {
39
+ message.on('body', (stream, info) => {
40
+ size = info.size;
41
+ // node-imap hands over a `stream.Readable`, which its declaration file types as `NodeJS.ReadableStream`.
42
+ parsing = simpleParser(stream);
43
+ // Observed right away: the explicit await below may come later, and an unhandled rejection would end the process.
44
+ parsing.catch(() => undefined);
45
+ });
46
+ message.on('attributes', (attributes) => {
47
+ uid = attributes.uid;
48
+ });
49
+ message.on('end', () => {
50
+ const pending = parsing;
51
+ if (pending === undefined) {
52
+ resolve({ uid, size });
53
+ return;
54
+ }
55
+ pending.then((mail) => {
56
+ resolve({ uid, size, mail });
57
+ }, (error) => {
58
+ resolve({ uid, size, error });
59
+ });
60
+ });
61
+ });
62
+ }
63
+ /**
64
+ * The inbound connection of one account.
65
+ *
66
+ * `start()` resolves once the first attempt reached a stable state: the mailbox is open and the first scan runs in
67
+ * the background, or the failure was transient and the reconnect timer took over. A permanent failure (credentials,
68
+ * mailbox) rejects instead, so a misconfiguration is visible at startup.
69
+ */
70
+ export class ImapTransport {
71
+ options;
72
+ imap;
73
+ first;
74
+ failures = 0;
75
+ connected = false;
76
+ stopping = false;
77
+ permanent;
78
+ reconnectTimer;
79
+ scanning = false;
80
+ rescan = false;
81
+ scanPromise;
82
+ mailListenerAttached = false;
83
+ constructor(options) {
84
+ this.options = options;
85
+ }
86
+ /** Create the connection (once) and wait for the first attempt's stable outcome. */
87
+ async start() {
88
+ const { config } = this.options;
89
+ const imap = new NodeIMAP({
90
+ user: config.username,
91
+ password: config.password,
92
+ host: config.imap.host,
93
+ port: config.imap.port,
94
+ tls: config.imap.tls,
95
+ });
96
+ this.imap = imap;
97
+ imap.on('error', (error) => {
98
+ this.handleError(error);
99
+ });
100
+ imap.on('ready', () => {
101
+ this.handleReady();
102
+ });
103
+ imap.on('close', () => {
104
+ this.handleClose();
105
+ });
106
+ const first = new Promise((resolve, reject) => {
107
+ this.first = { resolve, reject };
108
+ });
109
+ imap.connect();
110
+ return first;
111
+ }
112
+ /** Abort the reconnect timer, log out and wait for an in-flight scan. */
113
+ async stop() {
114
+ this.stopping = true;
115
+ this.clearReconnect();
116
+ const imap = this.imap;
117
+ this.imap = undefined;
118
+ if (imap !== undefined)
119
+ imap.end();
120
+ await this.scanPromise?.catch(() => undefined);
121
+ }
122
+ /**
123
+ * Re-fetch one message by UID for the attachment route (`undefined` when the UID no longer exists).
124
+ * @param uid - the IMAP UID to fetch.
125
+ * @returns the parsed message.
126
+ */
127
+ async fetch(uid) {
128
+ const imap = this.imap;
129
+ if (imap === undefined)
130
+ throw new Error('mail: the IMAP connection is not open');
131
+ const fetched = imap.fetch(uid, { bodies: '' });
132
+ const results = [];
133
+ const tasks = [];
134
+ await new Promise((resolve, reject) => {
135
+ fetched.on('message', (message) => {
136
+ tasks.push(readMessage(message).then((result) => {
137
+ results.push(result);
138
+ }));
139
+ });
140
+ fetched.on('end', () => {
141
+ resolve();
142
+ });
143
+ fetched.on('error', reject);
144
+ });
145
+ await Promise.all(tasks);
146
+ const [result] = results;
147
+ if (result === undefined)
148
+ return undefined;
149
+ if (result.error !== undefined)
150
+ throw result.error;
151
+ return result.mail;
152
+ }
153
+ handleReady() {
154
+ if (this.stopping)
155
+ return;
156
+ const imap = this.imap;
157
+ if (imap === undefined)
158
+ return;
159
+ imap.openBox(this.options.config.mailbox, false, (error) => {
160
+ if (this.stopping)
161
+ return;
162
+ if (error) {
163
+ this.options.logger.error('mail: the mailbox %s could not be opened: %s', this.options.config.mailbox, messageOf(error));
164
+ this.failPermanently(error);
165
+ return;
166
+ }
167
+ this.failures = 0;
168
+ this.connected = true;
169
+ this.options.onOnline();
170
+ this.first?.resolve();
171
+ this.first = undefined;
172
+ this.attachMailListener();
173
+ void this.scan();
174
+ });
175
+ }
176
+ handleError(error) {
177
+ if (this.stopping)
178
+ return;
179
+ if (error.source === 'authentication') {
180
+ this.options.logger.error('mail: IMAP authentication failed: %s', messageOf(error));
181
+ this.failPermanently(error);
182
+ return;
183
+ }
184
+ this.options.logger.warn('mail: IMAP error (%s): %s', error.source ?? 'unknown', messageOf(error));
185
+ // A transient first failure lets startup continue with the reconnect timer instead of failing the whole profile.
186
+ this.first?.resolve();
187
+ this.first = undefined;
188
+ }
189
+ handleClose() {
190
+ if (this.stopping)
191
+ return;
192
+ this.connected = false;
193
+ if (this.permanent !== undefined)
194
+ return;
195
+ // A close during the first attempt is transient too: the reconnect loop takes over.
196
+ this.first?.resolve();
197
+ this.first = undefined;
198
+ this.options.onReconnect();
199
+ this.scheduleReconnect();
200
+ }
201
+ failPermanently(error) {
202
+ this.permanent = error;
203
+ this.connected = false;
204
+ this.clearReconnect();
205
+ this.first?.reject(error);
206
+ this.first = undefined;
207
+ this.options.onOffline(error);
208
+ }
209
+ scheduleReconnect() {
210
+ if (this.stopping ||
211
+ this.permanent !== undefined ||
212
+ this.reconnectTimer !== undefined ||
213
+ this.connected)
214
+ return;
215
+ const delay = reconnectDelay(this.failures, this.options.config.retry);
216
+ this.failures += 1;
217
+ this.reconnectTimer = setTimeout(() => {
218
+ this.reconnectTimer = undefined;
219
+ if (this.stopping || this.permanent !== undefined)
220
+ return;
221
+ this.imap?.connect();
222
+ }, delay);
223
+ }
224
+ clearReconnect() {
225
+ if (this.reconnectTimer === undefined)
226
+ return;
227
+ clearTimeout(this.reconnectTimer);
228
+ this.reconnectTimer = undefined;
229
+ }
230
+ /** Register the new-mail listener once: every reconnect reuses the connection and its listeners. */
231
+ attachMailListener() {
232
+ const imap = this.imap;
233
+ if (this.mailListenerAttached || imap === undefined)
234
+ return;
235
+ this.mailListenerAttached = true;
236
+ imap.on('mail', () => {
237
+ void this.scan();
238
+ });
239
+ }
240
+ /** Run one scan; a request during a scan sets one "run again" flag instead of starting a second scan. */
241
+ scan() {
242
+ if (this.scanning) {
243
+ this.rescan = true;
244
+ return Promise.resolve();
245
+ }
246
+ this.scanning = true;
247
+ const run = (async () => {
248
+ try {
249
+ do {
250
+ this.rescan = false;
251
+ await this.scanOnce();
252
+ } while (this.rescan && !this.stopping && this.connected);
253
+ }
254
+ catch (error) {
255
+ // A failed scan never ends the connection loop: the next mail event or reconnect scans again.
256
+ this.options.logger.error('mail: the scan failed: %s', messageOf(error));
257
+ }
258
+ finally {
259
+ this.scanning = false;
260
+ }
261
+ })();
262
+ this.scanPromise = run;
263
+ return run;
264
+ }
265
+ async scanOnce() {
266
+ const imap = this.imap;
267
+ if (imap === undefined)
268
+ return;
269
+ const uids = await new Promise((resolve, reject) => {
270
+ imap.search(['UNSEEN'], (error, result) => {
271
+ if (error)
272
+ reject(error);
273
+ else
274
+ resolve(result ?? []);
275
+ });
276
+ });
277
+ if (uids.length === 0)
278
+ return;
279
+ const fetched = imap.fetch(uids, { bodies: '' });
280
+ const tasks = [];
281
+ await new Promise((resolve) => {
282
+ let settled = false;
283
+ const done = () => {
284
+ if (settled)
285
+ return;
286
+ settled = true;
287
+ resolve();
288
+ };
289
+ fetched.on('message', (message) => {
290
+ tasks.push(this.deliverMessage(message));
291
+ });
292
+ fetched.on('end', done);
293
+ fetched.on('error', (error) => {
294
+ this.options.logger.error('mail: fetching the message bodies failed: %s', messageOf(error));
295
+ done();
296
+ });
297
+ });
298
+ await Promise.all(tasks);
299
+ }
300
+ /** Parse one fetched message, hand it to the host and acknowledge it only when the host accepted it. */
301
+ async deliverMessage(message) {
302
+ const result = await readMessage(message);
303
+ if (result.mail === undefined) {
304
+ // A malformed message can never be parsed: marking it seen is the only way out of the retry loop.
305
+ if (result.error !== undefined) {
306
+ this.options.logger.error('mail: the message could not be parsed: %s', messageOf(result.error));
307
+ }
308
+ else {
309
+ this.options.logger.error('mail: a fetched message carried no body');
310
+ }
311
+ if (result.uid !== undefined)
312
+ await this.markSeen(result.uid);
313
+ return;
314
+ }
315
+ if (result.uid === undefined) {
316
+ // Without the UID there is nothing to acknowledge; the host still receives the message.
317
+ this.options.logger.error('mail: a fetched message carried no UID');
318
+ return;
319
+ }
320
+ try {
321
+ await this.options.deliver(result.mail, {
322
+ uid: result.uid,
323
+ mailbox: this.options.config.mailbox,
324
+ size: result.size,
325
+ });
326
+ }
327
+ catch (error) {
328
+ // Not accepted: leave it unseen so the next scan retries it.
329
+ this.options.logger.error('mail: the host did not accept a message, it stays unseen: %s', messageOf(error));
330
+ return;
331
+ }
332
+ await this.markSeen(result.uid);
333
+ }
334
+ /** Write `\\Seen`; a failure only warns, because the host deduplicates the redelivery by `Message-ID`. */
335
+ async markSeen(uid) {
336
+ const imap = this.imap;
337
+ if (imap === undefined)
338
+ return;
339
+ try {
340
+ await new Promise((resolve, reject) => {
341
+ imap.setFlags(uid, ['\\SEEN'], (error) => {
342
+ if (error)
343
+ reject(error);
344
+ else
345
+ resolve();
346
+ });
347
+ });
348
+ }
349
+ catch (error) {
350
+ this.options.logger.warn('mail: the message %d could not be marked as seen: %s', uid, messageOf(error));
351
+ }
352
+ }
353
+ }
354
+ //# sourceMappingURL=imap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imap.js","sourceRoot":"","sources":["../../../src/transport/imap.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,QAAQ,MAAM,WAAW,CAAA;AAwChC;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,QAAgB,EAChB,KAAsB;IAEtB,OAAO,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAA;AAC7D,CAAC;AAED,2CAA2C;AAC3C,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,OAA6B;IAChD,IAAI,GAAuB,CAAA;IAC3B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,IAAI,OAAwC,CAAA;IAC5C,OAAO,IAAI,OAAO,CAAa,CAAC,OAAO,EAAE,EAAE;QACzC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;YAClC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;YAChB,yGAAyG;YACzG,OAAO,GAAG,YAAY,CAAC,MAAkB,C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AAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@im-more/dsh-mail",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Mail adapter for official dsh-im of DeepSeek Harness",
5
+ "homepage": "https://github.com/ilharp/dsh-im-more",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/ilharp/dsh-im-more.git",
9
+ "directory": "packages/mail"
10
+ },
11
+ "author": {
12
+ "name": "Il Harper",
13
+ "email": "hi@ilharper.com",
14
+ "url": "https://ilharper.com"
15
+ },
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "main": "lib/index.js",
19
+ "types": "lib/types/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./lib/types/index.d.ts",
23
+ "default": "./lib/index.js"
24
+ },
25
+ "./package.json": "./package.json",
26
+ "./cordis.patch.yml": "./cordis.patch.yml"
27
+ },
28
+ "files": [
29
+ "lib",
30
+ "src",
31
+ "cordis.patch.yml"
32
+ ],
33
+ "engines": {
34
+ "dsh": ">=0.2.3-alpha.3"
35
+ },
36
+ "peerDependencies": {
37
+ "@deepseek-ai/cordis": ">=4.2.0-alpha.2",
38
+ "@deepseek-ai/cordis-plugin-http": ">=1.6.1-alpha.2",
39
+ "@deepseek-ai/cordis-plugin-im-core": ">=5.0.1-alpha.2",
40
+ "@deepseek-ai/satori-element": ">=4.0.1-alpha.2",
41
+ "@deepseek-ai/schemastery": ">=3.20.0-alpha.2"
42
+ },
43
+ "dependencies": {
44
+ "html5parser": "^2.0.2",
45
+ "mailparser": "^3.9.3",
46
+ "node-imap": "^0.9.6",
47
+ "nodemailer": "^6.10.1"
48
+ },
49
+ "devDependencies": {
50
+ "@deepseek-ai/cordis": ">=4.2.0-alpha.2",
51
+ "@deepseek-ai/cordis-plugin-http": ">=1.6.1-alpha.2",
52
+ "@deepseek-ai/cordis-plugin-im-core": ">=5.0.1-alpha.2",
53
+ "@deepseek-ai/satori-element": ">=4.0.1-alpha.2",
54
+ "@deepseek-ai/schemastery": ">=3.20.0-alpha.2",
55
+ "@types/node": "^22.20.1",
56
+ "tsdown": "^0.22.2",
57
+ "typescript": "^6.0.3",
58
+ "vitest": "^4.1.11",
59
+ "@types/node-imap": "^0.9.3",
60
+ "@types/nodemailer": "^6.4.23",
61
+ "@types/mailparser": "^3.4.6"
62
+ },
63
+ "dsh": {
64
+ "bundle": {
65
+ "patch": "./cordis.patch.yml"
66
+ }
67
+ },
68
+ "scripts": {
69
+ "build": "tsc -p tsconfig.json && tsdown",
70
+ "typecheck": "tsc -p tsconfig.test.json",
71
+ "test": "vitest run"
72
+ }
6
73
  }