View Single Post
Community Council | Posts: 4,920 | Thanked: 12,867 times | Joined on May 2012 @ Southerrn Finland
#1
Okay, firstly, I am not really sure if this belongs into the "applications" category since this is really more an extension of functionality than an application, but here it goes anyway

Background:

The default email synchronization framework for Sailfish is pretty barebones, you could say it sucks like a hoover in fact.
For IMAP accounts the only thing you can do is to set up synchronization interval, and that's it.
I have been told it is a bit better for Exchange accounts, there you can set at least busy-hour interval and off-hour interval separately.

This is way too primitive, what it means is that I'd need to suffer continuous email pings thru the night, or else manually turn it off at the end of the day.

What I want to do, is something like this, for example:
  • On weekdays I want synchronizing every 10 minutes between 06:00 and 16:00, else I want syncing every hour until midnight.
  • Between midnight and 06:00 no syncing whatsoever, I want to sleep.
  • On weekends I want to sleep late, so start syncing only after 11:00am, and sync every two hours until midnight.

Well, that does sound like job for cron, right?

Solution:
I have built and packaged the basic Vixie Cron that's been adapted to Sailfish by Zeamoceq. It's probably the simplest cron version, no extra niceties&features like on fcron but it does the job.
Now, normally I use that for backup syncing and setting up remote connections to my device, and adding email sync to crontab was no brainer.

What caused me eornomous problems was how to get cron to signal the mail client that it should do an update... I tried various ways of DBUS messaging to emulate the swipe gesture on the email UI but no avail

Thanks to @w00t, @special & @chem|st, who helped me with this!
I had gone at it from the wrong end of things, it appears that the correct way is to send DBUS message to buteo, which is the synchronization framework on Sailfish. Buteo will then trigger the sync on the email client...

This is the message to sync email:
dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'syncemail'

Now, my special email synchronizing schedule can be reduced to 3 lines in my crontab:
Code:
# check mail every 10 minutes during office hours on weekdays
*/10  6-16  *  *  1-5   DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/100000/dbus/user_bus_socket" /bin/dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'syncemail'  > /dev/null 2>&1

# check mail every hour on evenings on weekdays
1  17-23  *  *  1-5     DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/100000/dbus/user_bus_socket" /bin/dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'syncemail'  > /dev/null 2>&1

# check mail every second hour after I have woken up on weekends
1  11-23/2  *  *  6-7   DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/100000/dbus/user_bus_socket" /bin/dbus-send --session --type=method_call --print-reply --dest=com.meego.msyncd /synchronizer com.meego.msyncd.startSync string:'syncemail'  > /dev/null 2>&1

The installable application:
That's the crond & crontab, of course. Here is the SRPM for it

Now, why do I distribute a SRPM, wouldn't a RPM be better, huh??
Absolutely not. I have an ideological aversion to distributing binary programs, unless I really really have to. Installing unknown binary packages to your system is not something I encourage.

Hence the SRPM.

Besides, building well made SRPM's is just as easy & quick as installing a binary RPM, and it gives you the chance to peek at the source, to verify yourself that the beast really is what it claims to be.

So, for the first'timers to source package installation, this is how you do it:
rpm -i vixie-cron-3.0pl1-1.src.rpm
rpmbuild -bb rpmbuild/SPECS/vixie_cron.spec

That's it, now you have the RPM and you can install it as root:
rpm -i rpmbuild/RPMS/armv7hl/vixie-cron-3.0pl1-1.armv7hl.rpm

Now there's some dependencies you need on your device, but nothing too drastic. You need to install the following packages:
zypper in gcc rpm-build meego-rpm-config


Stability & battery usage:
I have now used this email sync method for a full week, and it works without a hitch.

I have found that this does not really increase battery consumption of the device noticeably. Most of the time cron is sleeping on a socket, waiting for a system timer wakeup event to happen.

My biggest battery eater is always the GPS track recorder I use few hours every day. If I don't use that, I have maybe 77% left after a day of maybe 18 hours active use (few phonecalls, SMS, emails, browsinf TMO, etc...)
If I use 2 hours of GPS logging in addition to that, battery could be down to 60% in the evening when I go to sleep...

You need to keep the email app open, of course, for this to work. If you close your email, synchronization event does not start it, but rather passes harmlessely.
 

The Following 11 Users Say Thank You to juiceme For This Useful Post: