I want to create an app to read through an IMAP mailbox extracting information from the headers. Unfortunately, the Zend\Mail\Imap functions can’t handle badly-formed emails and keep throwing exceptions. Is there an alternative or must I revert to the IMAP functions in PHP?
Can you give an example?
You can try … catch and handle the errors too.
For example
/home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Address.php:77
Message:
The input is not a valid email address. Use the basic format local-part@hostname
Stack trace:
#0 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Address.php(53): Zend\Mail\Address->__construct('R', NULL, '')
#1 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Header/AbstractAddressList.php(86): Zend\Mail\Address::fromString('R', '')
#2 [internal function]: Zend\Mail\Header\AbstractAddressList::Zend\Mail\Header\{closure}('R')
#3 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Header/AbstractAddressList.php(88): array_map(Object(Closure), Array)
#4 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Headers.php(484): Zend\Mail\Header\AbstractAddressList::fromString('Reply-to: R')
#5 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Headers.php(231): Zend\Mail\Headers->loadHeader('Reply-to: R')
#6 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Headers.php(95): Zend\Mail\Headers->addHeaderLine('Reply-to: R')
#7 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mime/src/Decode.php(149): Zend\Mail\Headers::fromString('Return-Path: <b...', '\r\n')
#8 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Storage/Part.php(110): Zend\Mime\Decode::splitMessage('Return-Path: <b...', 'Return-Path: <b...', '')
#9 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Storage/Message.php(52): Zend\Mail\Storage\Part->__construct(Array)
#10 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mail/src/Storage/Imap.php(126): Zend\Mail\Storage\Message->__construct(Array)
#11 /home/richard/httpdocs/aqp-mail/new/module/Application/src/Controller/IndexController.php(25): Zend\Mail\Storage\Imap->getMessage(79)
#12 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mvc/src/Controller/AbstractActionController.php(78): Application\Controller\IndexController->indexAction()
#13 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#15 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(106): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#16 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mvc/src/DispatchListener.php(138): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#17 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#18 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-eventmanager/src/EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#19 /home/richard/httpdocs/aqp-mail/new/vendor/zendframework/zend-mvc/src/Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#20 /home/richard/httpdocs/aqp-mail/new/public/index.php(40): Zend\Mvc\Application->run()
#21 {main}