Index: app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt b/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt --- a/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt (revision f69533b0497e71f0b817af72ec10d1f8830b060a) +++ b/app/src/main/kotlin/at/bitfire/davdroid/sync/CalendarSyncManager.kt (date 1730531313263) @@ -41,9 +41,11 @@ import java.io.ByteArrayOutputStream import java.io.Reader import java.io.StringReader +import java.nio.charset.Charset import java.time.Duration import java.time.ZonedDateTime import java.util.logging.Level +import java.util.regex.Pattern /** * Synchronization manager for CalDAV collections; handles events (VEVENT). @@ -237,9 +239,11 @@ override fun postProcess() {} + val regex = + "\\s*data:(?:[a-z]+\\/[a-z0-9\\-+.]+(?:;[a-z-]+=[a-z0-9-]+)?)?(?:;base64)?,([a-z0-9!$&',()*+;=\\-._~:@/?%\\s]*)\\s*" + val pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE) // helpers - private fun processVEvent(fileName: String, eTag: String, scheduleTag: String?, reader: Reader) { val events: List try { @@ -250,9 +254,32 @@ return } + + if (events.size == 1) { val event = events.first() + val description = event.description?.toByteArray() + if(description != null && description.size > 500 * 1024){ + + val msg = context.getString(R.string.sync_description_size_limit_msg) + + val matcher = pattern.matcher(event.description.toString()) + var newDescription = matcher.replaceAll("\n\n--- $msg ---\n\n") + + val newDescriptionSize = newDescription.toByteArray().size + if(newDescriptionSize > 500 * 1024) { + val endMsg = "\n\n--- $msg ---" + newDescription = description + .copyOfRange(0, 500 * 1024 - endMsg.toByteArray().size - 1) + .toString(charset = Charset.defaultCharset()) + endMsg + } + + event.description = newDescription + + } + + // set default reminder for non-full-day events, if requested val defaultAlarmMinBefore = accountSettings.getDefaultAlarm() if (defaultAlarmMinBefore != null && DateUtils.isDateTime(event.dtStart) && event.alarms.isEmpty()) { @@ -267,11 +294,13 @@ // update local event, if it exists val local = localCollection.findByName(fileName) + SyncException.wrapWithLocalResource(local) { if (local != null) { logger.log(Level.INFO, "Updating $fileName in local calendar", event) local.eTag = eTag local.scheduleTag = scheduleTag + local.update(event) syncResult.stats.numUpdates++ } else {