【问题标题】:imap_msgno() returns 0 for an uid returned form imap_search()imap_msgno() 为从 imap_search() 返回的 uid 返回 0
【发布时间】:2014-07-10 19:20:45
【问题描述】:

我不确定如何调试它,函数imap_msgno() 返回 0 而不是消息号,没有任何错误。这是导致问题的代码部分(带有调试信息):

// Retrieve and order emails
$search = imap_search($this->open, 'SINCE "' . $date . '"');
$sorted_search = $this->order_search($search, $sorted);

// Store all the messages
$Messages = array();
foreach($sorted_search as $msgUID) {
  $msgNo  = imap_msgno ($this->open, $msgUID);
  $header = imap_header($this->open, $msgNo);

  var_dump($msgUID);
  var_dump($msgNo);
  if (empty($header->message_id)) {
    var_dump($header);
    }
  else {
    echo "Good";
    }
  echo " | ";

  // mode code ...
  }

这应该返回许多int (12) int (10) Good | int (11) int (9) Good | ...。然而,事实并非如此,它返回这个(为清楚起见添加了返回):

int(12) int(10) Good |
int(11) int(9) Good |
int(10) int(0) bool(false) |
int(9) int(0) bool(false) |
int(8) int(8) Good | 
...

如您所见,$msgNo 似乎是正确的。 function imap_msgno() in the documentation 没有提供有关无效$msgNo 行为的更多信息,我认为它应该是有效的$msgNo,因为它是返回的imap_search() 的一部分。知道如何调试它或哪里出错了吗?

【问题讨论】:

  • 你在混用 UIDS 和消息序列号吗?

标签: php email imap


【解决方案1】:

除非在 order_search 调用中设置它们,否则您将返回消息编号而不是唯一 ID。如果您在 imap_search 调用中设置选项 SE_UID,例如

$search = imap_search($this->open, 'SINCE "' . $date . '"', SE_UID);

您应该获得唯一的 ID。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-11
    • 2015-06-21
    • 2022-01-23
    • 2015-06-15
    • 1970-01-01
    • 2012-06-15
    • 2014-05-01
    相关资源
    最近更新 更多