We??™ll chose the latter as it??™s the one most readers will have access to and can start
using right away with minimal setup. In our case we??™ll connect using:
$mail = new Zend_Mail_Storage_Pop3(array('host' => 'example.com'
'user' => 'support',
'password' => 'support123'));
Our mail object now has a connection open and we can start fetching messages.
Fetching and storing the support messages
Because Zend_Mail_Storage_Abstract implements one of the standard PHP library iterator classes it can be
iterated over easily so let??™s start with the first requirement of our application and look at storing the messages
in our support table. Listing 9.11 shows the first implementation without filtering.
Listing 9.11: Turning the support email into a row in the support table
foreach ($mail as $messageNum => $message) {
$newSupport = $this->_supportTable->createRow();
$newSupport->priority = isset($message->xPriority) ? A
$message->xPriority : 3; A
$newSupport->status = 'open';
$newSupport->title = $message->subject; B
Licensed to Menshu You
Zend Framework in Action (Ch010) Manning Publications Co. 15
$newSupport->date_created = date('Y-m-d H:i:s');
$newSupport->body = $message->getContent(); C
$id = $newSupport->save();
}
A Using the x-priority header as the priority setting
B Using the email subject as the issue title
C Using the email body as the issue body
Combine the above with some way to run it periodically, such as with cron, and we??™ve pretty well covered
the first requirement.
Pages:
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270