Here‘s my solution and it works stable as far as my testing went:
Problem
This is for syncing appointments (calendar) and addresses (contacts) with Android. The first time I was syncing everything looked good, appointments showed up, addresses showed up, I even could open them and read the details. Seconds to minutes later, everything vanished again. Anything I edited was lost. It also disappeared, when I hit sync again. Thunderbird and iOS never had this problem (knock on wood).
Solution
In my self-written backend there‘s a function getFolderList() that returns all the folders for syncing. At first it only returned root, tasks, appointments and adresses – there was no Emailfolder, since I do not want to sync that.
After adding
email-inbox (SYNC_FOLDER_TYPE_INBOX),
email-deleted (SYNC_FOLDER_TYPE_WASTEBASKET),
email-outbox (SYNC_FOLDER_TYPE_OUTBOX)
and email-sent (SYNC_FOLDER_TYPE_SENTMAIL)
it worked. I now reduced that through some more testing to only the email-inbox and it‘s still syncing my appointments and addresses without a problem and without them disappearing again. EDIT: No, some more testing and it’s not stable with only the inbox. Just keep all the folders.
My theory is that Android somehow relies on having at least the inbox folder and assumes there‘s an error if it is missing. With this idea, my logs read differently:
Step 1: foldersync with key, gets “0 changes” - Android assumes it is out of sync, since it is missing the email-folder
Step 2: foldersync without a key, gets the whole list and a new sync key
Step 3: sync without key, gets a new key for appointments
Step 4: sync with key, gets the whole data of appointments
Step 5: foldersync with the new sync key, gets “0 changes” - Android assumes it is out of sync, since it is missing the email-folder and breaks off
So the problem is not the last sync, which I assumed to be a rogue sync that had a problem, but already the first, since it was missing the emailfolder(s).
Additional Info
In my first post is a pastebin, where you can see the “before” in lines 117-198. Here’s part of the log from a successful foldersync (reverse chronological order, start reading at the bottom):
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:FolderSync>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Changes>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 2
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O onOffice Email-Inbox
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooroot
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooemailinbox
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 9
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O onOffice Adressen
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooroot
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooaddress
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 8
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O onOffice Termine
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooroot
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooappointments
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 7
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O onOffice Aufgaben
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooroot
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ootasks
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 1
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Type>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O onOffice root
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:DisplayName>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 0
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ParentId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O ooroot
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:ServerEntryId>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Add>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Count>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 5
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Count>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Changes>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:SyncKey>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O {81ba4da1-5c9a-48b5-b1ca-edfc8cab050d}1
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:SyncKey>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O </FolderHierarchy:Status>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O 1
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:Status>
28/02/2020 11:01:56 [ 3704] [WBXML] [zpushy@doen] [androidc1323317619] O <FolderHierarchy:FolderSync>
28/02/2020 11:01:56 [ 3704] [DEBUG] [zpushy@doen] [androidc1323317619] HierarchyCache: AddFolder() serverid: ooemailinbox displayname: onOffice Email-Inbox
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::StatFolder: id=ooemailinbox
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::GetFolder: id=ooemailinbox
28/02/2020 11:01:56 [ 3704] [DEBUG] [zpushy@doen] [androidc1323317619] HierarchyCache: AddFolder() serverid: ooaddress displayname: onOffice Adressen
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::StatFolder: id=ooaddress
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::GetFolder: id=ooaddress
28/02/2020 11:01:56 [ 3704] [DEBUG] [zpushy@doen] [androidc1323317619] HierarchyCache: AddFolder() serverid: ooappointments displayname: onOffice Termine
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::StatFolder: id=ooappointments
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::GetFolder: id=ooappointments
28/02/2020 11:01:56 [ 3704] [DEBUG] [zpushy@doen] [androidc1323317619] HierarchyCache: AddFolder() serverid: ootasks displayname: onOffice Aufgaben
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::StatFolder: id=ootasks
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::GetFolder: id=ootasks
28/02/2020 11:01:56 [ 3704] [DEBUG] [zpushy@doen] [androidc1323317619] HierarchyCache: AddFolder() serverid: ooroot displayname: onOffice root
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::StatFolder: id=ooroot
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::GetFolder: id=ooroot
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] ExportChangesDiff->InitializeExporter(): Found '5' changes for 'hierarchy'
28/02/2020 11:01:56 [ 3704] [ INFO] [zpushy@doen] [androidc1323317619] BackendOnOfficeSync::GetFolderList
Big thank you for everyone who pitched in, here and in the other thread! :)
Bye,
BD