public function GetFoldersList($arFilter) { $this->ClearErrors(); $request = $this->CreateSOAPRequest("POST", $this->GetPath()); $request->AddHeader("Content-Type", "text/xml; charset=utf-8"); $request->AddHeader("SOAPAction", "http://schemas.microsoft.com/exchange/services/2006/messages/FindFolder"); $request->AddHeader("Connection", "Keep-Alive"); $arMapTmp = array("mailbox" => "Mailbox", "id" => "Id", "xml_id" => "Id"); CDavExchangeClient::NormalizeArray($arFilter, $arMapTmp); $arParentFolderId = array(); if (array_key_exists("Id", $arFilter)) { $arParentFolderId["id"] = $arFilter["Id"]; } else { $arParentFolderId["id"] = "inbox"; } if (array_key_exists("Mailbox", $arFilter)) { $arParentFolderId["mailbox"] = $arFilter["Mailbox"]; } $request->CreateFindFolderBody($arParentFolderId, "AllProperties"); $this->Connect(); $response = $this->Send($request); $this->Disconnect(); if (is_null($response)) { return null; } if ($this->ParseError($response)) { return null; } $arResultFoldersList = array(); $xmlDoc = $response->GetBodyXml(); $arResponseMessage = $xmlDoc->GetPath("/Envelope/Body/FindFolderResponse/ResponseMessages/FindFolderResponseMessage"); foreach ($arResponseMessage as $responseMessage) { $arResponseCode = $responseMessage->GetPath("/FindFolderResponseMessage/ResponseCode"); $responseCode = null; if (count($arResponseCode) > 0) { $responseCode = $arResponseCode[0]->GetContent(); } $responseClass = $responseMessage->GetAttribute("ResponseClass"); if (!is_null($responseClass) && $responseClass != "Success" || !is_null($responseCode) && $responseCode != "NoError") { $arMessageText = $responseMessage->GetPath("/FindFolderResponseMessage/MessageText"); $messageText = "Error"; if (count($arMessageText) > 0) { $messageText = $arMessageText[0]->GetContent(); } $this->AddError(!is_null($responseCode) ? $this->Encode($responseCode) : $this->Encode($responseClass), $this->Encode($messageText)); continue; } $arMailFolder = $responseMessage->GetPath("/FindFolderResponseMessage/RootFolder/Folders/Folder"); foreach ($arMailFolder as $mailFolder) { $arResultFoldersList[] = $this->ConvertMailFolderToArray($mailFolder); } } return $arResultFoldersList; }
public function CreateGetFolderBody($folderId = null, $folderShape = "AllProperties") { $arMapTmp = array("idonly" => "IdOnly", "id_only" => "IdOnly", "allproperties" => "AllProperties", "all_properties" => "AllProperties"); $folderShapeLower = strtolower($folderShape); if (array_key_exists($folderShapeLower, $arMapTmp)) { $folderShape = $arMapTmp[$folderShapeLower]; } else { $folderShape = "AllProperties"; } $this->body = "<" . "?xml version=\"1.0\" encoding=\"utf-8\"?" . ">\r\n"; $this->body .= "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n"; $this->body .= " <soap:Body>\r\n"; $this->body .= " <GetFolder xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">\r\n"; $this->body .= " <FolderShape>\r\n"; $this->body .= " <BaseShape xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">" . $folderShape . "</BaseShape>\r\n"; $this->body .= " </FolderShape>\r\n"; $this->body .= " <FolderIds>\r\n"; if (!is_array($folderId)) { $folderId = array("id" => $folderId); } $arKeys = array_keys($folderId); if (count($folderId) > 0) { if ($arKeys[0] . "!" != "0!") { $folderId = array($folderId); } } $arMapTmp = array("mailbox" => "Mailbox", "id" => "Id", "xml_id" => "Id", "changekey" => "ChangeKey", "modification_label" => "ChangeKey"); foreach ($folderId as $value) { CDavExchangeClient::NormalizeArray($value, $arMapTmp); $id = isset($value["Id"]) ? $value["Id"] : null; $changekey = isset($value["ChangeKey"]) ? $value["ChangeKey"] : null; $mailbox = isset($value["Mailbox"]) ? $value["Mailbox"] : null; if (!in_array($id, self::$arDistinguishedFolderIdNameType)) { $this->body .= " <FolderId Id=\"" . htmlspecialcharsbx($id) . "\""; if (!is_null($changekey) && !empty($changekey)) { $this->body .= " ChangeKey=\"" . htmlspecialcharsbx($changekey) . "\""; } $this->body .= " xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\"/>\r\n"; } else { $this->body .= " <DistinguishedFolderId Id=\"" . htmlspecialcharsbx($id) . "\""; if (!is_null($changekey) && !empty($changekey)) { $this->body .= " ChangeKey=\"" . htmlspecialcharsbx($changekey) . "\""; } $this->body .= " xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\""; if (!is_null($mailbox) && !empty($mailbox)) { $this->body .= "><Mailbox><EmailAddress>" . htmlspecialcharsbx($mailbox) . "</EmailAddress></Mailbox></DistinguishedFolderId>\r\n"; } else { $this->body .= "/>\r\n"; } } } $this->body .= " </FolderIds>\r\n"; $this->body .= " </GetFolder>\r\n"; $this->body .= " </soap:Body>\r\n"; $this->body .= "</soap:Envelope>"; }