Warn about suspicious mail senders and links
Bump version to 0.1.21 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -4,7 +4,9 @@ import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.app.AlertDialog
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
@@ -224,6 +226,34 @@ class EpMailPlugin : Plugin() {
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun openExternal(call: PluginCall) {
|
||||
val raw = call.getString("url").orEmpty()
|
||||
val uri = runCatching { Uri.parse(raw) }.getOrNull()
|
||||
if (uri == null || uri.scheme?.lowercase(Locale.ROOT) !in setOf("http", "https") ||
|
||||
uri.host.isNullOrBlank() || uri.userInfo != null) {
|
||||
call.reject("Only standard web links can be opened from mail.")
|
||||
return
|
||||
}
|
||||
AlertDialog.Builder(activity)
|
||||
.setTitle("Open external link?")
|
||||
.setMessage("Email links can lead to fake sign-in pages or harmful content.\n\nCheck the full address before continuing:\n${uri}")
|
||||
.setNegativeButton("Cancel") { _, _ -> call.resolve(JSObject().put("opened", false)) }
|
||||
.setPositiveButton("Open link") { _, _ ->
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri)
|
||||
activity.startActivity(intent)
|
||||
call.resolve(JSObject().put("opened", true))
|
||||
} catch (_: android.content.ActivityNotFoundException) {
|
||||
call.reject("No browser is available to open this link.")
|
||||
} catch (error: Exception) {
|
||||
call.reject(error.message ?: "Could not open the link.")
|
||||
}
|
||||
}
|
||||
.setOnCancelListener { call.resolve(JSObject().put("opened", false)) }
|
||||
.show()
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun send(call: PluginCall) {
|
||||
val input = JSONObject(call.data.toString()).apply {
|
||||
|
||||
Reference in New Issue
Block a user