This is for making a PAK with the e-mail address. zimbraPAK contains the key generated by the gdpak command.
Code:
function getZimbraPAK($email) {
// Returns query array with the PAK in it for an e-mail address
global $zimbraPAK;
$PAKTime = time()."000";
$preauthString = $email."|name|0|".$PAKTime;
$PAK = hash_hmac ("sha1",$preauthString,$zimbraPAK);
$query = array(
"account" => $email,
"by" => "name",
"timestamp" => $PAKTime,
"expires" => "0",
"preauth" => $PAK);
return $query;
} Turn this into a URL with....
Code:
$zimbraPAK = "RANDOM_ZIMBRA_PAK";
$query = getZimbraPAK("user@domain.com");
$url = $zimbraHost."/service/preauth?".http_build_query($query); I also use the following to get the mailbox node of the user...
Code:
function getZimbraHomeServer($email) {
// Gets the users mailbox server
$zimbraLDAP = ldap_connect("zimbra.domain.com");
ldap_set_option($zimbraLDAP, LDAP_OPT_PROTOCOL_VERSION, 3);
$zimbraLDAPR = ldap_bind($zimbraLDAP);
// Query Zimbra Accounts
$zimbraLDAPBase = "ou=people,dc=co,dc=marshall,dc=ia,dc=us";
$zimbraSearchFilter="(zimbraMailDeliveryAddress=".$email.")";
$zimbraSearchRes = ldap_search($zimbraLDAP,$zimbraLDAPBase,$zimbraSearchFilter);
$zimbraSearchEntries = ldap_get_entries($zimbraLDAP,$zimbraSearchRes);
return $zimbraSearchEntries[0]["zimbramailhost"][0];
}