简体   繁体   中英

Get message in Zimbra by php zimbra-api

I use PHP Zimbra-API and try to get messages by search request. My request is

$req = new \Zimbra\Mail\Request\Search();

$req->setQuery('Mail Delivery System in:inbox')
                ->setResultMode('IDS')
                ->setField('subject')
                ->setSearchTypes('message')
                ->setLimit(1000);

How can I get response? I didn't find any method of Search like getRespone() or something else. Or my request is incorrect?

The code

They recently added a doc section showing exactly your use case in docs/usage.md :

<?php declare(strict_types=1);

require_once 'vendor/autoload.php';

use Zimbra\Mail\MailApi;

$query = 'in:inbox';

$api = new MailApi('https://zimbra.server/service/soap');
$api->authByAccountName($accountName, $password);
$response = $api->search($query, FALSE, 'message');
$messages = $response->getMessageHits(); //$messages contains the results

The function

The search() function used by the example and defined in src/Mail/MailApi.php has all the parameters needed for pagination and other stuff

public function search(
    ?string $query = NULL,
    ?bool $inDumpster = NULL,
    ?string $searchTypes = NULL,
    ?string $groupBy = NULL,
    ?int $calItemExpandStart = NULL,
    ?int $calItemExpandEnd = NULL,
    ?bool $quick = NULL,
    ?SearchSortBy $sortBy = NULL,
    ?bool $includeTagDeleted = NULL,
    ?bool $includeTagMuted = NULL,
    ?string $taskStatus = NULL,
    ?string $fetch = NULL,
    ?bool $markRead = NULL,
    ?int $maxInlinedLength = NULL,
    ?bool $wantHtml = NULL,
    ?bool $needCanExpand = NULL,
    ?bool $neuterImages = NULL,
    ?WantRecipsSetting $wantRecipients = NULL,
    ?bool $prefetch = NULL,
    ?string $resultMode = NULL,
    ?bool $fullConversation = NULL,
    ?string $field = NULL,
    ?int $limit = NULL,
    ?int $offset = NULL,
    array $headers = [],
    ?CalTZInfo $calTz = NULL,
    ?string $locale = NULL,
    ?CursorInfo $cursor = NULL,
    ?MsgContent $wantContent = NULL,
    ?bool $includeMemberOf = NULL,
    ?bool $warmup = NULL
): ?Message\SearchResponse

Query Syntax

Regarding the query syntax please refer to the official Zimbra documentation

The "Search Language Structure" described is a common standard between webmail usage, Rest API and Soap API (the one used by this library)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM