react-native-email-imap-smtp 0.3.33 → 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())
|
package/package.json
CHANGED