/** * (non-PHPdoc) * @see kernel/classes/eZPersistentObject#setAttribute($attr, $val) */ function setAttribute($attr, $value) { switch ($attr) { case 'status': switch ($value) { case CjwNewsletterEditionSendItem::STATUS_NEW: $this->setAttribute('created', time()); break; case CjwNewsletterEditionSendItem::STATUS_SEND: $this->setAttribute('processed', time()); break; case CjwNewsletterEditionSendItem::STATUS_ABORT: $this->setAttribute('processed', time()); break; default: break; } CjwNewsletterLog::writeDebug('set status - CjwNewsletterEditionSendItem::setAttribute', 'send_item', $this->attribute('id'), array('status_old' => $this->attribute('status'), 'status_new' => $value, 'nl_user' => $this->attribute('newsletter_user_id'))); return eZPersistentObject::setAttribute($attr, $value); break; default: return eZPersistentObject::setAttribute($attr, $value); } }
/** * (non-PHPdoc) * @see kernel/classes/eZPersistentObject#setAttribute($attr, $val) */ function setAttribute($attr, $value) { switch ($attr) { case 'status': // only update timestamp and status if status id is changed if ($this->attribute('status') == $value) { return; } $currentTimeStamp = time(); // set status timestamps switch ($value) { case CjwNewsletterSubscription::STATUS_CONFIRMED: $this->setAttribute('removed', 0); $this->setAttribute('confirmed', $currentTimeStamp); $newsletterListAttributeContent = $this->attribute('newsletter_list_attribute_content'); // set approve automatically if defined in list config if (is_object($newsletterListAttributeContent) and (int) $newsletterListAttributeContent->attribute('auto_approve_registered_user') == 1) { $this->setAttribute('approved', $currentTimeStamp); $value = CjwNewsletterSubscription::STATUS_APPROVED; } else { // if subscription status is changed from approved to confirmed the approved timestamp should be removed $this->setAttribute('approved', 0); } break; case CjwNewsletterSubscription::STATUS_APPROVED: $this->setAttribute('approved', $currentTimeStamp); $this->setAttribute('removed', 0); break; case CjwNewsletterSubscription::STATUS_REMOVED_ADMIN: case CjwNewsletterSubscription::STATUS_REMOVED_SELF: $this->setAttribute('removed', $currentTimeStamp); break; } $this->setAttribute('modified', $currentTimeStamp); $statusOld = $this->attribute('status'); $statusNew = $value; if ($statusOld != $statusNew) { CjwNewsletterLog::writeNotice('CjwNewsletterSubscription::setAttribute', 'subscription', 'status', array('status_old' => $statusOld, 'status_new' => $statusNew, 'subscription_id' => $this->attribute('id'), 'list_id' => $this->attribute('list_contentobject_id'), 'nl_user' => $this->attribute('newsletter_user_id'), 'modifier' => eZUser::currentUserID())); } else { CjwNewsletterLog::writeDebug('CjwNewsletterSubscription::setAttribute', 'subscription', 'status', array('status_old' => $statusOld, 'status_new' => $statusNew, 'subscription_id' => $this->attribute('id'), 'list_id' => $this->attribute('list_contentobject_id'), 'nl_user' => $this->attribute('newsletter_user_id'), 'modifier' => eZUser::currentUserID())); } eZPersistentObject::setAttribute($attr, $value); break; default: eZPersistentObject::setAttribute($attr, $value); break; } }
/** * saved parsed infos from ezcMailObject into database * * @param $parsedResult */ private function saveParsedInfos($parsedResult) { $this->setAttribute('email_from', $parsedResult['from']); $this->setAttribute('email_to', $parsedResult['to']); $this->setAttribute('email_subject', $parsedResult['subject']); $this->setAttribute('bounce_code', $parsedResult['error_code']); //$this->setAttribute( 'final_recipient', $parsedResult[ 'final_recipient' ] ); $this->setAttribute('email_send_date', $this->convertEmailSendDateToTimestamp($parsedResult['email_send_date'])); // if x-cjwnl-senditem hash was set in bounce mail than fetch some ez data if (isset($parsedResult['x-cjwnl-senditem'])) { $sendItemHash = $parsedResult['x-cjwnl-senditem']; // try to fetch edition send item object $sendItemObject = CjwNewsletterEditionSendItem::fetchByHash($sendItemHash, true); if (is_object($sendItemObject)) { $newsletterUserId = $sendItemObject->attribute('newsletter_user_id'); $editionSendId = $sendItemObject->attribute('edition_send_id'); $editionSendItemId = $sendItemObject->attribute('id'); $this->setAttribute('newsletter_user_id', $newsletterUserId); $this->setAttribute('edition_send_id', $editionSendId); $this->setAttribute('edition_send_item_id', $editionSendItemId); if ($this->isBounce()) { $sendItemObject->setBounced(); $newsletterUser = $sendItemObject->attribute('newsletter_user_object'); if (is_object($newsletterUser)) { // bounce nl user $isHardBounce = false; $newsletterUser->setBounced($isHardBounce); } } } } elseif (isset($parsedResult['x-cjwnl-user'])) { $newsletterUser = CjwNewsletterUser::fetchByHash($sendItemHash, true); if (is_object($sendItemObject)) { $newsletterUserId = $newsletterUser->attribute('id'); $this->setAttribute('newsletter_user_id', $newsletterUserId); if ($this->isBounce()) { // bounce nl user $isHardBounce = false; $newsletterUser->setBounced($isHardBounce); } } } CjwNewsletterLog::writeDebug('parse_result CjwNewsletterMailboxItem::saveParsedInfos', 'mailbox_item', $this->attribute('id'), $parsedResult); // item is parsed $this->setAttribute('processed', time()); $this->store(); }
/** * This should be called if a user is bounced or blacklisted * all related subscriptions and active senditems will be updated * * @param $status * @return unknown_type */ private function setAllNewsletterUserRelatedItemsToStatus($status) { $newsletterUserId = $this->attribute('id'); $updateSubcriptions = false; switch ($status) { case CjwNewsletterSubscription::STATUS_BOUNCED_SOFT: case CjwNewsletterSubscription::STATUS_BOUNCED_HARD: $bounceCount = CjwNewsletterEditionSendItem::setAllActiveItemsToStatusAbortAndBouncedByNewsletterUserId($newsletterUserId); $updateSubcriptions = true; break; case CjwNewsletterSubscription::STATUS_BLACKLISTED: // update active senditems $abortCount = CjwNewsletterEditionSendItem::setAllActiveItemsToStatusAbortByNewsletterUserId($newsletterUserId); $updateSubcriptions = true; break; } if ($updateSubcriptions === true) { // update active subscriptions $activeSubscriptionList = CjwNewsletterSubscription::fetchListNotRemovedOrBlacklistedByNewsletterUserId($newsletterUserId, true); foreach ($activeSubscriptionList as $subscription) { if ($subscription->attribute('status') == $status) { CjwNewsletterLog::writeDebug('skip - already set this status - CjwNewsletterUser::setAllNewsletterUserRelatedItemsToStatus', 'subscription', 'status', array('status' => $status, 'subscription_id' => $subscription->attribute('id'), 'nl_user' => $newsletterUserId)); } else { $subscription->setAttribute('status', $status); $subscription->store(); /* CjwNewsletterLog::writeDebug( 'set CjwNewsletterUser::setAllNewsletterUserRelatedItemsToStatus', 'subscription', 'status', array( 'status' => $status, 'subscription_id' => $subscription->attribute('id'), 'nl_user' => $newsletterUserId ) ); */ } } } }
/** * connect with mailaccount * * @return object / boolean */ public function connect() { // current mailbox id $mailboxId = $this->attribute('id'); // current mailbox type, for pop3-/imap switch $mailboxType = $this->attribute('type'); // login data $server = $this->attribute('server'); $userName = $this->attribute('user_name'); $password = $this->attribute('password'); $port = $this->attribute('port'); $ssl = (bool) $this->attribute('is_ssl'); $deleteMailsFromServer = (bool) $this->attribute('delete_mails_from_server'); if ($port > 0) { $serverPort = $port; } else { // let choose ezc the right port if not set $serverPort = null; } $ezcTransportObject = null; $settingArray = array('mailbox_id' => $mailboxId, 'type' => $mailboxType, 'server' => $server, 'user_name' => $userName, 'password' => $password, 'port' => $port, 'is_ssl' => $ssl, 'delete_mails_from_server' => $deleteMailsFromServer); try { // create transport object switch ($mailboxType) { case 'imap': $options = new ezcMailImapTransportOptions(); $options->ssl = $ssl; $options->timeout = 3; $ezcTransportObject = new ezcMailImapTransport($server, $serverPort, $options); break; case 'pop3': $options = new ezcMailPop3TransportOptions(); $options->ssl = $ssl; $options->timeout = 3; // $options->authenticationMethod = ezcMailPop3Transport::AUTH_APOP; $ezcTransportObject = new ezcMailPop3Transport($server, $serverPort, $options); break; default: CjwNewsletterLog::writeError('CjwNewsletterMailbox::connect', 'mailbox', 'connect-failed', array('error-code' => $e->getMessage())); return $e->getMessage(); } } catch (Exception $e) { CjwNewsletterLog::writeError('authenticate ezcMailTransport CjwNewsletterMailbox::connect', 'mailbox', 'connect-failed', array('error-code' => $e->getMessage())); return $e->getMessage(); } try { // authenticate twise is not allowed $ezcTransportObject->authenticate($userName, $password); } catch (Exception $e) { CjwNewsletterLog::writeError('CjwNewsletterMailbox::connect', 'mailbox', 'authenticate-failed', array_merge(array('error-code' => $e->getMessage()), $settingArray)); return $e->getMessage(); } try { switch ($mailboxType) { case 'imap': $ezcTransportObject->selectMailbox('Inbox'); break; } $this->TransportObject = $ezcTransportObject; // set connect time $this->setAttribute('last_server_connect', time()); $this->store(); CjwNewsletterLog::writeDebug('CjwNewsletterMailbox::connect', 'mailbox', 'connect-ok', $settingArray); return $ezcTransportObject; } catch (Exception $e) { CjwNewsletterLog::writeError('CjwNewsletterMailbox::connect', 'mailbox', 'selectBox-failed', array('error-code' => $e->getMessage())); return $e->getMessage(); } }