Example #1
0
 /**
  * Parse the current message
  * 
  * Return the parse time
  * 
  * @return number
  */
 public function parse()
 {
     $start = microtime(true);
     $this->getResource()->flagAsParsed($this);
     try {
         /* @var $message Mzax_Bounce_Message */
         $message = new Mzax_Bounce_Message($this->getRawData());
         $message->setHeader('created_at', $this->getCreatedAt());
         $result = self::getBounceDecoder()->inspect($message);
         $result = new Varien_Object($result);
         $update = array('is_parsed' => 1, 'email' => $result->getRecipient(), 'sent_at' => $result->getSentAt(), 'status_code' => $result->getStatus(), 'is_arf' => (int) $result->getArf(), 'is_autoreply' => (int) $result->getAutoreply(), 'arf_type' => $result->getFeedbackType(), 'recipient_id' => $result->getRecipientId(), 'store_id' => $result->getStoreId(), 'campaign_id' => $result->getCampaignId());
         $status = $result->getStatus();
         if ($status) {
             if (strpos($status, '4.') === 0) {
                 $update['type'] = self::BOUNCE_SOFT;
             }
             if (strpos($status, '5.') === 0) {
                 $update['type'] = self::BOUNCE_HARD;
             }
         } else {
             if ($result->getAutoreply()) {
                 $update['type'] = self::AUTOREPLY;
             } else {
                 if ($result->getUnsubscribe()) {
                     $update['type'] = self::UNSUBSCRIBE;
                     /* @see $subscriber Mzax_Emarketing_Helper_Newsletter */
                     Mage::helper('mzax_emarketing/newsletter')->unsubscribe($result->getRecipient(), $result->getStoreId(), false);
                 } else {
                     $update['type'] = self::NO_BOUNCE;
                 }
             }
         }
         if ($part = $message->findMinePart(Zend_Mime::TYPE_TEXT)) {
             $text = $part->getDecodedContent();
         } else {
             $text = $message->getDecodedContent();
         }
         if ($pos = strpos($text, '---')) {
             $text = substr($text, 0, $pos);
         }
         $text = Mage::helper('core/string')->stripTags($text);
         $text = Mage::helper('core/string')->truncate($text, 512);
         $update['message'] = $text;
         $update['subject'] = $message->getSubject();
         $this->addData($update);
         $this->save();
         Mage::dispatchEvent('mzax_emarketing_inbox_email_parse', array('email' => $this, 'message' => $message, 'result' => $result));
         if ($this->shouldForward()) {
             $this->forward($message);
         }
         // unsubscribe hard bounces
         if (!$this->getNoUnsubscribe() && $this->getType() == self::BOUNCE_HARD && Mage::getStoreConfigFlag('mzax_emarketing/inbox/unsubscribe_hard_bounce', $this->getStore())) {
             Mage::getSingleton('mzax_emarketing/medium_email')->unsubscribe($this->getEmail(), sprintf('%s bounce, email %s', $status, $this->getId()));
         }
     } catch (Exception $e) {
         if (Mage::getIsDeveloperMode()) {
             throw $e;
         }
         Mage::logException($e);
     }
     return microtime(true) - $start;
 }