react-native-email-imap-smtp 0.3.20 → 0.3.21

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.
@@ -6,94 +6,188 @@
6
6
  import type { HybridObject } from 'react-native-nitro-modules';
7
7
 
8
8
  // ─── Shared Types ─────────────────────────────────────────
9
-
9
+ //
10
+ // 注意:本文件的类型是「原生层」结构,通过 JSON 序列化与 JS 层通信,
11
+ // 与 src/types.ts 中的公共类型语义一一对应(但字段更底层)。
12
+ // 修改时请保持与 src/types.ts 同步。
13
+
14
+ /**
15
+ * 邮件地址(发件人 / 收件人等)。
16
+ */
10
17
  export interface EmailAddress {
18
+ /** 显示名称 */
11
19
  name: string;
20
+ /** 邮箱地址 */
12
21
  email: string;
13
22
  }
14
23
 
24
+ /**
25
+ * IMAP 服务器连接配置(原生层)。
26
+ */
15
27
  export interface ConnectionConfig {
28
+ /** 服务器主机名或 IP */
16
29
  host: string;
30
+ /** 服务器端口 */
17
31
  port: number;
32
+ /** 登录用户名 */
18
33
  username: string;
34
+ /** 登录密码 */
19
35
  password: string;
36
+ /** 是否使用 SSL/TLS */
20
37
  tls: boolean;
38
+ /** 认证方式:`password` / `oauth2` / `none` */
21
39
  authType: string;
40
+ /** OAuth2 访问令牌 */
22
41
  accessToken?: string;
42
+ /** 连接超时(毫秒) */
23
43
  timeout: number;
44
+ /** 是否校验服务器证书 */
24
45
  checkCertificate: boolean;
46
+ /** 是否输出调试日志 */
25
47
  debug: boolean;
26
48
  }
27
49
 
50
+ /**
51
+ * SMTP 服务器连接配置(原生层)。
52
+ */
28
53
  export interface SmtpConnectionConfig {
54
+ /** 服务器主机名或 IP */
29
55
  host: string;
56
+ /** 服务器端口 */
30
57
  port: number;
58
+ /** 登录用户名 */
31
59
  username: string;
60
+ /** 登录密码 */
32
61
  password: string;
62
+ /** 是否使用 SSL/TLS */
33
63
  tls: boolean;
64
+ /** 认证方式:`password` / `oauth2` / `none` */
34
65
  authType: string;
66
+ /** OAuth2 访问令牌 */
35
67
  accessToken?: string;
68
+ /** 连接超时(毫秒) */
36
69
  timeout: number;
70
+ /** 是否校验服务器证书 */
37
71
  checkCertificate: boolean;
72
+ /** EHLO 问候主机名 */
38
73
  helloName?: string;
74
+ /** 是否输出调试日志 */
39
75
  debug: boolean;
40
76
  }
41
77
 
78
+ /**
79
+ * IMAP 服务器信息(连接成功后)。
80
+ */
42
81
  export interface ImapServerInfo {
82
+ /** 服务器标识名 */
43
83
  serverName: string;
84
+ /** 支持的 IMAP 能力列表 */
44
85
  capabilities: string[];
86
+ /** 是否启用压缩 */
45
87
  isCompressed: boolean;
46
88
  }
47
89
 
90
+ /**
91
+ * SMTP 服务器信息(连接成功后)。
92
+ */
48
93
  export interface SmtpServerInfo {
94
+ /** 服务器标识名 */
49
95
  serverName: string;
96
+ /** 支持的 SMTP 扩展能力列表 */
50
97
  capabilities: string[];
98
+ /** 支持的认证方法列表 */
51
99
  supportedAuthMethods: string[];
52
100
  }
53
101
 
102
+ /**
103
+ * 连接结果(IMAP / SMTP 通用)。
104
+ */
54
105
  export interface ConnectionResult {
106
+ /** 连接是否成功 */
55
107
  success: boolean;
108
+ /** 服务器信息(失败时为空) */
56
109
  serverInfo?: ImapServerInfo | SmtpServerInfo;
110
+ /** 失败时的错误信息 */
57
111
  error?: string;
58
112
  }
59
113
 
114
+ /**
115
+ * 邮箱列表项(IMAP mailbox)。
116
+ */
60
117
  export interface MailboxListItem {
118
+ /** 邮箱名称 */
61
119
  name: string;
120
+ /** 邮箱完整路径 */
62
121
  path: string;
122
+ /** 路径分隔符 */
63
123
  delimiter: string;
124
+ /** 属性标记 */
64
125
  flags: string[];
126
+ /** 是否已订阅 */
65
127
  subscribed: boolean;
66
128
  }
67
129
 
130
+ /**
131
+ * 邮箱状态信息(原生层)。
132
+ */
68
133
  export interface MailboxInfo {
134
+ /** 邮箱名称 */
69
135
  name: string;
136
+ /** 邮箱完整路径 */
70
137
  path: string;
138
+ /** 下一个可用的 UID */
71
139
  uidNext: number;
140
+ /** UID 有效性标识 */
72
141
  uidValidity: number;
142
+ /** 邮件总数 */
73
143
  messageCount: number;
144
+ /** 新邮件(\Recent)数 */
74
145
  recentCount: number;
146
+ /** 未读邮件数 */
75
147
  unseenCount: number;
148
+ /** 第一封未读邮件的 UID */
76
149
  firstUnseenUid: number;
150
+ /** 最新修改序号 MODSEQ */
77
151
  highestModSeq: number;
152
+ /** 支持的标记列表 */
78
153
  flags: string[];
154
+ /** 可持久化的标记列表 */
79
155
  permanentFlags: string[];
80
156
  }
81
157
 
158
+ /**
159
+ * 文件夹信息(原生层)。
160
+ */
82
161
  export interface FolderInfo {
162
+ /** 文件夹名称 */
83
163
  name: string;
164
+ /** 完整路径 */
84
165
  path: string;
166
+ /** 路径分隔符 */
85
167
  delimiter: string;
168
+ /** 父文件夹路径 */
86
169
  parent: string;
170
+ /** 直接子文件夹路径列表 */
87
171
  children: string[];
172
+ /** 属性标记 */
88
173
  flags: string[];
174
+ /** 是否已订阅 */
89
175
  subscribed: boolean;
176
+ /** 邮件总数 */
90
177
  messageCount: number;
178
+ /** 未读邮件数 */
91
179
  unseenCount: number;
92
180
  }
93
181
 
182
+ /**
183
+ * 邮件正文(原生层)。
184
+ */
94
185
  export interface EmailBody {
186
+ /** 纯文本正文 */
95
187
  text: string;
188
+ /** HTML 正文 */
96
189
  html: string;
190
+ /** 内嵌资源的附件对象 ID 列表 */
97
191
  embeddedAttachments: string[];
98
192
  }
99
193
 
@@ -122,25 +216,47 @@ export interface EmailMessage {
122
216
  charset: string;
123
217
  }
124
218
 
219
+ /**
220
+ * `imapFetchEmails` 的查询选项(原生层,与 src/types.ts 的 FetchEmailsOptions 对应)。
221
+ */
125
222
  export interface FetchEmailsOptions {
223
+ /** 范围起始 */
126
224
  from?: number;
225
+ /** 范围结束 */
127
226
  to?: number;
227
+ /** `uid` 按 UID,`sequence` 按序号 */
128
228
  rangeType?: string;
229
+ /** 页码(从最新往旧翻) */
129
230
  page?: number;
231
+ /** 每页数量 */
130
232
  pageSize?: number;
233
+ /** 只取晚于该时间的邮件(ISO 8601) */
131
234
  since?: string;
235
+ /** 只取早于该时间的邮件(ISO 8601) */
132
236
  before?: string;
237
+ /** 目标邮箱路径,默认 INBOX */
133
238
  mailbox?: string;
239
+ /** 是否下载正文 */
134
240
  fetchBody: boolean;
241
+ /** 是否下载附件 */
135
242
  fetchAttachments: boolean;
243
+ /** 是否返回标记 */
136
244
  fetchFlags: boolean;
245
+ /** 是否返回头字段 */
137
246
  fetchHeaders: boolean;
247
+ /** 是否返回完整原始内容 */
138
248
  fetchFullContent: boolean;
249
+ /** 正文大小上限(字节) */
139
250
  maxBodySize: number;
140
251
  }
141
252
 
253
+ /**
254
+ * 按自定义头字段搜索。
255
+ */
142
256
  export interface SearchHeader {
257
+ /** 头字段名,如 `X-Tag` */
143
258
  key: string;
259
+ /** 期望值 */
144
260
  value: string;
145
261
  }
146
262
 
@@ -177,86 +293,167 @@ export interface SearchCriteria {
177
293
  maxBodySize: number;
178
294
  }
179
295
 
296
+ /**
297
+ * 批量操作结果(原生层)。
298
+ */
180
299
  export interface DeleteResult {
300
+ /** 成功的 UID 列表 */
181
301
  success: number[];
302
+ /** 失败的 UID 列表 */
182
303
  failed: number[];
304
+ /** 失败时的错误信息 */
183
305
  error?: string;
184
306
  }
185
307
 
308
+ /**
309
+ * 邮件附件(原生层)。
310
+ */
186
311
  export interface AttachmentInfo {
312
+ /** 附件文件名 */
187
313
  filename: string;
314
+ /** MIME 类型 */
188
315
  mimeType: string;
316
+ /** 在邮件体中的部分 ID */
189
317
  partId: string;
318
+ /** 大小(字节) */
190
319
  size: number;
320
+ /** 二进制内容 */
191
321
  data: ArrayBuffer;
322
+ /** 内嵌资源 content-id */
192
323
  contentId?: string;
324
+ /** 是否内嵌显示 */
193
325
  isInline: boolean;
326
+ /** 字符集 */
194
327
  charset?: string;
328
+ /** MIME 内容处置 */
195
329
  contentDisposition: string;
196
- /** 附件缓存在本地的文件路径(如果有),避免大附件全部加载到内存 */
330
+ /** 本地缓存路径(大附件) */
197
331
  localPath?: string;
198
332
  }
199
333
 
334
+ /**
335
+ * IDLE 实时通知(原生层)。
336
+ */
200
337
  export interface IdleNotification {
338
+ /** 通知类型:newMessage / messageDeleted / messageFlagged / mailboxChanged / connectionLost */
201
339
  type: string;
340
+ /** 发生变化的邮箱路径 */
202
341
  mailbox: string;
342
+ /** 涉及邮件的 UID */
203
343
  uid?: number;
344
+ /** 涉及的新标记名 */
204
345
  flag?: string;
346
+ /** 变化后的邮件总数 */
205
347
  messageCount?: number;
348
+ /** 通知时间戳(毫秒) */
206
349
  timestamp: number;
207
350
  }
208
351
 
352
+ /**
353
+ * 配额信息(原生层)。
354
+ */
209
355
  export interface QuotaInfo {
356
+ /** 已用存储(字节) */
210
357
  storageUsed: number;
358
+ /** 存储上限(字节) */
211
359
  storageLimit: number;
360
+ /** 存储单位 */
212
361
  storageUnit: string;
362
+ /** 已用邮件数 */
213
363
  messagesUsed?: number;
364
+ /** 邮件数上限 */
214
365
  messagesLimit?: number;
366
+ /** 配额根名称 */
215
367
  root: string;
216
368
  }
217
369
 
370
+ /**
371
+ * 追加邮件结果(原生层)。
372
+ */
218
373
  export interface AppendResult {
374
+ /** 新邮件 UID */
219
375
  uid: number;
376
+ /** uidValidity */
220
377
  uidValidity: number;
378
+ /** 追加时间(ISO 8601) */
221
379
  date: string;
222
380
  }
223
381
 
382
+ /**
383
+ * 发送邮件附件(原生层)。
384
+ */
224
385
  export interface SmtpAttachment {
386
+ /** 附件文件名 */
225
387
  filename: string;
388
+ /** MIME 类型 */
226
389
  mimeType: string;
390
+ /** 二进制内容 */
227
391
  data: ArrayBuffer;
392
+ /** 是否内嵌显示 */
228
393
  isInline: boolean;
394
+ /** 内嵌资源 content-id */
229
395
  contentId?: string;
396
+ /** 内容处置:attachment / inline */
230
397
  disposition?: string;
231
398
  }
232
399
 
400
+ /**
401
+ * 发信选项(原生层,与 src/types.ts 的 SendMailOptions 对应)。
402
+ */
233
403
  export interface SendMailOptions {
404
+ /** 发件人 */
234
405
  from: EmailAddress;
406
+ /** 收件人列表 */
235
407
  to: EmailAddress[];
408
+ /** 抄送列表 */
236
409
  cc?: EmailAddress[];
410
+ /** 密送列表 */
237
411
  bcc?: EmailAddress[];
412
+ /** 回复地址列表 */
238
413
  replyTo?: EmailAddress[];
414
+ /** 主题 */
239
415
  subject: string;
416
+ /** 纯文本正文 */
240
417
  textBody?: string;
418
+ /** HTML 正文 */
241
419
  htmlBody?: string;
420
+ /** 附件列表 */
242
421
  attachments?: SmtpAttachment[];
422
+ /** 优先级:low / normal / high */
243
423
  priority?: string;
424
+ /** 自定义头字段 */
244
425
  headers?: Record<string, string>;
426
+ /** 回复的父邮件 Message-ID */
245
427
  inReplyTo?: string;
428
+ /** 引用链 */
246
429
  references?: string;
430
+ /** 阅读回执收件人 */
247
431
  readReceiptTo?: EmailAddress;
432
+ /** 字符集 */
248
433
  charset?: string;
434
+ /** 传输编码 */
249
435
  encoding?: string;
250
436
  }
251
437
 
438
+ /**
439
+ * 发信结果(原生层)。
440
+ */
252
441
  export interface SendMailResult {
442
+ /** 是否成功 */
253
443
  success: boolean;
444
+ /** 服务器生成的 Message-ID */
254
445
  messageId?: string;
446
+ /** 发送时间(ISO 8601) */
255
447
  date?: string;
448
+ /** 服务器响应码 */
256
449
  serverResponseCode?: number;
450
+ /** 原始 MIME 数据 */
257
451
  rawMimeData?: ArrayBuffer;
452
+ /** 队列 ID */
258
453
  queueId?: string;
454
+ /** 错误信息 */
259
455
  error?: string;
456
+ /** 是否可重试 */
260
457
  retryable?: boolean;
261
458
  }
262
459
 
@@ -264,59 +461,185 @@ export interface SendMailResult {
264
461
  // HybridObject Interface
265
462
  // ═══════════════════════════════════════════════════════════
266
463
 
464
+ /**
465
+ * 原生(Android / iOS)IMAP + SMTP 混合对象。
466
+ * 通过 NitroModules 暴露给 JS 层;Web / Windows 不经过此接口。
467
+ * 方法语义与公共 API(scripts/index.d.ts.template)一致。
468
+ */
267
469
  export interface EmailImapSmtp extends HybridObject<{
268
470
  ios: 'swift';
269
471
  android: 'kotlin';
270
472
  }> {
271
473
  // ─── Connection ─────────────────────────────────────────
474
+
475
+ /**
476
+ * 建立 IMAP 连接。
477
+ * @param config 服务器连接配置
478
+ */
272
479
  imapConnect(config: ConnectionConfig): Promise<ConnectionResult>;
480
+
481
+ /** 断开 IMAP 连接。 */
273
482
  imapDisconnect(): Promise<void>;
274
483
 
275
484
  // ─── Mailbox ────────────────────────────────────────────
485
+
486
+ /** 列出所有邮箱。 */
276
487
  imapListMailboxes(): Promise<MailboxListItem[]>;
488
+
489
+ /**
490
+ * 选择(打开)邮箱。
491
+ * @param mailbox 邮箱完整路径
492
+ * @param readOnly 是否只读打开
493
+ */
277
494
  imapSelectMailbox(mailbox: string, readOnly: boolean): Promise<MailboxInfo>;
495
+
496
+ /** 刷新当前邮箱状态。 */
278
497
  imapRefreshMailbox(): Promise<MailboxInfo>;
279
498
 
280
499
  // ─── Folders ────────────────────────────────────────────
500
+
501
+ /** 获取文件夹树。 */
281
502
  imapFetchFolders(): Promise<FolderInfo[]>;
503
+
504
+ /**
505
+ * 创建文件夹。
506
+ * @param folderName 新文件夹完整路径
507
+ */
282
508
  imapCreateFolder(folderName: string): Promise<void>;
509
+
510
+ /**
511
+ * 删除文件夹。
512
+ * @param folderName 待删除文件夹完整路径
513
+ */
283
514
  imapDeleteFolder(folderName: string): Promise<void>;
515
+
516
+ /**
517
+ * 重命名文件夹。
518
+ * @param oldName 原路径
519
+ * @param newName 新路径
520
+ */
284
521
  imapRenameFolder(oldName: string, newName: string): Promise<void>;
522
+
523
+ /**
524
+ * 订阅文件夹。
525
+ * @param folderName 文件夹完整路径
526
+ */
285
527
  imapSubscribeFolder(folderName: string): Promise<void>;
528
+
529
+ /**
530
+ * 取消订阅文件夹。
531
+ * @param folderName 文件夹完整路径
532
+ */
286
533
  imapUnsubscribeFolder(folderName: string): Promise<void>;
287
534
 
288
535
  // ─── Fetch Emails ────────────────────────────────────────
536
+
537
+ /**
538
+ * 拉取邮件列表。
539
+ * @param options 查询条件
540
+ */
289
541
  imapFetchEmails(options: FetchEmailsOptions): Promise<EmailMessage[]>;
542
+
543
+ /**
544
+ * 按 UID 获取单封邮件。
545
+ * @param uid 邮件 UID
546
+ */
290
547
  imapFetchEmailByUID(uid: number): Promise<EmailMessage | null>;
291
548
 
292
549
  // ─── Search ─────────────────────────────────────────────
550
+
551
+ /**
552
+ * 搜索邮件。
553
+ * @param criteria 搜索条件
554
+ */
293
555
  imapSearchEmails(criteria: SearchCriteria): Promise<EmailMessage[]>;
294
556
 
295
557
  // ─── Flags ──────────────────────────────────────────────
558
+
559
+ /**
560
+ * 标记为已读。
561
+ * @param uids 目标 UID 列表
562
+ * @param silent 是否静默
563
+ */
296
564
  imapMarkAsRead(uids: number[], silent: boolean): Promise<void>;
565
+
566
+ /**
567
+ * 添加 / 移除星标。
568
+ * @param uids 目标 UID 列表
569
+ * @param flagged true 加星标,false 取消
570
+ */
297
571
  imapMarkAsFlagged(uids: number[], flagged: boolean): Promise<void>;
298
572
 
299
573
  // ─── Move / Copy / Delete ───────────────────────────────
574
+
575
+ /**
576
+ * 移动邮件。
577
+ * @param uids 目标 UID 列表
578
+ * @param destinationMailbox 目标文件夹路径
579
+ */
300
580
  imapMoveEmails(uids: number[], destinationMailbox: string): Promise<void>;
581
+
582
+ /**
583
+ * 复制邮件。
584
+ * @param uids 目标 UID 列表
585
+ * @param destinationMailbox 目标文件夹路径
586
+ */
301
587
  imapCopyEmails(uids: number[], destinationMailbox: string): Promise<void>;
588
+
589
+ /**
590
+ * 删除邮件。
591
+ * @param uids 目标 UID 列表
592
+ */
302
593
  imapDeleteEmails(uids: number[]): Promise<DeleteResult>;
594
+
595
+ /** 永久清除标记为删除的邮件。 */
303
596
  imapExpunge(): Promise<void>;
304
597
 
305
598
  // ─── Attachments ───────────────────────────────────────
599
+
600
+ /**
601
+ * 获取单个附件。
602
+ * @param uid 所属邮件 UID
603
+ * @param partId 附件部分 ID
604
+ */
306
605
  imapFetchAttachments(
307
606
  uid: number,
308
607
  partId: string
309
608
  ): Promise<AttachmentInfo | null>;
609
+
610
+ /**
611
+ * 获取一封邮件的全部附件。
612
+ * @param uid 邮件 UID
613
+ */
310
614
  imapFetchAllAttachments(uid: number): Promise<AttachmentInfo[]>;
311
615
 
312
616
  // ─── IDLE ──────────────────────────────────────────────
617
+
618
+ /**
619
+ * 开启 IDLE 实时监听。
620
+ * @param callback 新通知回调
621
+ */
313
622
  imapIdle(callback: (notification: IdleNotification) => void): Promise<void>;
623
+
624
+ /** 停止 IDLE 监听。 */
314
625
  imapStopIdle(): Promise<void>;
315
626
 
316
627
  // ─── Quota ──────────────────────────────────────────────
628
+
629
+ /**
630
+ * 查询配额。
631
+ * @param root 配额根名称
632
+ */
317
633
  imapGetQuota(root?: string): Promise<QuotaInfo>;
318
634
 
319
635
  // ─── Append ────────────────────────────────────────────
636
+
637
+ /**
638
+ * 追加原始 MIME 邮件。
639
+ * @param mailbox 目标文件夹路径
640
+ * @param rawMimeData 原始 MIME 内容
641
+ * @param flags 附加标记
642
+ */
320
643
  imapAppendMessage(
321
644
  mailbox: string,
322
645
  rawMimeData: ArrayBuffer,
@@ -326,8 +649,22 @@ export interface EmailImapSmtp extends HybridObject<{
326
649
  // ═══════════════════════════════════════════════════════
327
650
  // SMTP
328
651
  // ═══════════════════════════════════════════════════════
652
+
653
+ /**
654
+ * 建立 SMTP 连接。
655
+ * @param config 服务器连接配置
656
+ */
329
657
  smtpConnect(config: SmtpConnectionConfig): Promise<ConnectionResult>;
658
+
659
+ /** 断开 SMTP 连接。 */
330
660
  smtpDisconnect(): Promise<void>;
661
+
662
+ /**
663
+ * 发送邮件。
664
+ * @param options 发信选项
665
+ */
331
666
  smtpSendMail(options: SendMailOptions): Promise<SendMailResult>;
667
+
668
+ /** 验证 SMTP 连接是否可用。 */
332
669
  smtpVerifyConnection(): Promise<boolean>;
333
670
  }