Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better mailto handling on Android #5519

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions app-android/app/src/main/java/de/tutao/tutanota/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.content.pm.PackageManager
import android.graphics.Color
import android.graphics.Rect
import android.net.MailTo
import android.net.ParseException
import android.net.Uri
import android.os.Bundle
import android.os.PowerManager
Expand Down Expand Up @@ -573,11 +574,16 @@ class MainActivity : FragmentActivity() {
} else {
files = listOf()
}
val mailToUrlString: String = if (intent.data != null && MailTo.isMailTo(intent.dataString)) {
intent.dataString ?: ""
} else {
""

val mailTo = try {
MailTo.parse(intent.dataString.orEmpty())
} catch (e: ParseException) {
Log.w(TAG, e)
null
}

val mailToUrlString: String = if (mailTo != null && !mailTo.isEmpty) intent.dataString.orEmpty() else ""

try {
commonNativeFacade.createMailEditor(
files,
Expand Down
4 changes: 4 additions & 0 deletions app-android/app/src/main/java/de/tutao/tutanota/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package de.tutao.tutanota

import android.content.Context
import android.content.res.Resources
import android.net.MailTo
import android.net.Uri
import android.os.Build
import android.provider.OpenableColumns
Expand Down Expand Up @@ -145,3 +146,6 @@ fun HttpURLConnection.iterateDataAsLines(action: (line: String) -> Unit) =
fun Int.toPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt()

fun Int.toDp(): Int = (this / Resources.getSystem().displayMetrics.density).toInt()

val MailTo.isEmpty: Boolean
get() = headers?.all { entry -> entry.value.isNullOrEmpty() } ?: true