protected function fetchEmails()
 {
     $msgs = $errors = 0;
     $max = $this->gateway->getFetchMax();
     $messages = $this->mailbox->getMessages('UNSEEN');
     $emailsNumber = $this->mailbox->count();
     if ($limit = $this->gateway->getFetchLimit()) {
         $start = $emailsNumber - $limit + 1;
         if ($start < 1) {
             $start = 1;
         }
         for ($num = $start; $num <= $emailsNumber; $num++) {
             try {
                 //we can have different errors during fetching of email. we don't want to stop fetching of all queue.
                 $message = $this->mailbox->getMessage($num);
                 if ($this->createEmail($message)) {
                     if ($this->gateway->getIsDeleteEmails()) {
                         $message->delete();
                         $this->mailbox->expunge();
                     }
                     $msgs++;
                 }
                 if ($max && $msgs >= $max) {
                     break;
                 }
             } catch (Exception $e) {
                 Mage::log($e->getMessage(), 'helpdesk_error.log');
             }
         }
     } else {
         foreach ($messages as $message) {
             try {
                 //we can have different errors during fetching of email. we don't want to stop fetching of all queue.
                 if ($this->createEmail($message)) {
                     if ($this->gateway->getIsDeleteEmails()) {
                         $message->delete();
                         $this->mailbox->expunge();
                     }
                     $msgs++;
                 }
                 if ($max && $msgs >= $max) {
                     break;
                 }
             } catch (Exception $e) {
                 Mage::log($e->getMessage(), 'helpdesk_error.log');
             }
         }
     }
 }
 public function testCreateEmailWithInlineAttachment2()
 {
     $message = $this->getFixt('email_attachment_inline_image2.eml');
     $this->mailbox->addMessage($message);
     $message = $this->mailbox->getMessage(1);
     $email = $this->helper->createEmail($message);
     $attachments = array();
     foreach ($email->getAttachments() as $attachment) {
         $attachments[] = $attachment;
     }
     $this->assertEquals(1, count($attachments));
     $a = $attachments[0];
     $this->assertEquals('Outlook.jpg', $a->getName());
     $this->assertEquals('image', $a->getType());
 }
Ejemplo n.º 3
0
 public function deleteMailbox(Mirasvit_Ddeboer_Imap_Mailbox $mailbox)
 {
     if (false === imap_deletemailbox($this->resource, $this->server . $mailbox->getName())) {
         throw new Mirasvit_Ddeboer_Imap_Exception_Exception('Mailbox ' . $mailbox->getName() . ' could not be deleted');
     }
     $this->mailboxes = $this->mailboxNames = null;
 }
 /**
  * Move message to another mailbox.
  *
  * @param Mailbox $mailbox
  *
  * @throws MessageMoveException
  *
  * @return Message
  */
 public function move(Mirasvit_Ddeboer_Imap_Mailbox $mailbox)
 {
     if (!imap_mail_move($this->stream, $this->messageNumber, $mailbox->getName())) {
         throw new Mirasvit_Ddeboer_Imap_MessageMoveException($this->messageNumber, $mailbox->getName());
     }
     return $this;
 }