Share My Creation TBirdSync: Thunderbird contacts/calendar/tasks mirroring from PC to Android (sources included)

Background
I hesitated to post this as it's probably only useful for a small audience (if any), but as I didn't find another solution, perhaps it can benefit others who are looking for this or for something similar.

I've been using the excellent MyPhoneExplorer (https://www.fjsoft.at/en/) for years to sync my contacts, calendar, and tasks from a Windows PC (first MS Outlook, then Mozilla Thunderbird) to my Android devices. In the future (possibly distant - or even never) I may switch completely from Windows to Linux. Unfortunately I (and apparently anybody else) was unable to get MyPhoneExplorer running on Linux - e.g. with WINE - and I don't want the overhead of a VM.

So I decided to create something myself: TBirdSync. I haven't tested it on Linux yet - that's for later (or never). Tested on Windows 10 and Linux Mint 20.02 Cinnamon.

The big picture - my setup
TBirdSync.png


What does/doesn't it do?
It DOES:
- Synchronise Thunderbird contacts with one or more Android devices; contact matching is based on the combination of first and last name (which means that these combinations must be unique)
- Prepare calendar and tasks data and send them to the Android device(s) where they can be processed with the ICSx5 app (see below)
- Convert tasks data to calendar data, which means no separate tasks app is needed on the Android device: everything winds up in the calendar app, where tasks' titles are prefixed with '(T)' so that it's easy to distinguish them from appointments

It DOES NOT:
Perform a 2-way sync (so it's actually more mirroring than syncing): the synchronisation source is Thunderbird, and all changes to the data are expected to be applied there. Changes made on the Android device are not detected.

If you can live with these limitations, read on.

Why ICSx5?
I didn't want to write the calendar/tasks sync code as TBirdSync is a means to an end (i.e. moving to Linux) and not a goal by itself. Calendars are complex beasts and ICSx5 (https://play.google.com/store/apps/details?id=at.bitfire.icsdroid) is a low-cost app (1.99 EUR) that works perfectly; it's even open source and can be found on GitLab (https://gitlab.com/bitfireAT/icsx5). Among other, it syncs an iCalendar (.ics) file with a read-only calendar that it creates itself.

At the moment, ICSx5's sync can't be started via an Intent: on the Android device, TBirdSync starts the app and then a 'pull to refresh' is needed to sync the calendar and tasks data (unless a scheduled sync is setup; sync intervals as of 5 minutes can be selected). I've asked the developers if they would be willing to provide an Intent, and it's on their todo list. Once it's there, I'll update the app to start the sync without user interaction.

If you only want to sync contacts, ICSx5 is not needed.

Getting started
- Get ICSx5 (see above) and install it on the Android device(s)
- Install the TBirdSync app on the Android device(s), enter the settings, and save them
- Install the B4J program on the PC(s), enter the settings, and save them
- In the Android device(s) Settings / Battery / Battery optimization you may want to set TBirdSync and ICSx5 as 'Not optimised' so that they'll also keep going when the device is locked
- TBirdSync uses an iCalendar (.ics) file to process calendar and tasks data. In Thunderbird, you'll either have to manually use 'Export' from the 'Events and Tasks' menu each time you want to sync the data, or do this:
1. Export Events and Tasks to an .ics file
2. File / Open / Calendar file, and then select that exported file, and work with that calendar (and perhaps also delete the original one to avoid confusion/mistakes)
This way, the data are always available in .ics format. It does however slow editing calendar and tasks down a little, but in my opinion the performance hit is reasonable.

Other
- Deleting contacts (which is also used to update them as this simplified the code and speeds things up on the Android side because the PC side does the heavy lifting) didn't work on my Fire tablet with Android 5.1.1 but did on a Moto X Style phone with Android 7, which is why the minSdkVersion in the Manifest was set to 24 to correspond with Android 7. It is however possible that this was caused by the custom ROM I had installed on the Fire tablet and that it does work on older Android versions.
- The icon comes from https://www.pngrepo.com/svg/156939/update-business-user
- My environment: Windows 10, Thunderbird 78.10.1 (32-bit), Android 7, ICSx5 1.9.1-gplay, B4A 10.70, B4J 8.90

Non-core library dependencies
B4A:
- AndroidResources: https://www.b4x.com/android/forum/threads/16847
- Archiver: https://www.b4x.com/android/forum/threads/21688
- Clipboard: https://www.b4x.com/android/forum/threads/clipboard-library.7382
- zt-zip (see https://www.b4x.com/android/forum/threads/b4j-b4a-zt-zip.99595): add the 3 jars from the attached 'zt-zip jars.zip' to your B4A additional libraries folder

B4J:
- jReflection: https://www.b4x.com/android/forum/threads/jreflection-library.35448/
- zt-zip (see https://www.b4x.com/android/forum/threads/b4j-b4a-zt-zip.99595): add the 3 jars from the attached 'zt-zip jars.zip' to your B4J additional libraries folder

Screenshots

TBirdSync B4J screenshot.PNG
TBirdSync B4A screenshot.jpg


Enjoy!
 

Attachments

  • TBirdSync_B4A.zip
    96.9 KB · Views: 259
  • TBirdSync_B4J.zip
    63.9 KB · Views: 258
  • TBirdSync B4J screenshot.PNG
    TBirdSync B4J screenshot.PNG
    38.9 KB · Views: 368
  • TBirdSync B4A screenshot.jpg
    TBirdSync B4A screenshot.jpg
    294.8 KB · Views: 369
  • TBirdSync_B4A v2.zip
    98.9 KB · Views: 238
  • TBirdSync_B4J v2.zip
    65.5 KB · Views: 251
  • zt-zip jars.zip
    140.3 KB · Views: 222
  • TBirdSync_B4J v5.zip
    72.9 KB · Views: 190
  • TBirdSync_B4A v5.zip
    127.4 KB · Views: 202
  • TBirdSync_B4A v6.zip
    129.2 KB · Views: 137
  • TBirdSync_B4J v6.zip
    94.7 KB · Views: 143
  • TBirdSync_B4A v8.zip
    134.3 KB · Views: 131
  • TBirdSync_B4J v8.zip
    102.8 KB · Views: 136
Last edited:

walt61

Active Member
Licensed User
Longtime User
Version 2 attached to the first post.

B4J changes:
- streamlined Msgbox2Async handling
- added button 'Select .ics copy folder' (and the label beside it); on Android 11, I couldn't find a directory that would be accessible by both TBirdSync and ICSx5; with this button, a copy of the calendar/tasks .ics file can be placed e.g. on a shared NAS folder and then be accessed with ICSx5 through a http subscription
- if an error occurs during sync preps, the connection with the server will now be closed
- at the first contacts sync (or after using menu option 'Reset contacts' on the Android device), an attempt will be made to delete all existing contacts on the Android device (after user approval)

B4A changes:
- streamlined Msgbox2Async handling
- added checkboxes 'Start at boot' and 'Keep alive'
- Manifest: changed targetSdkVersion from 29 to 30
- Manifest: added WRITE_EXTERNAL_STORAGE (for RuntimePermissions/GetSafeDirDefaultExternal)
- Manifest: added '<queries>' block to be able to detect the presence of ICSx5 (at.bitfire.icsdroid) on Android 11
- corrected RuntimePermissions handling
- at the first contacts sync (or after using menu option 'Reset contacts' on the Android device), an attempt will be made to delete all existing contacts on the Android device (after user approval)
 

jerry07

Member
Licensed User
Longtime User
This is very interesting project, thank you very much for posting I'm glad you decided to share.
 

walt61

Active Member
Licensed User
Longtime User
Version 5 attached to the first post. Notice that @stevel05's zt-zip is used (see https://www.b4x.com/android/forum/threads/b4j-b4a-zt-zip.99595); add the 3 jars from the attached 'zt-zip jars.zip' to your B4A/B4J additional libraries folders.

B4J changes:
- using wmutils.RedirectOutput now, and wmUtils.MsgBoxLongText where appropriate (as preparation for Linux)
- on Windows, stdout and stderr are now redirected to files in directory %APPDATA%\Roaming\TBirdSync instead of File.DirApp
- stdout and stderr files are now overwritten instead of appending to them
- File.DirApp replaced with File.DirData("TBirdSync") as the former will cause problems on Windows with the program installed by Inno Setup
- added Sub Application_Error
- improved handling of the 'Sync' button's visibility
- added more progress reporting messages
- the ics file is now zipped before transferring it to the B4A device (and unzipped when it arrives there)

B4A changes:
- the ics file is now zipped before transferring it to the B4A device (and unzipped when it arrives there)
- B4A version number aligned with the B4J version
 

walt61

Active Member
Licensed User
Longtime User
Version 6 attached to the first post.

B4J changes:
- changed a number of views from native to B4XView
- the form is now immediately shown at its intended position, instead of moving visibly
- now using wmUtils.MyDirData instead of File.DirData (to facilitate Linux operation and avoid the settings file to be overwritten when the program is re-packaged)
- on Linux, querying the Thunderbird database threw an exception if Thunderbird was running ('the database is locked'); this exception is now intercepted
- ReportProgress now Logs its messages too
- ReportProgress and ReportProgress2 now enclose the text in 'Plain' tags to avoid BBCodeView exceptions when the text contains square brackets

B4A changes:
- changed a number of views from native to B4XView
 
Top