【问题标题】:How to search inbox using zend mail如何使用zend邮件搜索收件箱
【发布时间】:2011-06-02 03:17:48
【问题描述】:

以下是来自 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() 必须 是一个数组,给定字符串,调用 在...

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

【问题讨论】:

  • 嗨,鲍勃,你有没有想过这个问题?我现在正在尝试做同样的事情。
  • 不,但我通过将代码从 zend_mail 重写到 php_imap 库发现了类似的功能:php.net/manual/en/ref.imap.php

标签: php email zend-framework zend-mail


【解决方案1】:

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

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

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

现在你应该可以这样打电话了

$storage->search(array('SUBJECT "test","UNSEEN",'FROM "santa@northpole.org"'));

结果应该是消息的 ids/uids 列表,就像 imap_search 一样。 恕我直言,此函数或协议的 getter 应该在存储类中,但它不是。

【讨论】:

    【解决方案2】:

    我就是这样做的

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

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

    【讨论】:

      【解决方案3】:

      怎么样

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

      【讨论】:

      • 我试过这个并且得到一个不同的致命错误“致命错误:调用未定义的方法 Zend_Mail_Storage_Imap::search() in...”
      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 2017-12-04
      • 2011-02-27
      • 2021-04-27
      • 1970-01-01
      • 2012-07-03
      • 2017-12-21
      • 2017-07-23
      相关资源
      最近更新 更多