Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,32 @@ object MsgBlockFactory {
}

fun fromAttachment(type: MsgBlock.Type, attachment: MimePart): MsgBlock {
val attContent = attachment.content
val data = attachment.inputStream.readBytes()

val attMeta = AttMeta(
name = attachment.fileName,
data = attachment.inputStream.readBytes(),
length = data.size.toLong(),
type = attachment.contentType,
contentId = attachment.contentID
)
val content = if (attContent is String) attachment.content as String else null
return when (type) {
MsgBlock.Type.DECRYPTED_ATT -> DecryptedAttMsgBlock(null, true, attMeta, null)
MsgBlock.Type.ENCRYPTED_ATT -> EncryptedAttMsgBlock(content, attMeta)
MsgBlock.Type.PLAIN_ATT -> PlainAttMsgBlock(content, attMeta)
else ->
throw IllegalArgumentException("Can't create block of type ${type.name} from attachment")
try {
val attContent = attachment.content
val data = attachment.inputStream.readBytes()
val attMeta = AttMeta(
name = attachment.fileName,
data = data,
length = data.size.toLong(),
type = attachment.contentType,
contentId = attachment.contentID
)
val content = if (attContent is String) attachment.content as String else null
return when (type) {
MsgBlock.Type.DECRYPTED_ATT -> DecryptedAttMsgBlock(null, true, attMeta, null)
MsgBlock.Type.ENCRYPTED_ATT -> EncryptedAttMsgBlock(content, attMeta)
MsgBlock.Type.PLAIN_ATT -> PlainAttMsgBlock(content, attMeta)
else ->
throw IllegalArgumentException("Can't create block of type ${type.name} from attachment")
}
} catch (e: Exception) {
e.printStackTrace()
return GenericMsgBlock(
type = type,
content = null,
complete = false,
error = MsgBlockError("[" + e.javaClass.simpleName + "]: " + e.message)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@ object MsgBlockParser {
}

for (attachment in decoded.attachments) {
try {
val attMsgBlock = if (PgpMsg.treatAs(attachment) == PgpMsg.TreatAs.PUBLIC_KEY) {
val content = String(attachment.inputStream.readBytes())
MsgBlockFactory.fromContent(MsgBlock.Type.PUBLIC_KEY, content)
} else {
MsgBlockFactory.fromAttachment(MsgBlock.Type.DECRYPTED_ATT, attachment)
}
blocks.add(attMsgBlock)
} catch (e: Exception) {
e.printStackTrace()
val treatAs = PgpMsg.treatAs(attachment)
val attMsgBlock = if (treatAs == PgpMsg.TreatAs.PUBLIC_KEY) {
val content = String(attachment.inputStream.readBytes())
MsgBlockFactory.fromContent(MsgBlock.Type.PUBLIC_KEY, content)
} else {
MsgBlockFactory.fromAttachment(MsgBlock.Type.DECRYPTED_ATT, attachment)
}
blocks.add(attMsgBlock)
}

return SanitizedBlocks(blocks, isRichText)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,16 +845,15 @@ class MessageDetailsFragment : BaseFragment(), ProgressBehaviour, View.OnClickLi
}

MsgBlock.Type.DECRYPTED_ATT -> {
val decryptAtt: DecryptedAttMsgBlock = block as DecryptedAttMsgBlock
inlineEncryptedAtts.add(decryptAtt.toAttachmentInfo())
val decryptAtt = block as? DecryptedAttMsgBlock
if (decryptAtt != null) {
inlineEncryptedAtts.add(decryptAtt.toAttachmentInfo())
} else {
handleOtherBlock(block, layoutInflater)
}
}

else -> layoutMsgParts?.addView(
genDefPart(
block, layoutInflater,
R.layout.message_part_other, layoutMsgParts
)
)
else -> handleOtherBlock(block, layoutInflater)
}
isFirstMsgPartText = false
}
Expand All @@ -869,6 +868,18 @@ class MessageDetailsFragment : BaseFragment(), ProgressBehaviour, View.OnClickLi
}
}

private fun handleOtherBlock(
block: @JvmSuppressWildcards MsgBlock,
layoutInflater: LayoutInflater
) {
layoutMsgParts?.addView(
genDefPart(
block, layoutInflater,
R.layout.message_part_other, layoutMsgParts
)
)
}

private fun setupWebView(block: MsgBlock) {
emailWebView?.configure()

Expand Down Expand Up @@ -1087,13 +1098,22 @@ class MessageDetailsFragment : BaseFragment(), ProgressBehaviour, View.OnClickLi
inflater: LayoutInflater,
res: Int,
viewGroup: ViewGroup?
): TextView {
val textViewMsgPartOther = inflater.inflate(res, viewGroup, false) as TextView
textViewMsgPartOther.text = clipLargeText(block.content)
return textViewMsgPartOther
): View {
val errorMsg = block.error?.errorMsg
return if (errorMsg?.isNotEmpty() == true) {
getView(
null,
getString(R.string.msg_contains_not_valid_block, block.type.toString(), errorMsg),
layoutInflater
)
} else {
val textViewMsgPartOther = inflater.inflate(res, viewGroup, false) as TextView
textViewMsgPartOther.text = clipLargeText(block.content)
textViewMsgPartOther
}
}

private fun genTextPart(block: MsgBlock, layoutInflater: LayoutInflater): TextView {
private fun genTextPart(block: MsgBlock, layoutInflater: LayoutInflater): View {
return genDefPart(block, layoutInflater, R.layout.message_part_text, layoutMsgParts)
}

Expand Down Expand Up @@ -1179,12 +1199,14 @@ class MessageDetailsFragment : BaseFragment(), ProgressBehaviour, View.OnClickLi
val textViewErrorMsg = viewGroup.findViewById<TextView>(R.id.textViewErrorMessage)
ExceptionUtil.handleError(ManualHandledException(errorMsg))
textViewErrorMsg.text = errorMsg
viewGroup.addView(genShowOrigMsgLayout(originalMsg, layoutInflater, viewGroup))
onClickListener?.let {
val btAction = viewGroup.findViewById<TextView>(R.id.btAction)
btAction.text = buttonText
btAction.visible()
btAction.setOnClickListener(it)
if (originalMsg != null) {
viewGroup.addView(genShowOrigMsgLayout(originalMsg, layoutInflater, viewGroup))
onClickListener?.let {
val btAction = viewGroup.findViewById<TextView>(R.id.btAction)
btAction.text = buttonText
btAction.visible()
btAction.setOnClickListener(it)
}
}
return viewGroup
}
Expand Down
1 change: 1 addition & 0 deletions FlowCrypt/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,5 @@
<string name="decrypt_error_message_bad_mdc">Security threat - opening this message is dangerous because it was modified in transit.</string>
<string name="decrypt_error_message_no_mdc">Security threat!\n\nMessage is missing integrity checks (MDC). The sender should update their outdated software.\n\nDisplay the message at your own risk.</string>
<string name="msg_contains_not_valid_pub_key">This message contained a Public Key that was not valid.\n\n%1$s</string>
<string name="msg_contains_not_valid_block">This message contained a block with type = %1$s that was not valid.\n\n%2$s</string>
</resources>