Merge pull request #1876 from Chris-GW/fix_contentLine_formatting

Use the correct line seperator as defined in RFC 5545 formatting guidelines, which can otherwise lead to an error
This commit is contained in:
Tibor Kaputa 2022-11-11 18:44:13 +01:00 committed by GitHub
commit 78fce7bb86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import com.simplemobiletools.commons.extensions.writeLn
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import java.io.BufferedWriter
import java.io.OutputStream
import java.io.OutputStreamWriter
class IcsExporter {
enum class ExportResult {
@ -47,7 +48,20 @@ class IcsExporter {
activity.toast(R.string.exporting)
}
outputStream.bufferedWriter().use { out ->
object : BufferedWriter(OutputStreamWriter(outputStream, Charsets.UTF_8)) {
val lineSeparator = "\r\n"
/**
* Writes a line separator. The line separator string is defined by RFC 5545 in 3.1. Content Lines:
* Content Lines are delimited by a line break, which is a CRLF sequence (CR character followed by LF character).
*
* @see <a href="https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html">RFC 5545 - 3.1. Content Lines</a>
*/
override fun newLine() {
write(lineSeparator)
}
}.use { out ->
out.writeLn(BEGIN_CALENDAR)
out.writeLn(CALENDAR_PRODID)
out.writeLn(CALENDAR_VERSION)
@ -58,7 +72,7 @@ class IcsExporter {
event.eventType.let { out.writeLn("$CATEGORY_COLOR${activity.eventTypesDB.getEventTypeWithId(it)?.color}") }
event.eventType.let { out.writeLn("$CATEGORIES${activity.eventTypesDB.getEventTypeWithId(it)?.title}") }
event.lastUpdated.let { out.writeLn("$LAST_MODIFIED:${Formatter.getExportedTime(it)}") }
event.location.let { out.writeLn("$LOCATION:$it") }
event.location.let { if (it.isNotEmpty()) out.writeLn("$LOCATION:$it") }
event.availability.let { out.writeLn("$TRANSP${if (it == Events.AVAILABILITY_FREE) TRANSPARENT else OPAQUE}") }
if (event.getIsAllDay()) {
@ -138,9 +152,5 @@ class IcsExporter {
isFirstLine = false
index += MAX_LINE_LENGTH
}
if (isFirstLine) {
out.writeLn("$DESCRIPTION$description")
}
}
}