A couple of weeks ago I decided it was time to upgrade my Roundcube installation again. I don’t really enjoy doing that due to the amount of plugins I have installed. But it was overdue. In what must have been a stroke of pure brilliance, I allowed Webmail Notifier to upgrade too. (Part of that upgrade was a rename to X-notifier.)
Don’t upgrade two dependent things at the same time. Just don’t. That’s the kind of stuff that causes double breakage and you won’t know where to look for the problem, or the solution.
Anyway, the X-notifier script for Roundcube didn’t work the way I wanted it too. In fact, it didn’t work properly at all. Two problems that needed fixing. I just love spending more time than planned on this kind of stuff. I’m describing this here, hoping that it saves someone else a bit of time.
Just a few preliminaries: the Roundcube version I’m using is 0.8.4. X-notifier is at 3.0.4. Both are the latest versions at the time of writing. I run X-notifier in Firefox. The script for Roundcube is downloadable on the X-notifier site: direct link.
X-notifier scripts are quite flexible in how they get the number of unread counts. The script for Roundcube uses the fact that Roundcube is quite Ajax-centric to its advantage. After the login yada yada it does a simple call to one of the Ajax end-points and parses the output.
First problem: cached mailboxes
Roundcube caches the number of unread messages and it doesn’t flush that cache when the X-notifier scripts requests the number of unread messages. There are two possible calls (“actions” in Roundcube-speak) that can be done: “getunread” and “check-recent”. The first is used by Roundcube when you first load the page, the second during the periodic refresh.
The X-notifier script uses “getunread”. Unfortunately, “getunread” uses cached values. The only way to get an up-to-date value is to go to Roundcube and hit refresh there, defeating the purpose of having a notifier. “check-recent” refreshes the cache, but it can’t be used either, because it sends only counts for changed mailboxes.
The solution is to first do a “check-recent” call and then a “getunread” call, giving neatly updated counts.
Second problem: only inbox counting
I have a few filters that sort mail into several mailboxes. (The purpose is to keep bacn separate from ham, and to have some rudimentary separation between private and business emails.) Having a notifier that only notifies for a single mailbox doesn’t work in that scenario.
Fortunately, the “getunread” call returns counts for all subscribed mailboxes (if you enabled the proper setting in Roundcube’s settings). So fixing that was a matter of looping through some regex patterns and adding the counts. A simple trick. My efforts here were hampered a little by the lack of debugging tools, or even logging, but the code was short and fixing short code can be done acceptably with a brute-force approach.
Both Roundcube and X-notifier are well-designed, making it possible to understand what was going on and how things should be. I was a bit disappointed by the lack of documentation regarding writing X-notifier scripts. The only documentation was a short forum post. I had to look at other scripts and the extension source code to figure out how things should work.
My new Roundcube script for X-notifier is available for download here. I have also created a patch-file with the differences. If the original is updated and mine isn’t, you can use that. It’s available for download here.