0

在网上搜索了几个小时后,你是我最后的希望:

我必须构建一个系统来读取来自 Microsoft Exchange Server 的发送和传入邮件。我为此找到了以下脚本:Exchange-Web-Services-for-PHP (Heartspring) https://github.com/Heartspring/Exchange-Web-Services-for-PHP

现有的 get_messages() 函数返回文件夹的所有消息,例如“收件箱”。到目前为止,一切都清楚了。当我想从“已发送”-文件夹中获取所有消息时,我的问题就开始了-我尝试了很多词,从“发送”到“已发送邮件”;没有任何结果(邮箱不可用)

我的想法是获取文件夹“root”的所有子文件夹并写下:

include "init.php";

$ec = new ExchangeClient();
$ec->init("bambullis@123.de", "", NULL, "https://amxprd3610.outlook.com/EWS/Services.wsdl");

$folders = $ec->get_subfolders("root"); 

foreach($folders as $folder) {

    print_r($folder); 

}

这就是我得到的:

stdClass Object
(
    [FolderId] => stdClass Object
        (
            [Id] => AAAeAGJhbWJ1bGxpc0BzdHVrZSbi5kZQAuAAAAAABw352p5E4yS5voYF9ELBmiAQBXYPdO6NZAQ6T9C3xviT7xAAAAC1iXAAA=
            [ChangeKey] => AQAAABYAAABXYPdO6NZAQ6T9C3xviAALNCey
        )

    [DisplayName] => Oberste Ebene des Informationsspeichers
    [TotalCount] => 0
    [ChildFolderCount] => 16
    [UnreadCount] => 0
)

(我知道 FolderId->Id 是 base64 编码的,出于安全原因,我已经修改了上面的字符串;o))

现在我试图列出这个目录的子文件夹(我添加了一个邮箱来查看,如果值“ChildFolderCount”会改变,它会改变):

...
print_r($folder); 

print_r($ec->get_subfolders($folder->FolderId->Id)); 
...

这是我得到的错误:请求模式验证失败:“Id”属性无效

我做错什么了?如何递归地从“root”获取所有子文件夹?感谢这个可以帮助我的可爱的人!

4

1 回答 1

2

EWS-PHP get_subfolders方法默认使用TraversalTypeShallow ”,因此它仅搜索已识别的文件夹并仅返回未删除项目的文件夹 ID。
要在已识别父文件夹的所有子文件夹中搜索并仅返回未删除项目的文件夹 ID,您应该使用“ Deep ”TraversalType。
例如:

<?php

include "init.php";

class myExchangeClient extends ExchangeClient {
    public function get_subfolders_deep($ParentFolderId = "inbox", $Distinguished = TRUE) {
        $this->setup();

        $FolderItem = new stdClass();
        $FolderItem->FolderShape = new stdClass();
        $FolderItem->ParentFolderIds = new stdClass();

        $FolderItem->FolderShape->BaseShape = "Default";
        /* 
        **  See http://msdn.microsoft.com/en-us/library/exchange/exchangewebservices.folderquerytraversaltype(v=exchg.140).aspx 
        **  Deep Traversal: Searches in all subfolders of the identified parent folder and returns only the folder IDs for items that
        **  have not been deleted.
        */
        $FolderItem->Traversal = "Deep";

        if ($Distinguished) {
          $FolderItem->ParentFolderIds->DistinguishedFolderId = new stdClass();
          $FolderItem->ParentFolderIds->DistinguishedFolderId->Id = $ParentFolderId;
        } else {
          $FolderItem->ParentFolderIds->FolderId = new stdClass();
          $FolderItem->ParentFolderIds->FolderId->Id = $ParentFolderId;
        }

        $response = $this->client->FindFolder($FolderItem);

        if ($response->ResponseMessages->FindFolderResponseMessage->ResponseCode == "NoError") {
          $folders = array();

          if (!is_array($response->ResponseMessages->FindFolderResponseMessage->RootFolder->Folders->Folder)) {
              $folders[] = $response->ResponseMessages->FindFolderResponseMessage->RootFolder->Folders->Folder;
          } else {
              $folders = $response->ResponseMessages->FindFolderResponseMessage->RootFolder->Folders->Folder;
          }

          return $folders;
        } else {
          $this->lastError = $response->ResponseMessages->FindFolderResponseMessage->ResponseCode;
        }
    }
}

$ec = new myExchangeClient();
$ec->init("bambullis@123.de", "", NULL, "https://amxprd3610.outlook.com/EWS/Services.wsdl");

$folders = $ec->get_subfolders_deep("root");
echo "<pre>".print_r($folders,true)."</pre>\n";

?>

无论如何,查看ExchangeClient类源代码,发送项目的 FolderID 应该是“ sentitems ”。

于 2012-09-15T19:08:45.110 回答