I have a e-mail driver. It get a list of e-mail accounts and receive and store messages, it works fine. But the messages deletion, at last line, doesn't works. Thats a part of code:
$arrPop3Config['host'] = $arrEmailconfiguracao['strPOPHost'];
$arrPop3Config['port'] = $arrEmailconfiguracao['intPOPPorta'];
$arrPop3Config['user'] = $arrEmailconfiguracao['strPOPUsuario'];
$arrPop3Config['password'] = $arrEmailconfiguracao['strPOPSenha'];
if($arrEmailconfiguracao['intAuth'] == '1') {
$arrPop3Config['ssl'] = 'SSL';
} else if($arrEmailconfiguracao['intAuth'] == '2') {
$arrPop3Config['ssl'] = 'TLS';
}
$objMail = new Zend_Mail_Storage_Pop3($arrPop3Config);
foreach($objMail as $intMensagemNum => $objMensagem) {
$strMensagemUniqueId = $objMail->getUniqueId($intMensagemNum);
$arrHeader = $objMensagem->getHeaders();
$strRemetente = $objMensagem->getHeader('from', 'string');
preg_match_all("/(.*)?<(.*)?>/", $strRemetente, $arrRemetente);
$strRemetenteNome = $arrRemetente[1][0];
$strRemetenteEmail = $arrRemetente[2][0];
$strTitulo = $objMensagem->getHeader('subject', 'string');
$objMensagemPart = $objMensagem;
while ($objMensagemPart->isMultipart()) {
$objMensagemPart = $objMensagem->getPart(1);
}
$strCorpo = $objMensagemPart->getContent();
$objDb->call(
'emailClienteRecebe'
,array(
'intEmailconfiguracao' => $arrEmailconfiguracao['intId']
,'strMensagemUniqueId' => $strMensagemUniqueId
,'strRemetenteNome' => $strRemetenteNome
,'strRemetenteEmail' => $strRemetenteEmail
,'strHeaders' => serialize($arrHeader)
,'strTitulo' => $strTitulo
,'strCorpo' => $strCorpo
)
);
$objMail->removeMessage($strMensagemUniqueId);
Php client return this message:
PHP Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'last request failed' in /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php:189
Stack trace:
#0 /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php(221): Zend_Mail_Protocol_Pop3->readResponse(false)
#1 /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php(457): Zend_Mail_Protocol_Pop3->request('DELE GmailId12d...')
#2 /var/www/maru/Maru/Zend/Mail/Storage/Pop3.php(227): Zend_Mail_Protocol_Pop3->delete('GmailId12de8345...')
#3 /var/www/maru/drivers/recebe-emails/driver.php(82): Zend_Mail_Storage_Pop3->removeMessage('GmailId12de8345...')
#4 {main}
thrown in /var/www/maru/Maru/Zend/Mail/Protocol/Pop3.php on line 189
Apparently the pop command "DELE GmailId1283038051edcc6e" is the problem. However, using a common e-mail client, like mozilla thunderbird, i've monitorated sent commands e the same command works fine.
Any ideas?
I know nothing about the Zend Pop3 client, only by looking at the online documentation.
The POP3 specification has a DELE command, taking a message number. You are supplying a string! Therefore the server of course does not know what to do. The Zend POP3 method even states that the id supplied has to be of integer type in the removeMessage documentation.
If you look at the getNumberByUniqueId documentation, you will see that you should translate the unique ID to a message number before calling removeMessage.
Therefore, to fix your problem, you should replace your last line with:
$objMail->removeMessage($objMail->getNumberByUniqueId($strMensagemUniqueId));
And then I think everything will be fine.