Dovecot and iPhone push

I don’t know how many of you out there have your own webserver and an iPhone, but I just found the thing I’ve been looking for ever since I got my iPhone: push e-mail!

I have a webserver running cPanel, Dovecot and suPHP. Here’s what I did:

1) Download z-push from here.

2) Upload z-push to /usr/local/apache/htdocs

3) Change ownership to nobody (it fails if you leave it as root)

4) Modify index.php (if you are using suPHP)

Comment out $requestheaders = apache_request_headers(); and replace it with

    function getHeaders()
$headers = array();
foreach ($_SERVER as $k => $v)
if (substr($k, 0, 5) == "HTTP_")
$k = str_replace('_', ' ', substr($k, 5));
$k = str_replace(' ', '-', ucwords(strtolower($k)));
$headers[$k] = $v;
return $headers;
$requestheaders = getHeaders();

5) Modify config.php


6) Add the alias to httpd. conf (as explained in the config file, but use /usr/local/apache/htdocs instead of /var/ www)

7) Restart Apache

8) Go to your iPhone and set up your e-mail account as a Microsoft Exchange account. (Be sure to sync “All messages” or else you’ll be deleting things twice.)

9) Voila! You now have push mail on your iPhone with your Dovecot IMAP server!


10) You may need to modify backend/diffbackend.php to make it delete properly.

Find the following code:

        function ImportMessageMove($id, $newfolder) {
return true;

Change that to

function ImportMessageMove($id, $newfolder) {
//do nothing if it is in a dummy folder
if ($this->_folderid == SYNC_FOLDER_TYPE_DUMMY)
return true;

// See if there's a conflict
$conflict = $this->isConflict("move", $this->_folderid, $id);

// Update client state
$change = array();
$change["id"] = $id;
$change["newfolder"] = $newfolder;
$this->updateState("move", $change);

P.S. I am not the author of any of the above fixes. These were all found in the forums.

Be Sociable, Share!

4 Responses to “Dovecot and iPhone push”

  1. Kansas Bob says:

    We don’t have iPhones in Kansas.. we are Sprint-centric!

    Okay.. yeah.. there are iPhones here.. unfortunately not Sprint iPhones :(

  2. casey says:

    Well, it was the unlimited data plan that attracted me, and not necessarily the iPhone itself. It allows me to download big attachments from my clients on the go. That, plus the availability of the Bible app, because that lets me take my iPhone to church instead of a big Bible (it’s nice when you have to ride a train for 30 minutes, usually standing).

  3. Ionut says:


    i’m lost here at step 6) Add the alias to httpd. conf (as explained in the config file, but use /usr/local/apache/htdocs instead of /var/ www)

    how come.i don’t understand.. can you give more details?


    • casey says:

      Hi Ionut,

      The httpd. conf file is in /usr/local/apache/conf/
      What you want to do is open it up and add

      Alias /Microsoft-Server-ActiveSync /usr/local/apache/htdocs/z-push/index.php

      (Make sure it is on one line)

      You can add it anywhere you want, I think, but I added it after all the LoadModule lines.

      Don’t forget to restart Apache afterwards.