BUG 9090 ZImbra Trigger Issues

Now all Triggers uses in correct way Server param and Upload trigger does not use any more http_request instead use curl.
This commit is contained in:
Hugo Loza
2012-04-27 16:39:51 -04:00
parent 692cbe3f28
commit 6d7a14a5f0
2 changed files with 222 additions and 209 deletions

View File

@@ -21,7 +21,7 @@ class Zimbra {
protected $_preauth_expiration = 0; // 0 indicates using the default preauth expiration as defined on the server protected $_preauth_expiration = 0; // 0 indicates using the default preauth expiration as defined on the server
protected $_dev; // boolean indicating whether this is development or not protected $_dev; // boolean indicating whether this is development or not
protected $_protocol; // which protocol to use when building the URL protected $_protocol; // which protocol to use when building the URL
protected $_server1 = 'ip-10-73-18-235.ec2.internal'; // hostname of zimbra server protected $_server1;// = 'ip-10-73-18-235.ec2.internal'; // hostname of zimbra server
protected $_server; // displayname of zimbra server protected $_server; // displayname of zimbra server
protected $_path = '/service/soap'; protected $_path = '/service/soap';
protected $_timestamp; protected $_timestamp;
@@ -55,11 +55,12 @@ class Zimbra {
$this->_preAuthKey = $preAuthKey; $this->_preAuthKey = $preAuthKey;
$this->_protocol = "http://"; // could also be http:// $this->_protocol = "http://"; // could also be http://
$this->_server = $serverUrl; //'zimbra.hostname.edu'; $this->_server = $serverUrl; //'zimbra.hostname.edu';
$this->_server1 = $serverUrl; //'zimbra.hostname.edu';
$this->_username = $username; $this->_username = $username;
$this->_timestamp = time() . '000'; $this->_timestamp = time() . '000';
} }
// end __construct // end __construct
/** /**
* sso * sso
@@ -84,7 +85,7 @@ class Zimbra {
} }
} }
// end sso // end sso
/** /**
* createAccount * createAccount
@@ -99,10 +100,10 @@ class Zimbra {
$soap = '<CreateAccountRequest xmlns="urn:zimbraAccount"> $soap = '<CreateAccountRequest xmlns="urn:zimbraAccount">
<name>' . $name . '@' . $this->_server1 . '</name> <name>' . $name . '@' . $this->_server1 . '</name>
<password>' . $password . '</password>' . $option_string . ' <password>' . $password . '</password>' . $option_string . '
<session/> <session/>
</CreateAccountRequest>'; </CreateAccountRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
@@ -134,7 +135,7 @@ class Zimbra {
return $this->hmacsha1($this->_preAuthKey, $string); return $this->hmacsha1($this->_preAuthKey, $string);
} }
// end getPreAuth // end getPreAuth
/** /**
* hmacsha1 * hmacsha1
@@ -167,7 +168,7 @@ class Zimbra {
return bin2hex($hmac); return bin2hex($hmac);
} }
// end hmacsha1 // end hmacsha1
/** /**
* connect * connect
@@ -195,14 +196,14 @@ class Zimbra {
if ($this->_admin) { if ($this->_admin) {
$body = '<AuthRequest xmlns="urn:zimbraAdmin"> $body = '<AuthRequest xmlns="urn:zimbraAdmin">
<name>' . $this->_admin_username . '</name> <name>' . $this->_admin_username . '</name>
<password>' . $this->_admin_password . '</password> <password>' . $this->_admin_password . '</password>
</AuthRequest>'; </AuthRequest>';
} else { } else {
$body = '<AuthRequest xmlns="urn:zimbraAccount"> $body = '<AuthRequest xmlns="urn:zimbraAccount">
<account by="name">' . $this->_username . '@' . $this->_server1 . '</account> <account by="name">' . $this->_username . '@' . $this->_server1 . '</account>
<preauth timestamp="' . $this->_timestamp . '" expires="' . $this->_preauth_expiration . '">' . $preauth . '</preauth> <preauth timestamp="' . $this->_timestamp . '" expires="' . $this->_preauth_expiration . '">' . $preauth . '</preauth>
</AuthRequest>'; </AuthRequest>';
} }
$response = $this->soapRequest($body, $header, true); $response = $this->soapRequest($body, $header, true);
@@ -223,7 +224,7 @@ class Zimbra {
} }
} }
// end connect // end connect
/** /**
* administerUser * administerUser
@@ -243,8 +244,8 @@ class Zimbra {
$this->_username = $username; $this->_username = $username;
$body = '<DelegateAuthRequest xmlns="urn:zimbraAdmin"> $body = '<DelegateAuthRequest xmlns="urn:zimbraAdmin">
<account by="name">' . $this->_username . '@' . $this->_server . '</account> <account by="name">' . $this->_username . '@' . $this->_server . '</account>
</DelegateAuthRequest>'; </DelegateAuthRequest>';
$response = $this->soapRequest($body, $header); $response = $this->soapRequest($body, $header);
if ($response) { if ($response) {
$tmp = $this->makeXMLTree($response); $tmp = $this->makeXMLTree($response);
@@ -259,7 +260,7 @@ class Zimbra {
} }
} }
// end administerUser // end administerUser
/** /**
* getInfo * getInfo
@@ -285,7 +286,7 @@ class Zimbra {
} }
} }
// end getInfo // end getInfo
/** /**
* getMessages * getMessages
@@ -302,8 +303,8 @@ class Zimbra {
$option_string = $this->buildOptionString($options); $option_string = $this->buildOptionString($options);
$soap = '<SearchRequest xmlns="urn:zimbraMail" types="message"' . $option_string . '> $soap = '<SearchRequest xmlns="urn:zimbraMail" types="message"' . $option_string . '>
<query>' . $search . '</query> <query>' . $search . '</query>
</SearchRequest>'; </SearchRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -313,7 +314,7 @@ class Zimbra {
} }
} }
// end getMessages // end getMessages
/** /**
* getContacts * getContacts
@@ -330,8 +331,8 @@ class Zimbra {
$option_string = $this->buildOptionString($options); $option_string = $this->buildOptionString($options);
$soap = '<SearchRequest xmlns="urn:zimbraMail" types="contact"' . $option_string . '> $soap = '<SearchRequest xmlns="urn:zimbraMail" types="contact"' . $option_string . '>
<query>' . $search . '</query> <query>' . $search . '</query>
</SearchRequest>'; </SearchRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -341,26 +342,26 @@ class Zimbra {
} }
} }
// end getContacts // end getContacts
/* getAppointments /* getAppointments
* *
* get the Appointments in folder * get the Appointments in folder
* *
* @since version 1.0 * @since version 1.0
* @access public * @access public
* @param string $search folder to retrieve from * @param string $search folder to retrieve from
* @param array $options options to apply to retrieval * @param array $options options to apply to retrieval
* @return array array of messages * @return array array of messages
*/ */
public function getAppointments($search='in:calendar', $options=array('limit' => 50, 'fetch' => 'none')) { public function getAppointments($search='in:calendar', $options=array('limit' => 50, 'fetch' => 'none')) {
$option_string = $this->buildOptionString($options); $option_string = $this->buildOptionString($options);
$soap = '<SearchRequest xmlns="urn:zimbraMail" types="appointment"' . $option_string . '> $soap = '<SearchRequest xmlns="urn:zimbraMail" types="appointment"' . $option_string . '>
<query>' . $search . '</query> <query>' . $search . '</query>
</SearchRequest>'; </SearchRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -370,25 +371,25 @@ class Zimbra {
} }
} }
// end getAppointments // end getAppointments
/* getTasks /* getTasks
* *
* get the Tasks in folder * get the Tasks in folder
* *
* @since version 1.0 * @since version 1.0
* @access public * @access public
* @param string $search folder to retrieve from * @param string $search folder to retrieve from
* @param array $options options to apply to retrieval * @param array $options options to apply to retrieval
* @return array array of messages * @return array array of messages
*/ */
public function getTasks($search='in:tasks', $options=array('limit' => 50, 'fetch' => 'none')) { public function getTasks($search='in:tasks', $options=array('limit' => 50, 'fetch' => 'none')) {
$option_string = $this->buildOptionString($options); $option_string = $this->buildOptionString($options);
$soap = '<SearchRequest xmlns="urn:zimbraMail" types="task"' . $option_string . '> $soap = '<SearchRequest xmlns="urn:zimbraMail" types="task"' . $option_string . '>
<query>' . $search . '</query> <query>' . $search . '</query>
</SearchRequest>'; </SearchRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -398,7 +399,7 @@ class Zimbra {
} }
} }
// end getTasks // end getTasks
/** /**
* getMessageContent * getMessageContent
@@ -412,8 +413,8 @@ class Zimbra {
*/ */
public function getMessageContent($id) { public function getMessageContent($id) {
$soap = '<GetMsgRequest xmlns="urn:zimbraMail"> $soap = '<GetMsgRequest xmlns="urn:zimbraMail">
<m id="' . $id . '" html="1">*</m> <m id="' . $id . '" html="1">*</m>
</GetMsgRequest>'; </GetMsgRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
@@ -454,7 +455,7 @@ class Zimbra {
return $subscribed; return $subscribed;
} }
// end getSubscribedCalendars // end getSubscribedCalendars
/** /**
* getSubscribedTaskLists * getSubscribedTaskLists
@@ -476,7 +477,7 @@ class Zimbra {
return $subscribed; return $subscribed;
} }
// end getSubscribedCalendars // end getSubscribedCalendars
/** /**
* getFolder * getFolder
@@ -493,8 +494,8 @@ class Zimbra {
//$folder_option_string = $this->buildOptionString($folder_options); //$folder_option_string = $this->buildOptionString($folder_options);
$soap = '<GetFolderRequest xmlns="urn:zimbraMail" visible="1"> $soap = '<GetFolderRequest xmlns="urn:zimbraMail" visible="1">
<folder path="' . $folderName . '"/> <folder path="' . $folderName . '"/>
</GetFolderRequest>'; </GetFolderRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -510,7 +511,7 @@ class Zimbra {
} }
} }
// end getFolder // end getFolder
/** /**
* getPrefrences * getPrefrences
@@ -537,7 +538,7 @@ class Zimbra {
} }
} }
// end getPreferences // end getPreferences
/** /**
* setPrefrences * setPrefrences
@@ -557,8 +558,8 @@ class Zimbra {
} }
$soap = '<ModifyPrefsRequest xmlns="urn:zimbraAccount"> $soap = '<ModifyPrefsRequest xmlns="urn:zimbraAccount">
' . $option_string . ' ' . $option_string . '
</ModifyPrefsRequest>'; </ModifyPrefsRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
return true; return true;
@@ -567,7 +568,7 @@ class Zimbra {
} }
} }
// end setPreferences // end setPreferences
/** /**
* emailChannel * emailChannel
@@ -635,18 +636,18 @@ class Zimbra {
} }
/* include_once 'portal_functions.php'; /* include_once 'portal_functions.php';
$roles = getRoles($this->_username); $roles = getRoles($this->_username);
if(in_array('faculty', $roles) || in_array('employee', $roles)) if(in_array('faculty', $roles) || in_array('employee', $roles))
{ {
$tpl->parse('main.away_message'); $tpl->parse('main.away_message');
} */ } */
$tpl->parse('main'); $tpl->parse('main');
$tpl->out('main'); $tpl->out('main');
} }
// end emailChannel // end emailChannel
/** /**
* builOptionString * builOptionString
@@ -666,7 +667,7 @@ class Zimbra {
return $options_string; return $options_string;
} }
// end buildOptionString // end buildOptionString
/** /**
* extractAuthToken * extractAuthToken
@@ -705,7 +706,7 @@ class Zimbra {
return $session_id; return $session_id;
} }
// end extractSessionID // end extractSessionID
/** /**
* extractErrorCode * extractErrorCode
@@ -724,7 +725,7 @@ class Zimbra {
return $session_id; return $session_id;
} }
// end extractErrorCode // end extractErrorCode
/** /**
* makeBytesPretty * makeBytesPretty
@@ -741,7 +742,7 @@ class Zimbra {
if ($bytes < 1024) if ($bytes < 1024)
$size = $bytes . ' B'; $size = $bytes . ' B';
elseif ($bytes < 1024 * 1024) elseif ($bytes < 1024 * 1024)
$size = round($bytes / 1024, 1) . ' KB'; $size = round($bytes / 1024, 1) . ' KB';
else else
$size = round(($bytes / 1024) / 1024, 1) . ' MB'; $size = round(($bytes / 1024) / 1024, 1) . ' MB';
@@ -752,7 +753,7 @@ class Zimbra {
return $size; return $size;
} }
// end makeBytesPretty // end makeBytesPretty
/** /**
* message * message
@@ -769,7 +770,7 @@ class Zimbra {
} }
} }
// end message // end message
/** /**
* soapRequest * soapRequest
@@ -790,15 +791,15 @@ class Zimbra {
if ($header == false) { if ($header == false) {
$header = '<context xmlns="urn:zimbra"> $header = '<context xmlns="urn:zimbra">
<authToken>' . $this->auth_token . '</authToken> <authToken>' . $this->auth_token . '</authToken>
<sessionId id="' . $this->session_id . '">' . $this->session_id . '</sessionId> <sessionId id="' . $this->session_id . '">' . $this->session_id . '</sessionId>
</context>'; </context>';
} }
$soap_message = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> $soap_message = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Header>' . $header . '</soap:Header> <soap:Header>' . $header . '</soap:Header>
<soap:Body>' . $body . '</soap:Body> <soap:Body>' . $body . '</soap:Body>
</soap:Envelope>'; </soap:Envelope>';
$this->message('SOAP message:<textarea>' . $soap_message . '</textarea>'); $this->message('SOAP message:<textarea>' . $soap_message . '</textarea>');
curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $soap_message); curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $soap_message);
@@ -820,7 +821,7 @@ class Zimbra {
return $response; return $response;
} }
// end soapRequest // end soapRequest
/** /**
* getNumSOAPCalls * getNumSOAPCalls
@@ -835,7 +836,7 @@ class Zimbra {
return $this->_num_soap_calls; return $this->_num_soap_calls;
} }
// end getNumSOAPCalls // end getNumSOAPCalls
/** /**
* makeXMLTree * makeXMLTree
@@ -896,7 +897,7 @@ class Zimbra {
return $ret; return $ret;
} }
// end makeXMLTree // end makeXMLTree
/** /**
* &composeArray * &composeArray
@@ -926,7 +927,7 @@ class Zimbra {
return $array; return $array;
} }
// end composeArray // end composeArray
/** /**
* noop * noop
@@ -969,39 +970,41 @@ class Zimbra {
$role = $unserializeOp1['role']; $role = $unserializeOp1['role'];
$location = $unserializeOp1['location']; $location = $unserializeOp1['location'];
$ptst = $unserializeOp1['ptst']; $ptst = $unserializeOp1['ptst'];
$startDate = $unserializeOp1['startDate'];
$endDate = $unserializeOp1['endDate']; $dateFormat=$allDay=="1"?"Ymd":"Ymd\THis";
$timeZone = $unserializeOp1['tz']; $startDate = date($dateFormat,strtotime($unserializeOp1['startDate']));
$endDate = date($dateFormat,strtotime($unserializeOp1['endDate']));
$timeZone = $allDay=="1"?"":$unserializeOp1['tz'];
$explodeEmail = explode(';', $userEmail); $explodeEmail = explode(';', $userEmail);
$explodeFriendlyName = explode(';', $atFriendlyName); $explodeFriendlyName = explode(';', $atFriendlyName);
$countExplodeEmail = count($explodeEmail); $countExplodeEmail = count($explodeEmail);
$soap = '<CreateAppointmentRequest xmlns="urn:zimbraMail"><m> $soap = '<CreateAppointmentRequest xmlns="urn:zimbraMail"><m>
<su>' . $subject . '</su>'; <su>' . $subject . '</su>';
for ($i = 0; $i < $countExplodeEmail; $i++) { for ($i = 0; $i < $countExplodeEmail; $i++) {
$soap.= '<e p="' . $friendlyName . '" a="' . $explodeEmail[$i] . '" t="t"></e>'; $soap.= '<e p="' . $friendlyName . '" a="' . $explodeEmail[$i] . '" t="t"></e>';
} }
$soap.='<inv> $soap.='<inv>
<comp fb="' . $schedule . '" fba="' . $schedule . '" name="' . $appointmentName . '" allDay ="' . $allDay . '" isOrg="' . $isOrg . '" loc="' . $location . '"> <comp fb="' . $schedule . '" fba="' . $schedule . '" name="' . $appointmentName . '" allDay ="' . $allDay . '" isOrg="' . $isOrg . '" loc="' . $location . '">
<s tz="' . $timeZone . '" d="' . $startDate . '"/> <s tz="' . $timeZone . '" d="' . $startDate . '"/>
<e tz="' . $timeZone . '" d="' . $endDate . '"/> <e tz="' . $timeZone . '" d="' . $endDate . '"/>
<or a="' . $username . '@' . $domainName . '" d="' . $friendlyName . '"></or>'; <or a="' . $username . '@' . $domainName . '" d="' . $friendlyName . '"></or>';
for ($i = 0; $i < $countExplodeEmail; $i++) { for ($i = 0; $i < $countExplodeEmail; $i++) {
$soap.='<at role="' . $role . '" ptst="' . $ptst . '" d="' . $explodeFriendlyName[$i] . '" rsvp="' . $rsvp . '" cutype="' . $cutype . '" a="' . $explodeEmail[$i] . '"></at>'; $soap.='<at role="' . $role . '" ptst="' . $ptst . '" d="' . $explodeFriendlyName[$i] . '" rsvp="' . $rsvp . '" cutype="' . $cutype . '" a="' . $explodeEmail[$i] . '"></at>';
} }
$soap.= '</comp> $soap.= '</comp>
</inv> </inv>
<mp ct="multipart/alternative"> <mp ct="multipart/alternative">
<mp ct="text/plain"> <mp ct="text/plain">
<content> <content>
this is a sample Contents this is a sample Contents
</content> </content>
</mp> </mp>
</mp> </mp>
</m> </m>
</CreateAppointmentRequest>'; </CreateAppointmentRequest>';
//G::pr($soap);die;
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -1012,7 +1015,7 @@ class Zimbra {
} }
} }
// end addAppointments // end addAppointments
/** /**
* addTask * addTask
@@ -1035,35 +1038,35 @@ class Zimbra {
$allDay = $unserializeOp1['allDay']; $allDay = $unserializeOp1['allDay'];
$class = $unserializeOp1['class']; $class = $unserializeOp1['class'];
$location = $unserializeOp1['location']; $location = $unserializeOp1['location'];
$dueDate = $unserializeOp1['dueDate']; $dueDate = date("Ymd",strtotime($unserializeOp1['dueDate']));
$status = $unserializeOp1['status']; $status = $unserializeOp1['status'];
$percent = $unserializeOp1['percent']; $percent = $unserializeOp1['percent'];
$soap = '<CreateTaskRequest xmlns="urn:zimbraMail"> $soap = '<CreateTaskRequest xmlns="urn:zimbraMail">
<m l="15"> <m l="15">
<su>' . $subject . '</su> <su>' . $subject . '</su>
<e p="' . $friendlyName . '" a="' . $userEmail . '" t="t"></e> <e p="' . $friendlyName . '" a="' . $userEmail . '" t="t"></e>
<inv> <inv>
<comp allDay="' . $allDay . '" <comp allDay="' . $allDay . '"
name="' . $taskName . '" name="' . $taskName . '"
class="' . $class . '" class="' . $class . '"
priority="' . $priority . '" priority="' . $priority . '"
percentComplete="' . $percent . '" percentComplete="' . $percent . '"
status="' . $status . '" status="' . $status . '"
loc="' . $location . '"> loc="' . $location . '">
<dueDate d="' . $dueDate . '"/> <dueDate d="' . $dueDate . '"/>
</comp> </comp>
</inv> </inv>
<mp ct="multipart/alternative"> <mp ct="multipart/alternative">
<mp ct="text/plain"> <mp ct="text/plain">
<content/> <content/>
</mp> </mp>
</mp> </mp>
</m> </m>
</CreateTaskRequest>'; </CreateTaskRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
$array = $this->makeXMLTree($response); $array = $this->makeXMLTree($response);
@@ -1074,7 +1077,7 @@ class Zimbra {
} }
} }
// end addTask // end addTask
/** /**
* addContacts * addContacts
@@ -1096,13 +1099,13 @@ class Zimbra {
$otherDataValue = $unserializeOp1['otherDataValue']; $otherDataValue = $unserializeOp1['otherDataValue'];
$soap = '<CreateContactRequest xmlns="urn:zimbraMail"> $soap = '<CreateContactRequest xmlns="urn:zimbraMail">
<cn> <cn>
<a n="firstName">' . $firstName . '</a> <a n="firstName">' . $firstName . '</a>
<a n="lastName">' . $lastName . '</a> <a n="lastName">' . $lastName . '</a>
<a n="email">' . $email . '</a> <a n="email">' . $email . '</a>
<a n="' . $otherData . '">' . $otherDataValue . '</a> <a n="' . $otherData . '">' . $otherDataValue . '</a>
</cn> </cn>
</CreateContactRequest>'; </CreateContactRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
@@ -1114,17 +1117,17 @@ class Zimbra {
} }
} }
// end addContacts // end addContacts
/** /**
* addFolder * addFolder
* *
* add Folder in a BriefCase * add Folder in a BriefCase
* *
* @since version 1.0 * @since version 1.0
* @access public * @access public
* @param * @param
* @return * @return
*/ */
public function addFolder($serializeOp1) { public function addFolder($serializeOp1) {
$unserializeOp1 = unserialize($serializeOp1); $unserializeOp1 = unserialize($serializeOp1);
@@ -1133,9 +1136,9 @@ class Zimbra {
$folderColor = $unserializeOp1['color']; $folderColor = $unserializeOp1['color'];
$soap = '<CreateFolderRequest xmlns="urn:zimbraMail"> $soap = '<CreateFolderRequest xmlns="urn:zimbraMail">
<folder name="' . $folderName . '" color="' . $folderColor . '" view="document"> <folder name="' . $folderName . '" color="' . $folderColor . '" view="document">
</folder> </folder>
</CreateFolderRequest>'; </CreateFolderRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if ($response) { if ($response) {
@@ -1147,31 +1150,31 @@ class Zimbra {
} }
} }
// end addFolder // end addFolder
/** /**
* uploadDocument * uploadDocument
* *
* add Folder in a BriefCase * add Folder in a BriefCase
* *
* @since version 1.0 * @since version 1.0
* @access public * @access public
* @param * @param
* @return * @return
*/ */
public function upload($folderId, $UploadId, $fileVersion='', $docId='') { public function upload($folderId, $UploadId, $fileVersion='', $docId='') {
if ($fileVersion == '' && $docId == '') { if ($fileVersion == '' && $docId == '') {
$soap = '<SaveDocumentRequest xmlns="urn:zimbraMail"> $soap = '<SaveDocumentRequest xmlns="urn:zimbraMail">
<doc l="' . $folderId . '"> <doc l="' . $folderId . '">
<upload id="' . $UploadId . '"/> <upload id="' . $UploadId . '"/>
</doc> </doc>
</SaveDocumentRequest>'; </SaveDocumentRequest>';
} else { } else {
$soap = '<SaveDocumentRequest xmlns="urn:zimbraMail"> $soap = '<SaveDocumentRequest xmlns="urn:zimbraMail">
<doc l="' . $folderId . '" ver="' . $fileVersion . '" id="' . $docId . '" > <doc l="' . $folderId . '" ver="' . $fileVersion . '" id="' . $docId . '" >
<upload id="' . $UploadId . '"/> <upload id="' . $UploadId . '"/>
</doc> </doc>
</SaveDocumentRequest>'; </SaveDocumentRequest>';
} }
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
@@ -1186,7 +1189,7 @@ class Zimbra {
} }
} }
// end uploadDocument // end uploadDocument
/** /**
* getDocId * getDocId
@@ -1200,8 +1203,8 @@ class Zimbra {
*/ */
public function getDocId($folderId, $fileName) { public function getDocId($folderId, $fileName) {
$soap = '<GetItemRequest xmlns="urn:zimbraMail"> $soap = '<GetItemRequest xmlns="urn:zimbraMail">
<item l="' . $folderId . '" name="' . $fileName . '" /> <item l="' . $folderId . '" name="' . $fileName . '" />
</GetItemRequest>'; </GetItemRequest>';
$response = $this->soapRequest($soap); $response = $this->soapRequest($soap);
if (is_array($response)) { if (is_array($response)) {
@@ -1215,7 +1218,7 @@ class Zimbra {
} }
} }
// end getDocId // end getDocId
} }
// end Zimbra class // end Zimbra class

View File

@@ -31,7 +31,7 @@
* @name getZimbraFolder * @name getZimbraFolder
* @label Get Attributes for specified FolderName * @label Get Attributes for specified FolderName
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username | Valid username to connect to Zimbra server * @param string | $username | Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $folderName | Folder Name * @param string | $folderName | Folder Name
@@ -66,7 +66,7 @@ function getZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName) {
* @name getZimbraContactList * @name getZimbraContactList
* @label Get Contact Lists from Zimbra Server * @label Get Contact Lists from Zimbra Server
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username| Valid username to connect to Zimbra server * @param string | $username| Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* *
@@ -98,7 +98,7 @@ function getZimbraContactList($ServerUrl, $username, $preAuthKey) {
* @name getZimbraTaskList * @name getZimbraTaskList
* @label Get Task Lists from Zimbra Server * @label Get Task Lists from Zimbra Server
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username| Valid username to connect to Zimbra server * @param string | $username| Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* *
@@ -128,12 +128,12 @@ function getZimbraTaskList($ServerUrl, $username, $preAuthKey) {
/** /**
* @method * @method
* *
* Get Appointment List * Get Appointment List
* *
* @name getZimbraAppointmentList * @name getZimbraAppointmentList
* @label Get Appointment Lists from Zimbra Server * @label Get Appointment Lists from Zimbra Server
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username| Valid username to connect to Zimbra server * @param string | $username| Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* *
@@ -168,11 +168,11 @@ function getZimbraAppointmentList($ServerUrl, $username, $preAuthKey) {
* @name createZimbraFolder * @name createZimbraFolder
* @label Create Specified Folder with Attributes in Briefcase Tab * @label Create Specified Folder with Attributes in Briefcase Tab
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username | Valid username to connect to Zimbra server * @param string | $username | Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $folderName | Folder Name * @param string | $folderName | Folder Name
* @param string | $color | Color of Folder * @param string | $color | Color of Folder
* *
* @return string | $result | Response * @return string | $result | Response
* *
@@ -199,12 +199,12 @@ function createZimbraFolder($ServerUrl, $username, $preAuthKey, $folderName, $co
/** /**
* @method * @method
* *
* Create Contacts * Create Contacts
* *
* @name createZimbraContacts * @name createZimbraContacts
* @label Create Contacts in Address Book * @label Create Contacts in Address Book
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username | Valid username to connect to Zimbra server * @param string | $username | Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $firstName | First Name * @param string | $firstName | First Name
@@ -245,10 +245,10 @@ function createZimbraContacts($ServerUrl, $username, $preAuthKey, $firstName, $l
* @name createZimbraTask * @name createZimbraTask
* @label Create Task * @label Create Task
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username | Valid username to connect to Zimbra server * @param string | $username | Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $subject | Mail Subject * @param string | $subject | Mail Subject
* @param string | $taskName | Task Name * @param string | $taskName | Task Name
* @param string | $friendlyName | Friendly Name of the User * @param string | $friendlyName | Friendly Name of the User
* @param string | $userEmail | Email Address of the User * @param string | $userEmail | Email Address of the User
@@ -264,14 +264,13 @@ function createZimbraContacts($ServerUrl, $username, $preAuthKey, $firstName, $l
* *
*/ */
function createZimbraTask($ServerUrl, $username, $preAuthKey, $subject, $taskName, $friendlyName, $userEmail, $priority, $allDay, $class, $location, $dueDate, $status, $percent) { function createZimbraTask($ServerUrl, $username, $preAuthKey, $subject, $taskName, $friendlyName, $userEmail, $priority, $allDay, $class, $location, $dueDate, $status, $percent) {
$serializeOp = array(); $serializeOp = array();
$serializeOp = array('subject' => $subject, 'taskName' => $taskName, 'friendlyName' => $friendlyName, 'userEmail' => $userEmail, 'priority' => $priority, 'allDay' => $allDay, 'class' => $class, 'location' => $location, 'dueDate' => $dueDate, 'status' => $status, 'percent' => $percent); $serializeOp = array('subject' => $subject, 'taskName' => $taskName, 'friendlyName' => $friendlyName, 'userEmail' => $userEmail, 'priority' => $priority, 'allDay' => $allDay, 'class' => $class, 'location' => $location, 'dueDate' => $dueDate, 'status' => $status, 'percent' => $percent);
$serializeOp1 = serialize($serializeOp); $serializeOp1 = serialize($serializeOp);
$zimbra = new Zimbra($username, $ServerUrl, $preAuthKey); $zimbra = new Zimbra($username, $ServerUrl, $preAuthKey);
$connectionResult = $zimbra->connect();
$connectionResult = $zimbra->connect();
if (!$connectionResult) { if (!$connectionResult) {
return "Check userName or Server URL"; return "Check userName or Server URL";
} }
@@ -292,10 +291,10 @@ function createZimbraTask($ServerUrl, $username, $preAuthKey, $subject, $taskNam
* @name createZimbraAppointment * @name createZimbraAppointment
* @label Create Appointment * @label Create Appointment
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username | Valid username to connect to Zimbra server * @param string | $username | Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $subject | Mail Subject * @param string | $subject | Mail Subject
* @param string | $appointmentName | Appointment Name * @param string | $appointmentName | Appointment Name
* @param string | $friendlyName | Organizer's Friendly Name * @param string | $friendlyName | Organizer's Friendly Name
* @param string | $userEmail | Email Address of the Attendee(s) seperated by ';' * @param string | $userEmail | Email Address of the Attendee(s) seperated by ';'
@@ -345,7 +344,7 @@ function createZimbraAppointment($ServerUrl, $username, $preAuthKey, $subject, $
* @name uploadZimbraFile * @name uploadZimbraFile
* @label Upload File/Document to Zimbra Server * @label Upload File/Document to Zimbra Server
* *
* @param string | $ServerUrl | Server name and port where Zimbra exists | http://localhost:7070/service/soap * @param string | $ServerUrl | Server name and port where Zimbra exists | zimbra.server:port
* @param string | $username | Valid username to connect to Zimbra server * @param string | $username | Valid username to connect to Zimbra server
* @param string | $preAuthKey | Server Key for SSO authentication * @param string | $preAuthKey | Server Key for SSO authentication
* @param string | $folderName | Folder Name * @param string | $folderName | Folder Name
@@ -357,42 +356,53 @@ function createZimbraAppointment($ServerUrl, $username, $preAuthKey, $subject, $
function uploadZimbraFile($ServerUrl, $username, $preAuthKey, $folderName, $fileLocation) { function uploadZimbraFile($ServerUrl, $username, $preAuthKey, $folderName, $fileLocation) {
$header_array = array("ENCTYPE" => "multipart/form-data"); $header_array = array("ENCTYPE" => "multipart/form-data");
$credentials = "root:solutions";
$options = array(headers => $header_array,
httpauth => $credentials,
httpauthtype => HTTP_AUTH_BASIC); //1. test without the credentials
$file = $fileLocation; $file = $fileLocation;
$oZimbraObj = new Zimbra($username, $ServerUrl, $preAuthKey); $oZimbraObj = new Zimbra($username, $ServerUrl, $preAuthKey);
$connectResult = $oZimbraObj->connect(); $connectResult = $oZimbraObj->connect();
$sAuthToken = $oZimbraObj->auth_token; $sAuthToken = $oZimbraObj->auth_token;
$cookie = array('ZM_AUTH_TOKEN' => $sAuthToken, 'ZM_TEST' => true); $cookie = array('ZM_AUTH_TOKEN' => $sAuthToken, 'ZM_TEST' => true);
$cookie = 'ZM_AUTH_TOKEN=' . $sAuthToken. '; ZM_TEST='. true;
$url = "http://$ServerUrl/service/upload?fmt=raw"; $url = "http://$ServerUrl/service/upload?fmt=raw";
$request = new HttpRequest($url, HTTP_METH_POST); $params = array (
$request->setCookies($cookie); 'uploadFile' => "@$file"
$request->addPostFile("uploadFile", $file); // 2. test without 1st parameter );
$request->addPostFields(array($options)); $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$sendResult = $request->send(); //curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
// gettin Upload ID curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$aResponce = (array) $sendResult; curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$counter = 0; curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
foreach ($aResponce as $values) { curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$counter++; curl_setopt ($ch, CURLOPT_BINARYTRANSFER, true);
if ($counter == 2) { curl_setopt ($ch, CURLOPT_COOKIESESSION, true);
$sResponce = $values; curl_setopt ($ch, CURLOPT_FRESH_CONNECT, true);
} curl_setopt ($ch, CURLOPT_HEADER, true);
curl_setopt ($ch, CURLOPT_NOPROGRESS, false);
curl_setopt ($ch, CURLOPT_VERBOSE, true);
curl_setopt ($ch, CURLOPT_HTTPHEADER,$header_array);
if( ! $response = curl_exec($ch))
{
return "Upload error. Connection Error";
} }
//G::pr($response);
$header_size = curl_getinfo($ch,CURLINFO_HEADER_SIZE);
$result['header'] = substr($response, 0, $header_size);
$result['body'] = substr( $response, $header_size );
$result['http_code'] = curl_getinfo($ch,CURLINFO_HTTP_CODE);
$result['last_url'] = curl_getinfo($ch,CURLINFO_EFFECTIVE_URL);
$aString = array(); $aString = array();
$aExplode = explode(",", $sResponce); $aExplode = explode(",", $result['body']);
$uploadID = substr($aExplode[2], 1, -2); $uploadID = substr($aExplode[2], 1, -2);
// gettin FOlder ID curl_close($ch);
// gettin FOlder ID
$FolderResult = $oZimbraObj->getFolder($folderName); $FolderResult = $oZimbraObj->getFolder($folderName);
if (isset($FolderResult['id'])) { if (isset($FolderResult['id'])) {