Block remote images by default
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -591,9 +591,10 @@ internal object AndroidMailService {
|
||||
val senderEmail = sender?.address ?: ""
|
||||
val subject = decode(message.subject).ifBlank { "(no subject)" }
|
||||
val body = ArrayList<String>()
|
||||
val htmlBodies = ArrayList<String>()
|
||||
val attachments = JSONArray()
|
||||
val links = linkedSetOf<String>()
|
||||
collectParts(message, body, attachments, links)
|
||||
collectParts(message, body, htmlBodies, attachments, links)
|
||||
val bodyText = body.joinToString("\n\n").trim().take(8000)
|
||||
val snippet = (bodyText.ifBlank { subject }).replace(Regex("\\s+"), " ").take(180)
|
||||
val date = message.receivedDate ?: message.sentDate ?: Date()
|
||||
@@ -628,6 +629,7 @@ internal object AndroidMailService {
|
||||
.put("archived", requestedFolder == "Archive")
|
||||
.put("deleted", requestedFolder == "Trash")
|
||||
.put("sourceFolder", labelFolder)
|
||||
.put("html", htmlBodies.firstOrNull()?.take(100000) ?: "")
|
||||
.put("body", JSONArray().apply {
|
||||
val paragraphs = bodyText.split(Regex("\\n\\s*\\n")).map(String::trim).filter(String::isNotEmpty).take(40)
|
||||
if (paragraphs.isEmpty()) put("This message has no plain-text body.") else paragraphs.forEach(::put)
|
||||
@@ -641,7 +643,13 @@ internal object AndroidMailService {
|
||||
private fun attachmentList(attachments: JSONArray): List<JSONObject> =
|
||||
(0 until attachments.length()).map { attachments.getJSONObject(it) }
|
||||
|
||||
private fun collectParts(part: javax.mail.Part, body: MutableList<String>, attachments: JSONArray, links: MutableSet<String>) {
|
||||
private fun collectParts(
|
||||
part: javax.mail.Part,
|
||||
body: MutableList<String>,
|
||||
htmlBodies: MutableList<String>,
|
||||
attachments: JSONArray,
|
||||
links: MutableSet<String>
|
||||
) {
|
||||
val filename = decode(part.fileName)
|
||||
if (filename.isNotBlank() || part.disposition.equals(javax.mail.Part.ATTACHMENT, true)) {
|
||||
val name = filename.ifBlank { "attachment" }
|
||||
@@ -654,6 +662,7 @@ internal object AndroidMailService {
|
||||
is String -> if (part.isMimeType("text/plain")) {
|
||||
body.add(content.replace("\r", "").trim())
|
||||
} else if (part.isMimeType("text/html")) {
|
||||
if (htmlBodies.isEmpty()) htmlBodies.add(content.take(100000))
|
||||
Regex("""<a\b[^>]*\bhref\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))""", RegexOption.IGNORE_CASE)
|
||||
.findAll(content)
|
||||
.mapNotNull { match -> (match.groups[1]?.value ?: match.groups[2]?.value ?: match.groups[3]?.value)?.replace("&", "&") }
|
||||
@@ -662,9 +671,9 @@ internal object AndroidMailService {
|
||||
if (body.isEmpty()) body.add(Html.fromHtml(content, Html.FROM_HTML_MODE_LEGACY).toString().trim())
|
||||
}
|
||||
is Multipart -> for (index in 0 until content.count) {
|
||||
collectParts(content.getBodyPart(index), body, attachments, links)
|
||||
collectParts(content.getBodyPart(index), body, htmlBodies, attachments, links)
|
||||
}
|
||||
is javax.mail.BodyPart -> collectParts(content, body, attachments, links)
|
||||
is javax.mail.BodyPart -> collectParts(content, body, htmlBodies, attachments, links)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user