Trim leading and trailing whitespaces in incoming SMS messages

This commit is contained in:
mushroom-dev 2023-01-01 17:17:41 +01:00
parent ff1d3f1237
commit a7485385ef

View file

@ -259,7 +259,7 @@ class SmsCommunicatorPlugin @Inject constructor(
val pump = activePlugin.activePump
messages.add(receivedSms)
aapsLogger.debug(LTag.SMS, receivedSms.toString())
val divided = receivedSms.text.split(Regex("\\s+")).toTypedArray()
val divided = receivedSms.text.trim().split(Regex("\\s+")).toTypedArray()
val remoteCommandsAllowed = sp.getBoolean(R.string.key_smscommunicator_remote_commands_allowed, false)
val minDistance =
@ -1226,6 +1226,7 @@ class SmsCommunicatorPlugin @Inject constructor(
override fun sendSMS(sms: Sms): Boolean {
sms.text = stripAccents(sms.text)
try {
aapsLogger.debug(LTag.SMS, "Sending SMS to " + sms.phoneNumber + ": " + sms.text)
if (sms.text.toByteArray().size <= 140) smsManager?.sendTextMessage(sms.phoneNumber, null, sms.text, null, null)