Wednesday, November 17, 2010

Z-Push Woes

Z-Push (http://z-push.sourceforge.net/) is an interesting project. It is a PHP web app that lets you serve different backends for mail/contacts to clients that support ActiveSync. The most common use for it seems to be to give devices with zero or minimal IMAP support (but decent ActiveSync support) access to their mail by letting them connect to that IMAP through ActiveSync.

The first thing that bothered me was it REALLY wants to run under mod_php in Apache. People have been able to get it to run in fastCGI by adding the following to compat.php:

if (!function_exists("apache_request_headers")) {
    function apache_request_headers() {
        $headers = array();
        foreach ($_SERVER as $key => $value) {
            if (substr($key, 0, 5) != 'HTTP_') {
                continue;
            }
            $headername = strtr(ucwords(strtolower(strtr(substr($key, 5), '_', ' '))), ' ', '-');
            $headers[$headername] = $value;
        }

        return $headers;
    }
(Taken from http://z-push.sourceforge.net/phpbb/viewtopic.php?f=2&t=36#p1349)
Sadly, the z-push developers didn't accept that patch.

The second problem I ran in to was z-push was segfaulting in PHP's imap_search function. I looked at the raw logs and saw that the client was getting a good response from the search request, but PHP still segfaulted. Some investigation led me to suspect the SE_FREE flag, per this PHP bug report: http://bugs.php.net/48619

Basically I changed the following line in backend/imap.php:
$search = @imap_search($this->_mbox, "SINCE ". date("d-M-Y", $cutoffdate));
to look like:
$search = @imap_search($this->_mbox, "SINCE ". date("d-M-Y", $cutoffdate), ! SE_FREE);
and things started working. So if your PHP is newer than 5.2.10 you hopefully don't have to deal with this. But if not, hopefully this helps you.

No comments:

Post a Comment