Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 73a3c70c authored by Patrick Lang's avatar Patrick Lang Committed by GitHub
Browse files

Added x-parameter to store filename and preserve it over sync (#51)



* Added x-parameter to store filename and preserve it over sync

* Minor update (setting flags as in other components)

Co-authored-by: default avatarPatrick Lang <patrick@techbee.at>
parent 18e62f7b
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -196,12 +196,12 @@ open class JtxICalObject(
    companion object {

        const val X_PROP_COMPLETEDTIMEZONE = "X-COMPLETEDTIMEZONE"
        const val X_PARAM_ATTACH_LABEL = "X-LABEL"     // used for filename

        const val MAX_ATTACHMENT_SYNC_SIZE = 102400 // = 100KB

        /**
         * Parses an iCalendar resource, applies [ICalPreprocessor] to increase compatibility
         * and extracts the VTODOs and/or VJOURNALS.
         * Parses an iCalendar resource and extracts the VTODOs and/or VJOURNALS.
         *
         * @param reader where the iCalendar is taken from
         *
@@ -422,6 +422,10 @@ open class JtxICalObject(
                            attachment.fmttype = it.value
                            prop.parameters?.remove(it)
                        }
                        prop.parameters?.getParameter<XParameter>(X_PARAM_ATTACH_LABEL)?.let {
                            attachment.filename = it.value
                            prop.parameters.remove(it)
                        }

                        attachment.other = JtxContract.getJsonStringFromXParameters(prop.parameters)

@@ -807,6 +811,7 @@ open class JtxICalObject(
                    if(attachmentBytes.size <= MAX_ATTACHMENT_SYNC_SIZE) {     // Sync only small attachments that are smaller than 100 KB, larger ones are ignored
                        val att = Attach(attachmentBytes).apply {
                            attachment.fmttype?.let { this.parameters.add(FmtType(it)) }
                            attachment.filename?.let { this.parameters.add(XParameter(X_PARAM_ATTACH_LABEL, it)) }
                        }
                        props += att
                    }
@@ -815,6 +820,7 @@ open class JtxICalObject(
                    attachment.uri?.let { uri ->
                        val att = Attach(URI(uri)).apply {
                            attachment.fmttype?.let { this.parameters.add(FmtType(it)) }
                            attachment.filename?.let { this.parameters.add(XParameter(X_PARAM_ATTACH_LABEL, it)) }
                        }
                        props += att
                    }
@@ -1060,10 +1066,10 @@ duration?.let(props::add)
        var updateUri = JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(collection.account)
        updateUri = Uri.withAppendedPath(updateUri, this.id.toString())

        val values = ContentValues()
        val values = ContentValues(1)
        values.put(JtxContract.JtxICalObject.FLAGS, flags)

        collection.client.update(updateUri, values, null, null)
        this.flags = flags
    }

    /**
@@ -1276,6 +1282,7 @@ duration?.let(props::add)
                put(JtxContract.JtxAttachment.URI, attachment.uri)
                put(JtxContract.JtxAttachment.FMTTYPE, attachment.fmttype)
                put(JtxContract.JtxAttachment.OTHER, attachment.other)
                put(JtxContract.JtxAttachment.FILENAME, attachment.filename)
            }
            val newAttachment = collection.client.insert(
                JtxContract.JtxAttachment.CONTENT_URI.asSyncAdapter(
@@ -1533,7 +1540,7 @@ duration?.let(props::add)
                    attachmentValues.getAsString(JtxContract.JtxAttachment.BINARY)?.let { value -> this.binary = value }
                    attachmentValues.getAsString(JtxContract.JtxAttachment.FMTTYPE)?.let { fmttype -> this.fmttype = fmttype }
                    attachmentValues.getAsString(JtxContract.JtxAttachment.OTHER)?.let { other -> this.other = other }

                    attachmentValues.getAsString(JtxContract.JtxAttachment.FILENAME)?.let { filename -> this.filename = filename }
                }
                attachments.add(attachment)
            }
+15 −6
Original line number Diff line number Diff line
/***************************************************************************************************
 * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
 **************************************************************************************************/
/*
 * Copyright (c) Techbee e.U.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 */

package at.techbee.jtx

import android.accounts.Account
import android.net.Uri
import android.provider.BaseColumns
import android.util.Log
import at.bitfire.ical4android.Ical4Android
import net.fortuna.ical4j.model.ParameterList
import net.fortuna.ical4j.model.Property
@@ -39,7 +42,7 @@ object JtxContract {
    const val AUTHORITY = "at.techbee.jtx.provider"

    /** The version of this SyncContentProviderContract */
    const val VERSION = 1
    const val VERSION = 2

    /** Constructs an Uri for the Jtx Sync Adapter with the given Account
     * @param [account] The account that should be appended to the Base Uri
@@ -1217,6 +1220,13 @@ object JtxContract {
         */
        const val FMTTYPE = "fmttype"

        /**
         * Purpose:  To specify the filename of the attachment.
         * This is an X-PROPERTY that should be addressed as "X-LABEL"
         * Type: [String]
         */
        const val FILENAME = "filename"

        /**
         * Purpose:  To specify other properties for the attachment.
         * see [https://tools.ietf.org/html/rfc5545#section-3.8.1.1]
@@ -1405,5 +1415,4 @@ object JtxContract {
         */
        const val UNKNOWN_VALUE = "value"
    }

}
 No newline at end of file