react-native-email-imap-smtp 0.3.32 → 0.3.34

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.
@@ -13,6 +13,8 @@ import jakarta.mail.search.*
13
13
  import java.io.ByteArrayOutputStream
14
14
  import java.io.File
15
15
  import java.io.FileOutputStream
16
+ import java.net.Inet4Address
17
+ import java.net.InetAddress
16
18
  import java.security.cert.X509Certificate
17
19
  import java.time.ZoneId
18
20
  import java.time.ZonedDateTime
@@ -67,9 +69,24 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
67
69
  ctx.socketFactory
68
70
  }
69
71
 
72
+ /** 解析 host 为「优先 IPv4」的地址:
73
+ * - 默认走 IPv4,避免 JavaMail 优先选 IPv6 导致模拟器等无 IPv6 出站路由的环境连接超时;
74
+ * - 若域名无 IPv4(纯 IPv6-only 网络),回退用第一个地址(可能是 IPv6),保证仍可连接。
75
+ * 解析失败则回退原 host。 */
76
+ private fun resolveIpv4(host: String): String {
77
+ return try {
78
+ val addrs = InetAddress.getAllByName(host)
79
+ addrs.firstOrNull { it is Inet4Address }?.hostAddress
80
+ ?: addrs.firstOrNull()?.hostAddress
81
+ ?: host
82
+ } catch (_: Exception) {
83
+ host
84
+ }
85
+ }
86
+
70
87
  private fun imapSession(config: ConnectionConfig): Session {
71
88
  val props = Properties().apply {
72
- put("mail.imap.host", config.host)
89
+ put("mail.imap.host", resolveIpv4(config.host))
73
90
  put("mail.imap.port", config.port.toInt().toString())
74
91
  put("mail.imap.connectiontimeout", config.timeout.toInt().toString())
75
92
  put("mail.imap.timeout", config.timeout.toInt().toString())
@@ -104,7 +121,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
104
121
 
105
122
  private fun smtpSession(config: SmtpConnectionConfig): Session {
106
123
  val props = Properties().apply {
107
- put("mail.smtp.host", config.host)
124
+ put("mail.smtp.host", resolveIpv4(config.host))
108
125
  put("mail.smtp.port", config.port.toInt().toString())
109
126
  put("mail.smtp.auth", "true")
110
127
  put("mail.smtp.connectiontimeout", config.timeout.toInt().toString())
@@ -348,7 +365,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
348
365
  // fullData=false(列表阶段):只取元数据,不读附件内容,避免列表下载全部附件
349
366
  val info =
350
367
  if (fullData) readAttachmentData(part as BodyPart, fileName, contentId, isInline, disp)
351
- else readAttachmentMeta(part, fileName, contentId, isInline, disp)
368
+ else readAttachmentMeta(part as BodyPart, fileName, contentId, isInline, disp)
352
369
  if (isInline && contentId != null) {
353
370
  onEmbedded(fileName)
354
371
  }
@@ -1038,7 +1055,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
1038
1055
  return Promise.async {
1039
1056
  val folder = ensureFolderOpen()
1040
1057
  // 批量:解析目标邮件(本地代理,不触发网络)后一次 STORE 设置 SEEN
1041
- val msgs = uids.mapNotNull { uid ->
1058
+ val msgs = uids.toList().mapNotNull { uid ->
1042
1059
  try { folder.getMessageByUID(uid.toLong()) } catch (_: Exception) { null }
1043
1060
  }
1044
1061
  if (msgs.isEmpty()) return@async
@@ -1055,7 +1072,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
1055
1072
  override fun imapMarkAsFlagged(uids: DoubleArray, flagged: Boolean): Promise<Unit> {
1056
1073
  return Promise.async {
1057
1074
  val folder = ensureFolderOpen()
1058
- val msgs = uids.mapNotNull { uid ->
1075
+ val msgs = uids.toList().mapNotNull { uid ->
1059
1076
  try { folder.getMessageByUID(uid.toLong()) } catch (_: Exception) { null }
1060
1077
  }
1061
1078
  if (msgs.isEmpty()) return@async
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-email-imap-smtp",
3
- "version": "0.3.32",
3
+ "version": "0.3.34",
4
4
  "description": "The best of imap and smtp client of react native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",