react-native-email-imap-smtp 0.3.34 → 0.3.35
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.
|
@@ -252,7 +252,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
252
252
|
|
|
253
253
|
// ─── 邮件解析 ─────────────────────────────────────────────
|
|
254
254
|
|
|
255
|
-
private fun emailToEmailMessage(msg: Message, folder: IMAPFolder): EmailMessage {
|
|
255
|
+
private fun emailToEmailMessage(msg: Message, folder: IMAPFolder, needBody: Boolean = true): EmailMessage {
|
|
256
256
|
val mime = msg as? MimeMessage ?: return EmailMessage(
|
|
257
257
|
uid = 0.0, sequenceNumber = msg.messageNumber.toDouble(),
|
|
258
258
|
subject = "", from = EmailAddress("", ""), to = emptyArray(),
|
|
@@ -286,9 +286,10 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
286
286
|
onHtml = { bodyHtml = it },
|
|
287
287
|
onEmbedded = { embeddedAttachments.add(it) },
|
|
288
288
|
onAttachment = { attachments.add(it) },
|
|
289
|
-
fullData = false
|
|
289
|
+
fullData = false,
|
|
290
|
+
needBody = needBody)
|
|
290
291
|
} catch (_: Exception) {
|
|
291
|
-
bodyText = mime.content?.toString() ?: ""
|
|
292
|
+
if (needBody) bodyText = mime.content?.toString() ?: ""
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
val headers = mutableMapOf<String, String>()
|
|
@@ -392,19 +393,20 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
392
393
|
onEmbedded: (String) -> Unit,
|
|
393
394
|
onAttachment: (AttachmentInfo) -> Unit,
|
|
394
395
|
fullData: Boolean = true,
|
|
396
|
+
needBody: Boolean = true,
|
|
395
397
|
) {
|
|
396
398
|
if (part.isMimeType("text/plain")) {
|
|
397
399
|
// text/plain 也可能是附件(带 attachment disposition / filename / name):
|
|
398
400
|
// 先判定附件,再当作正文。与 Web 端一致(1.txt/2.txt 等 text/plain 附件)。
|
|
399
401
|
if (isAttachmentLike(part)) {
|
|
400
402
|
handleAttachmentLeaf(part, onEmbedded, onAttachment, fullData)
|
|
401
|
-
} else {
|
|
403
|
+
} else if (needBody) {
|
|
402
404
|
onText(part.content?.toString() ?: "")
|
|
403
405
|
}
|
|
404
406
|
} else if (part.isMimeType("text/html")) {
|
|
405
407
|
if (isAttachmentLike(part)) {
|
|
406
408
|
handleAttachmentLeaf(part, onEmbedded, onAttachment, fullData)
|
|
407
|
-
} else {
|
|
409
|
+
} else if (needBody) {
|
|
408
410
|
onHtml(part.content?.toString() ?: "")
|
|
409
411
|
}
|
|
410
412
|
} else if (part.isMimeType("multipart/alternative")) {
|
|
@@ -414,12 +416,14 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
414
416
|
for (i in 0 until mp.count) {
|
|
415
417
|
val bp = mp.getBodyPart(i)
|
|
416
418
|
if (bp.isMimeType("text/html") && !foundHtml && !isAttachmentLike(bp)) {
|
|
417
|
-
|
|
419
|
+
foundHtml = true
|
|
420
|
+
if (needBody) onHtml(bp.content?.toString() ?: "")
|
|
418
421
|
} else if (bp.isMimeType("text/plain") && !foundText && !isAttachmentLike(bp)) {
|
|
419
|
-
|
|
422
|
+
foundText = true
|
|
423
|
+
if (needBody) onText(bp.content?.toString() ?: "")
|
|
420
424
|
} else if (bp.isMimeType("multipart/*")) {
|
|
421
425
|
// alternative 内嵌套的子 multipart(related/mixed 等)→ 递归,不遗漏附件
|
|
422
|
-
parseBodyParts(bp, onText, onHtml, onEmbedded, onAttachment, fullData)
|
|
426
|
+
parseBodyParts(bp, onText, onHtml, onEmbedded, onAttachment, fullData, needBody)
|
|
423
427
|
} else {
|
|
424
428
|
// alternative 内的非正文叶子(内嵌图/附件)→ 附件判定
|
|
425
429
|
handleAttachmentLeaf(bp, onEmbedded, onAttachment, fullData)
|
|
@@ -428,7 +432,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
428
432
|
} else if (part.isMimeType("multipart/*")) {
|
|
429
433
|
val mp = part.content as? Multipart ?: return
|
|
430
434
|
for (i in 0 until mp.count) {
|
|
431
|
-
parseBodyParts(mp.getBodyPart(i), onText, onHtml, onEmbedded, onAttachment, fullData)
|
|
435
|
+
parseBodyParts(mp.getBodyPart(i), onText, onHtml, onEmbedded, onAttachment, fullData, needBody)
|
|
432
436
|
}
|
|
433
437
|
} else {
|
|
434
438
|
handleAttachmentLeaf(part, onEmbedded, onAttachment, fullData)
|
|
@@ -914,7 +918,8 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
914
918
|
}
|
|
915
919
|
|
|
916
920
|
try {
|
|
917
|
-
|
|
921
|
+
val needBody = options.fetchBody != false
|
|
922
|
+
msgs.forEach { result.add(emailToEmailMessage(it, ensureFolderOpen(), needBody)) }
|
|
918
923
|
} catch (e: Exception) {
|
|
919
924
|
Log.e(TAG, "Fetch emails failed", e)
|
|
920
925
|
}
|
|
@@ -975,7 +980,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
975
980
|
}
|
|
976
981
|
val limit = minOf(criteria.limit?.toInt() ?: msgs.size, msgs.size, MAX_FETCH_COUNT)
|
|
977
982
|
val sorted = msgs.sortedByDescending { it.receivedDate?.time ?: 0L }.take(limit)
|
|
978
|
-
sorted.forEach { result.add(emailToEmailMessage(it, folder)) }
|
|
983
|
+
sorted.forEach { result.add(emailToEmailMessage(it, folder, criteria.fetchBody != false)) }
|
|
979
984
|
return@async result.toTypedArray()
|
|
980
985
|
}
|
|
981
986
|
|
|
@@ -1039,7 +1044,7 @@ class EmailImapSmtp : HybridEmailImapSmtpSpec() {
|
|
|
1039
1044
|
|
|
1040
1045
|
val limit = minOf(criteria.limit?.toInt() ?: sortedMsgs.size, sortedMsgs.size, MAX_FETCH_COUNT)
|
|
1041
1046
|
for (i in 0 until limit) {
|
|
1042
|
-
result.add(emailToEmailMessage(sortedMsgs[i], folder))
|
|
1047
|
+
result.add(emailToEmailMessage(sortedMsgs[i], folder, criteria.fetchBody != false))
|
|
1043
1048
|
}
|
|
1044
1049
|
}
|
|
1045
1050
|
} catch (e: Exception) {
|
package/package.json
CHANGED