Fix Android ui scaling and account creation issue
This commit is contained in:
@@ -487,18 +487,19 @@ internal object AndroidMailService {
|
||||
|
||||
fun watchInbox(
|
||||
account: JSONObject,
|
||||
onNewMail: (Int) -> Unit,
|
||||
shouldStop: () -> Boolean,
|
||||
onConnection: (Store?, Folder?) -> Unit
|
||||
) {
|
||||
val props = imapProperties(account).apply {
|
||||
setProperty("mail.imap.timeout", "0")
|
||||
setProperty("mail.imap.writetimeout", "60000")
|
||||
}
|
||||
onNewMail: (Int) -> Unit,
|
||||
shouldStop: () -> Boolean,
|
||||
onConnection: (Store?, Folder?) -> Unit
|
||||
) {
|
||||
val protocol = imapProtocol(account)
|
||||
val props = imapProperties(account).apply {
|
||||
setProperty("mail.$protocol.timeout", "0")
|
||||
setProperty("mail.$protocol.writetimeout", "60000")
|
||||
}
|
||||
val pollingIntervalMs = account.optInt("syncIntervalMinutes", 2)
|
||||
.coerceIn(2, 60) * 60_000L
|
||||
val session = Session.getInstance(props, credentials(account))
|
||||
val store = session.getStore("imap")
|
||||
val store = session.getStore(protocol)
|
||||
try {
|
||||
store.connect(
|
||||
account.optString("imapHost"),
|
||||
@@ -782,9 +783,9 @@ internal object AndroidMailService {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> withStore(account: JSONObject, block: (Session, Store) -> T): T {
|
||||
val session = Session.getInstance(imapProperties(account), credentials(account))
|
||||
val store = session.getStore("imap")
|
||||
private fun <T> withStore(account: JSONObject, block: (Session, Store) -> T): T {
|
||||
val session = Session.getInstance(imapProperties(account), credentials(account))
|
||||
val store = session.getStore(imapProtocol(account))
|
||||
try {
|
||||
store.connect(
|
||||
account.optString("imapHost"),
|
||||
@@ -798,37 +799,28 @@ internal object AndroidMailService {
|
||||
}
|
||||
}
|
||||
|
||||
private fun credentials(account: JSONObject) = object : Authenticator() {
|
||||
private fun credentials(account: JSONObject) = object : Authenticator() {
|
||||
override fun getPasswordAuthentication() = PasswordAuthentication(
|
||||
account.optString("email"),
|
||||
account.optString("password")
|
||||
)
|
||||
}
|
||||
|
||||
private fun imapProperties(account: JSONObject) = Properties().apply {
|
||||
setProperty("mail.store.protocol", "imap")
|
||||
setProperty("mail.imap.host", account.optString("imapHost"))
|
||||
setProperty("mail.imap.port", account.optInt("imapPort", 143).toString())
|
||||
setProperty("mail.imap.auth", "true")
|
||||
setProperty("mail.imap.starttls.enable", "true")
|
||||
setProperty("mail.imap.starttls.required", "true")
|
||||
setProperty("mail.imap.ssl.checkserveridentity", "true")
|
||||
setProperty("mail.imap.connectiontimeout", "20000")
|
||||
setProperty("mail.imap.timeout", "30000")
|
||||
setProperty("mail.imap.writetimeout", "30000")
|
||||
}
|
||||
|
||||
private fun smtpProperties(account: JSONObject) = Properties().apply {
|
||||
setProperty("mail.smtp.host", account.optString("smtpHost"))
|
||||
setProperty("mail.smtp.port", account.optInt("smtpPort", 587).toString())
|
||||
setProperty("mail.smtp.auth", "true")
|
||||
setProperty("mail.smtp.starttls.enable", "true")
|
||||
setProperty("mail.smtp.starttls.required", "true")
|
||||
setProperty("mail.smtp.ssl.checkserveridentity", "true")
|
||||
setProperty("mail.smtp.connectiontimeout", "20000")
|
||||
setProperty("mail.smtp.timeout", "30000")
|
||||
setProperty("mail.smtp.writetimeout", "30000")
|
||||
}
|
||||
private fun imapProperties(account: JSONObject) = Properties().apply {
|
||||
putAll(AndroidMailTransport.imapProperties(MailServerConnection(
|
||||
account.optString("imapHost"),
|
||||
account.optInt("imapPort", 143),
|
||||
account.optBoolean("imapSecure", false)
|
||||
)))
|
||||
}
|
||||
|
||||
private fun imapProtocol(account: JSONObject) = if (account.optBoolean("imapSecure", false)) "imaps" else "imap"
|
||||
|
||||
private fun smtpProperties(account: JSONObject) = AndroidMailTransport.smtpProperties(MailServerConnection(
|
||||
account.optString("smtpHost"),
|
||||
account.optInt("smtpPort", 587),
|
||||
account.optBoolean("smtpSecure", false)
|
||||
))
|
||||
|
||||
private fun displayName(account: JSONObject) =
|
||||
account.optString("displayName").replace(Regex("[\\r\\n]"), " ").take(80)
|
||||
|
||||
Reference in New Issue
Block a user