如何使用 zend mail 搜索收件箱

发布于 2024-10-09 18:02:25 字数 1176 浏览 3 评论 0原文

以下是 zend_mail_protocol_imap 中的函数。我读到它是为了搜索电子邮件,我想使用 zend_mail_storage_imap 覆盖它(这就是我现在用来从 gmail 获取电子邮件的方法)。我将以下函数复制并粘贴到 zend_mail_storage_imap 中,但我遇到了参数问题。我找不到有关数组 $params 的使用内容的文档。在更彻底地阅读之前,我最初以为这是搜索词。我没主意了。这是函数...

/**
 * do a search request
 *
 * This method is currently marked as internal as the API might change and is not
 * safe if you don't take precautions.
 *
 * @internal
 * @return array message ids
 */
public function search(array $params)
{                                                                                    
    $response = $this->requestAndResponse('SEARCH', $params);
    if (!$response) {
        return $response;
    }

    foreach ($response as $ids) {
        if ($ids[0] == 'SEARCH') {
            array_shift($ids);
            return $ids;
        }
    }
    return array();
}

最初我认为这可以解决问题...

$storage = new Zend_Mail_Storage_Imap($imap);

$searchresults = $storage->search('search term');   

这是错误消息:

可捕获的致命错误:参数 1 传递给 Zend_Mail_Storage_Imap::search() 必须 是一个数组,给定的字符串,称为 在...

但是不,我需要以数组形式发送信息。有什么想法吗?

The following is a function from zend_mail_protocol_imap. i read that to search emails, I would want to override it using zend_mail_storage_imap (which is what I'm using now to grab email from gmail). I copy and pasted the following function into zend_mail_storage_imap, but I'm having issues with the params. I can't find documentation on what to use for the array $params. I initially thought it was the search term before reading it more thoroughly. I'm out of ideas. Here's the function...

/**
 * do a search request
 *
 * This method is currently marked as internal as the API might change and is not
 * safe if you don't take precautions.
 *
 * @internal
 * @return array message ids
 */
public function search(array $params)
{                                                                                    
    $response = $this->requestAndResponse('SEARCH', $params);
    if (!$response) {
        return $response;
    }

    foreach ($response as $ids) {
        if ($ids[0] == 'SEARCH') {
            array_shift($ids);
            return $ids;
        }
    }
    return array();
}

Initially I thought this would do the trick...

$storage = new Zend_Mail_Storage_Imap($imap);

$searchresults = $storage->search('search term');   

Here's the error message:

Catchable fatal error: Argument 1
passed to
Zend_Mail_Storage_Imap::search() must
be an array, string given, called
in...

But nope, I need to send the info in an array. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各自安好 2024-10-16 18:02:25

怎么样

$searchresults = $storage->search(array('search term'));

How about

$searchresults = $storage->search(array('search term'));
童话 2024-10-16 18:02:25

这就是我的做法

$searchTerm = 'TEXT ' . $searchTerm ;
$searchresults = $storage->search(array($searchTerm));

zend 的搜索参数与 imap_search 的相同。使用 http://php.net/manual/en/function.imap-search。 php 以供进一步参考。

this is how i did it

$searchTerm = 'TEXT ' . $searchTerm ;
$searchresults = $storage->search(array($searchTerm));

Search parameter for zend is same as of imap_search . Use http://php.net/manual/en/function.imap-search.php for further reference .

写给空气的情书 2024-10-16 18:02:25

storage\imap 中(仍然)没有搜索功能,该功能实际上位于协议类中。

要在 storage\imap 中进行搜索,请添加此函数:

public function search($params = null) {
    return $this->protocol->search($params);
}

现在您应该能够像这样调用

$storage->search(array('SUBJECT "test","UNSEEN",'FROM "[email protected]"'));

,结果应该是消息的 ids/uids 列表,就像 imap_search 一样。
恕我直言,这个函数或协议的 getter 应该位于存储类中,但事实并非如此。

there is (still) no search function in storage\imap, that function is actually in the protocol class.

to have a search in storage\imap add this function:

public function search($params = null) {
    return $this->protocol->search($params);
}

now you should be able to call like this

$storage->search(array('SUBJECT "test","UNSEEN",'FROM "[email protected]"'));

and the result should be a list of ids/uids of the messages, just like imap_search.
imho this function or a getter for protocol should be in the storage class, but it isnt.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文