Android security implementation Phase 2 finalization part 1
This commit is contained in:
@@ -669,6 +669,7 @@ internal object AndroidMailService {
|
||||
collectParts(message, body, htmlBodies, attachments, links)
|
||||
val bodyText = body.joinToString("\n\n").trim().take(8000)
|
||||
val encrypted = isEncryptedMessage(message) || bodyText.contains("-----BEGIN PGP MESSAGE-----")
|
||||
val signed = isSignedMessage(message) || bodyText.contains("-----BEGIN PGP SIGNED MESSAGE-----")
|
||||
val visibleBody = if (encrypted) "This message is encrypted. Unlock it with your OpenPGP key to read it." else bodyText
|
||||
val snippet = (if (encrypted) "Encrypted message" else visibleBody.ifBlank { subject }).replace(Regex("\\s+"), " ").take(180)
|
||||
val date = message.receivedDate ?: message.sentDate ?: Date()
|
||||
@@ -694,6 +695,7 @@ internal object AndroidMailService {
|
||||
.put("subject", subject)
|
||||
.put("snippet", snippet)
|
||||
.put("encrypted", encrypted)
|
||||
.put("signed", signed)
|
||||
.put("time", DateFormat.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(date))
|
||||
.put("date", DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault()).format(date))
|
||||
.put("timestamp", date.time)
|
||||
@@ -723,18 +725,29 @@ internal object AndroidMailService {
|
||||
} else if (content is String && content.contains("-----BEGIN PGP MESSAGE-----")) return true
|
||||
return false
|
||||
}
|
||||
|
||||
private fun isSignedMessage(part: javax.mail.Part): Boolean {
|
||||
if (part.isMimeType("multipart/signed")) return true
|
||||
val content = try { part.content } catch (_: Exception) { return false }
|
||||
if (content is Multipart) {
|
||||
for (index in 0 until content.count) if (isSignedMessage(content.getBodyPart(index))) return true
|
||||
} else if (content is String && content.contains("-----BEGIN PGP SIGNED MESSAGE-----")) return true
|
||||
return false
|
||||
}
|
||||
|
||||
private fun attachmentList(attachments: JSONArray): List<JSONObject> =
|
||||
(0 until attachments.length()).map { attachments.getJSONObject(it) }
|
||||
|
||||
private fun collectParts(
|
||||
private fun collectParts(
|
||||
part: javax.mail.Part,
|
||||
body: MutableList<String>,
|
||||
htmlBodies: MutableList<String>,
|
||||
attachments: JSONArray,
|
||||
links: MutableSet<String>
|
||||
) {
|
||||
val filename = decode(part.fileName)
|
||||
) {
|
||||
if (part.isMimeType("application/pgp-signature") || part.isMimeType("application/pgp-encrypted")) return
|
||||
val filename = decode(part.fileName)
|
||||
if (part.isMimeType("application/octet-stream") && filename.equals("encrypted.asc", true)) return
|
||||
if (filename.isNotBlank() || part.disposition.equals(javax.mail.Part.ATTACHMENT, true)) {
|
||||
val name = filename.ifBlank { "attachment" }
|
||||
val size = part.size.coerceAtLeast(0)
|
||||
|
||||
Reference in New Issue
Block a user