Php GMAIL Zend IMAP如何获取特定消息的id
我试图在使用PHP编程时使用GMAIL api实现Zend IMAP框架 一切顺利,我收到了邮件-电子邮件(发件人/收件人),但出于存储目的,我需要邮件的唯一id 有什么办法可以做到吗?我使用标准代码 非常感谢,希望这个问题描述得足够清楚 我想要唯一消息id的原因是我需要存储数据。 如果不使用唯一id,则无法将消息与数据库中的内容进行比较,zend中给出的messagenumber如示例8所示。如果我随后删除了第7条消息,那么第8条消息将变成第7条消息,这使得它不是很有用 我知道我必须使用:X-GM-MSGID,但我不知道放在哪里。。。当我把它放在我的取回中时,它不起作用:Php GMAIL Zend IMAP如何获取特定消息的id,php,zend-framework,gmail,imap,Php,Zend Framework,Gmail,Imap,我试图在使用PHP编程时使用GMAIL api实现Zend IMAP框架 一切顺利,我收到了邮件-电子邮件(发件人/收件人),但出于存储目的,我需要邮件的唯一id 有什么办法可以做到吗?我使用标准代码 非常感谢,希望这个问题描述得足够清楚 我想要唯一消息id的原因是我需要存储数据。 如果不使用唯一id,则无法将消息与数据库中的内容进行比较,zend中给出的messagenumber如示例8所示。如果我随后删除了第7条消息,那么第8条消息将变成第7条消息,这使得它不是很有用 我知道我必须使用:X-
$test = $imap->fetch("X-GM-MSGID", null, $emailto);
public function fetch($items, $from, $to = null)
{
if (is_array($from)) {
$set = implode(',', $from);
} else if ($to === null) {
$set = (int)$from;
} else if ($to === INF) {
$set = (int)$from . ':*';
} else {
$set = (int)$from . ':' . (int)$to;
}
$items = (array)$items;
$itemList = $this->escapeList($items);
$this->sendRequest('FETCH', array($set, $itemList), $tag);
$result = array();
while (!$this->readLine($tokens, $tag)) {
// ignore other responses
if ($tokens[1] != 'FETCH') {
continue;
}
// ignore other messages
if ($to === null && !is_array($from) && $tokens[0] != $from) {
continue;
}
// if we only want one item we return that one directly
if (count($items) == 1) {
if ($tokens[2][0] == $items[0]) {
$data = $tokens[2][1];
} else {
// maybe the server send an other field we didn't wanted
$count = count($tokens[2]);
// we start with 2, because 0 was already checked
for ($i = 2; $i < $count; $i += 2) {
if ($tokens[2][$i] != $items[0]) {
continue;
}
$data = $tokens[2][$i + 1];
break;
}
}
} else {
$data = array();
while (key($tokens[2]) !== null) {
$data[current($tokens[2])] = next($tokens[2]);
next($tokens[2]);
}
}
// if we want only one message we can ignore everything else and just return
if ($to === null && !is_array($from) && $tokens[0] == $from) {
// we still need to read all lines
while (!$this->readLine($tokens, $tag));
return $data;
}
$result[$tokens[0]] = $data;
}
if ($to === null && !is_array($from)) {
/**
* @see Zend_Mail_Protocol_Exception
*/
require_once 'Zend/Mail/Protocol/Exception.php';
throw new Zend_Mail_Protocol_Exception('the single id was not found in response');
}
return $result;
}
$test=$imap->fetch(“X-GM-MSGID”,null,$emailto);
公共函数fetch($items,$from,$to=null)
{
if(is_数组($from)){
$set=内爆(“,”,$from);
}else if($to==null){
$set=(int)$from;
}else if($to==INF){
$set=(int)$from.:*;
}否则{
$set=(int)$from.':'(int)$to;
}
$items=(数组)$items;
$itemList=$this->escapeList($items);
$this->sendRequest('FETCH',array($set,$itemList),$tag);
$result=array();
而(!$this->readLine($tokens,$tag)){
//忽略其他回应
如果($tokens[1]!='FETCH'){
继续;
}
//忽略其他消息
if($to==null&&!is_数组($from)&&$tokens[0]!=$from){
继续;
}
//如果我们只需要一个项目,我们直接返回一个
如果(计数($项目)=1){
如果($tokens[2][0]=$items[0]){
$data=$tokens[2][1];
}否则{
//也许服务器发送了另一个我们不想要的字段
$count=count($tokens[2]);
//我们从2开始,因为已经检查了0
对于($i=2;$i<$count;$i+=2){
如果($tokens[2][$i]!=$items[0]){
继续;
}
$data=$tokens[2][$i+1];
打破
}
}
}否则{
$data=array();
while(key($tokens[2])!==null){
$data[current($tokens[2])]=next($tokens[2]);
接下来($tokens[2]);
}
}
//如果我们只想要一条信息,我们可以忽略其他信息,然后返回
if($to==null&&!is_数组($from)&&$tokens[0]==from){
//我们仍然需要阅读所有的文字
而(!$this->readLine($tokens,$tag));
返回$data;
}
$result[$tokens[0]]=$data;
}
如果($to==null&&!是_数组($from)){
/**
*@参见Zend_邮件_协议_异常
*/
需要_once“Zend/Mail/Protocol/Exception.php”;
抛出新的Zend_邮件_协议_异常(“响应中未找到单个id”);
}
返回$result;
}
出于某种原因,从IMAP类中提取时,它可以正常工作
只需将它传递给您的其他类并按您的意愿使用它您真的需要Gmail ID还是UID,这是标准的IMAP,所有服务器都支持它?您好。。。我需要GMAIL的ID。。由于它对所有消息都是唯一的,所以现在解决了。。。这并不像我想的那么难:)我把我的解决方案写在下面。
public function getMessage($id)
{
$data = $this->_protocol->fetch(array('FLAGS', 'RFC822.HEADER', 'RFC822.TEXT', 'X-GM-MSGID'), $id);
$header = $data['RFC822.HEADER'];
$content = $data['RFC822.TEXT'];
$messageid = $data['X-GM-MSGID'];
var_dump($messageid);
$flags = array();
foreach ($data['FLAGS'] as $flag) {
$flags[] = isset(self::$_knownFlags[$flag]) ? self::$_knownFlags[$flag] : $flag;
}
return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $header, 'content' => $content, 'flags' => $flags, 'messageid' => $messageid));
}