mirror of
https://github.com/ProtonMail/android-mail.git
synced 2026-05-15 09:50:40 +00:00
Remove MailTo logic from IntentShareExtensions
ET-5410
This commit is contained in:
committed by
MargeBot
parent
a0309b39e3
commit
007b37685f
+3
-42
@@ -21,9 +21,7 @@ package ch.protonmail.android.mailcommon.data.file
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import androidx.core.net.MailTo
|
||||
import ch.protonmail.android.mailcommon.domain.model.IntentShareInfo
|
||||
import me.proton.core.util.kotlin.takeIfNotEmpty
|
||||
import timber.log.Timber
|
||||
|
||||
object IntentExtraKeys {
|
||||
@@ -35,8 +33,8 @@ fun Intent.getShareInfo(): IntentShareInfo {
|
||||
return when (action) {
|
||||
Intent.ACTION_SEND -> getShareInfoForSingleSendAction()
|
||||
Intent.ACTION_SEND_MULTIPLE -> getShareInfoForMultipleSendAction()
|
||||
Intent.ACTION_VIEW -> getShareInfoForViewAction()
|
||||
Intent.ACTION_SENDTO -> getShareInfoForSendToAction()
|
||||
Intent.ACTION_VIEW,
|
||||
Intent.ACTION_SENDTO -> getShareInfoForViewAndSendToAction()
|
||||
|
||||
else -> {
|
||||
Timber.d("Unhandled intent action: $action")
|
||||
@@ -45,7 +43,6 @@ fun Intent.getShareInfo(): IntentShareInfo {
|
||||
}
|
||||
}
|
||||
|
||||
fun Intent.isStartedFromLauncher(): Boolean = action == Intent.ACTION_MAIN
|
||||
fun Intent.isExternal(): Boolean = getBooleanExtra(IntentExtraKeys.EXTRA_EXTERNAL_SHARE, false) &&
|
||||
action != Intent.ACTION_MAIN
|
||||
|
||||
@@ -79,43 +76,7 @@ private fun Intent.getShareInfoForMultipleSendAction(): IntentShareInfo {
|
||||
)
|
||||
}
|
||||
|
||||
private fun Intent.getShareInfoForViewAction(): IntentShareInfo {
|
||||
val intentUri = getFileUrisForActionViewAndSendTo().takeIfNotEmpty()?.firstOrNull()
|
||||
|
||||
return if (intentUri?.scheme == MAILTO_SCHEME) {
|
||||
val mailTo = MailTo.parse(intentUri)
|
||||
|
||||
val toRecipients = mailTo.to
|
||||
?.split(",")
|
||||
?.map { it.trim() }
|
||||
?: getRecipientTo()
|
||||
|
||||
val ccRecipients: List<String> = mailTo.cc
|
||||
?.split(",")
|
||||
?: getRecipientCc()
|
||||
|
||||
val bccRecipients: List<String> = mailTo.bcc
|
||||
?.split(",")
|
||||
?: getRecipientBcc()
|
||||
|
||||
val subject = mailTo.subject ?: getSubject()
|
||||
val body = mailTo.body ?: getEmailBody()
|
||||
|
||||
IntentShareInfo(
|
||||
attachmentUris = emptyList(),
|
||||
emailSubject = subject,
|
||||
emailRecipientTo = toRecipients,
|
||||
emailRecipientCc = ccRecipients,
|
||||
emailRecipientBcc = bccRecipients,
|
||||
emailBody = body,
|
||||
isExternal = isExternal()
|
||||
)
|
||||
} else {
|
||||
getShareInfoForSendToAction()
|
||||
}
|
||||
}
|
||||
|
||||
private fun Intent.getShareInfoForSendToAction(): IntentShareInfo {
|
||||
private fun Intent.getShareInfoForViewAndSendToAction(): IntentShareInfo {
|
||||
return IntentShareInfo(
|
||||
attachmentUris = getFileUrisForActionViewAndSendTo().map { it.toString() },
|
||||
emailSubject = getSubject(),
|
||||
|
||||
-45
@@ -39,9 +39,6 @@ class IntentExtensionsTest {
|
||||
private val uri2 = mockk<Uri> {
|
||||
every { scheme } returns "content"
|
||||
}
|
||||
private val mailToUri = mockk<Uri> {
|
||||
every { scheme } returns "mailto"
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
@@ -91,48 +88,6 @@ class IntentExtensionsTest {
|
||||
assertEquals(expected, fileShareInfo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return share info with recipient when uri has mailto scheme in intent data for action view`() {
|
||||
// Given
|
||||
val recipientEmail = "user1@example.com"
|
||||
every { Uri.decode(any()) } returns recipientEmail
|
||||
every { Uri.parse(any()) } returns mailToUri
|
||||
every { mailToUri.toString() } returns "mailto:$recipientEmail"
|
||||
val intent = mockIntent(action = Intent.ACTION_VIEW, data = mailToUri)
|
||||
val expected = IntentShareInfo.Empty.copy(emailRecipientTo = listOf(recipientEmail))
|
||||
|
||||
// When
|
||||
val fileShareInfo = intent.getShareInfo()
|
||||
|
||||
// Then
|
||||
assertEquals(expected, fileShareInfo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return share info with multiple recipients when uri has mailto scheme in intent for action view`() {
|
||||
// Given
|
||||
val recipientEmail1 = "user1@example.com"
|
||||
val recipientEmail2 = "user2@example.com"
|
||||
val recipientEmail3 = "user3@example.com"
|
||||
every { Uri.decode(any()) } returns "$recipientEmail1,$recipientEmail2,$recipientEmail3"
|
||||
every { Uri.parse(any()) } returns mailToUri
|
||||
every { mailToUri.toString() } returns "mailto:$recipientEmail1,$recipientEmail2,$recipientEmail3"
|
||||
val intent = mockIntent(action = Intent.ACTION_VIEW, data = mailToUri)
|
||||
val expected = IntentShareInfo.Empty.copy(
|
||||
emailRecipientTo = listOf(
|
||||
recipientEmail1,
|
||||
recipientEmail2,
|
||||
recipientEmail3
|
||||
)
|
||||
)
|
||||
|
||||
// When
|
||||
val fileShareInfo = intent.getShareInfo()
|
||||
|
||||
// Then
|
||||
assertEquals(expected, fileShareInfo)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should return empty share info when no Uri in intent data for action sendto`() {
|
||||
// Given
|
||||
|
||||
Reference in New Issue
Block a user