/**
  * Testing that each model type can render properly and does not throw an exception
  */
 public function testRenderSummaryContentWithEmailMessage()
 {
     $super = User::getByUsername('super');
     $billy = User::getByUsername('billy');
     $this->assertEquals(0, EmailMessage::getCount());
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = 'My First Email';
     //Set sender, and recipient, and content
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'My First Message';
     $emailContent->htmlContent = 'Some fake HTML content';
     $emailMessage->content = $emailContent;
     //Sending from the system, does not have a 'person'.
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'Zurmo System';
     $sender->personsOrAccounts->add($super);
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $recipient->personsOrAccounts->add($billy);
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'HomeModule');
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_ALL, 'UserModule');
     $content = ActivitiesUtil::renderSummaryContent($emailMessage, 'someUrl', LatestActivitiesConfigurationForm::OWNED_BY_FILTER_USER, 'UserModule');
 }
 public static function createDraftSendGridSystemEmail($subject, User $owner)
 {
     $emailMessage = new EmailMessage();
     $emailMessage->owner = $owner;
     $emailMessage->subject = $subject;
     //Set sender, and recipient, and content
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'My First Message';
     $emailContent->htmlContent = 'Some fake HTML content';
     $emailMessage->content = $emailContent;
     //Sending from the system, does not have a 'person'.
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'Zurmo System';
     $emailMessage->sender = $sender;
     //Recipient is billy.
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Billy James';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     //Save, at this point the email should be in the draft folder
     $saved = $emailMessage->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     return $emailMessage;
 }
Exemplo n.º 3
0
 public function recurse($messageParts, $prefix = '', $index = 1, $fullPrefix = true)
 {
     foreach ($messageParts as $part) {
         $partNumber = $prefix . $index;
         if ($part->type == 0) {
             if ($part->subtype == 'PLAIN') {
                 $this->bodyPlain .= $this->getPart($partNumber, $part->encoding);
             } else {
                 $this->bodyHTML .= $this->getPart($partNumber, $part->encoding);
             }
         } elseif ($part->type == 2) {
             $msg = new EmailMessage($this->connection, $this->messageNumber);
             $msg->getAttachments = $this->getAttachments;
             $msg->recurse($part->parts, $partNumber . '.', 0, false);
             $this->attachments[] = array('type' => $part->type, 'subtype' => $part->subtype, 'filename' => '', 'data' => $msg, 'inline' => false);
         } elseif (isset($part->parts)) {
             if ($fullPrefix) {
                 $this->recurse($part->parts, $prefix . $index . '.');
             } else {
                 $this->recurse($part->parts, $prefix);
             }
         } elseif ($part->type > 2) {
             if (isset($part->id)) {
                 $id = str_replace(array('<', '>'), '', $part->id);
                 $this->attachments[$id] = array('type' => $part->type, 'subtype' => $part->subtype, 'filename' => $this->getFilenameFromPart($part), 'data' => $this->getAttachments ? $this->getPart($partNumber, $part->encoding) : '', 'inline' => true);
             } else {
                 $this->attachments[] = array('type' => $part->type, 'subtype' => $part->subtype, 'filename' => $this->getFilenameFromPart($part), 'data' => $this->getAttachments ? $this->getPart($partNumber, $part->encoding) : '', 'inline' => false);
             }
         }
         $index++;
     }
 }
 protected function resolveEmailMessage($subject = 'Subject', $textContent = 'My First Message', $htmlContent = 'Some fake HTML content', $fromAddress = '*****@*****.**', $fromName = 'Zurmo', $toAddress = '*****@*****.**', $toName = null, $contact = null)
 {
     if (!isset($contact)) {
         $contact = ContactTestHelper::createContactByNameForOwner('emailContact', Yii::app()->user->userModel);
     }
     $emailMessage = new EmailMessage();
     $emailMessage->owner = $contact->owner;
     $emailMessage->subject = $subject;
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = $textContent;
     $emailContent->htmlContent = $htmlContent;
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = $fromAddress;
     $sender->fromName = $fromName;
     $sender->personsOrAccounts->add(Yii::app()->user->userModel);
     $emailMessage->sender = $sender;
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = $toAddress;
     if (!isset($toName)) {
         $toName = strval($contact);
     }
     $recipient->toName = $toName;
     $recipient->personsOrAccounts->add($contact);
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $emailMessage->recipients->add($recipient);
     $emailBox = EmailBoxUtil::getDefaultEmailBoxByUser(Yii::app()->user->userModel);
     $emailMessage->folder = EmailFolder::getByBoxAndType($emailBox, EmailFolder::TYPE_OUTBOX);
     $saved = $emailMessage->save();
     if (!$saved) {
         var_dump($emailMessage->getErrors());
         throw new FailedToSaveModelException();
     }
     return $emailMessage;
 }
 /**
  * @param RedBeanModelSelectQueryAdapter $selectQueryAdapter
  * @param string $columnName
  */
 protected static function addEmailMessageFirstDayOfMonthDateClause(RedBeanModelSelectQueryAdapter $selectQueryAdapter, $columnName)
 {
     assert('is_string($columnName)');
     $quote = DatabaseCompatibilityUtil::getQuote();
     $emailMessageTableName = EmailMessage::getTableName('EmailMessage');
     $selectQueryAdapter->addFirstDayOfMonthDateClause($emailMessageTableName, $columnName, static::FIRST_DAY_OF_MONTH_DATE);
 }
 public function testRun()
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     //Create 2 sent notifications, and set one with a date over a week ago (8 days ago) for the modifiedDateTime
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $folder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $modifiedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 8);
     $sql = "Update item set modifieddatetime = '" . $modifiedDateTime . "' where id = " . $emailMessage->getClassId('Item');
     ZurmoRedBean::exec($sql);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message 2', $super);
     $emailMessage2->folder = $folder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ClearSentNotificationsEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(1, count($emailMessages));
     $this->assertEquals($emailMessage2->id, $emailMessages[0]->id);
 }
 protected static function makeSqlQuery($searchAttributeData)
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $where = null;
     $selectDistinct = false;
     $autoresponderTableName = Autoresponder::getTableName('Autoresponder');
     $autoresponderItemTableName = AutoresponderItem::getTableName('AutoresponderItem');
     $emailMessageTableName = EmailMessage::getTableName('EmailMessage');
     $sentDateTimeColumnName = EmailMessage::getColumnNameByAttribute('sentDateTime');
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Autoresponder');
     $selectQueryAdapter = new RedBeanModelSelectQueryAdapter($selectDistinct);
     $queuedEmailsSelectPart = "sum(CASE WHEN {$quote}{$emailMessageTableName}{$quote}.{$quote}{$sentDateTimeColumnName}" . $quote . " = '0000-00-00 00:00:00' OR {$quote}{$emailMessageTableName}{$quote}" . ".{$quote}{$sentDateTimeColumnName}{$quote} IS NULL THEN 1 ELSE 0 END)";
     // Not Coding Standard
     $sentEmailsSelectPart = "sum(CASE WHEN {$quote}{$emailMessageTableName}{$quote}.{$quote}{$sentDateTimeColumnName}" . $quote . " > '0000-00-00 00:00:00' THEN 1 ELSE 0 END)";
     $uniqueOpensSelectPart = static::resolveAutoresponderTypeSubQuery(EmailMessageActivity::TYPE_OPEN);
     $uniqueClicksSelectPart = static::resolveAutoresponderTypeSubQuery(EmailMessageActivity::TYPE_CLICK);
     $bouncedSelectPart = static::resolveAutoresponderTypeSubQuery(EmailMessageActivity::TYPE_BOUNCE);
     $optedOutSelectPart = static::resolveAutoresponderTypeSubQuery(EmailMessageActivity::TYPE_UNSUBSCRIBE);
     static::addEmailMessageDayDateClause($selectQueryAdapter, $sentDateTimeColumnName);
     static::addEmailMessageFirstDayOfWeekDateClause($selectQueryAdapter, $sentDateTimeColumnName);
     static::addEmailMessageFirstDayOfMonthDateClause($selectQueryAdapter, $sentDateTimeColumnName);
     $selectQueryAdapter->addNonSpecificCountClause();
     $selectQueryAdapter->addClauseByQueryString($queuedEmailsSelectPart, static::QUEUED);
     $selectQueryAdapter->addClauseByQueryString($sentEmailsSelectPart, static::SENT);
     $selectQueryAdapter->addClauseByQueryString("count((" . $uniqueOpensSelectPart . "))", static::UNIQUE_OPENS);
     $selectQueryAdapter->addClauseByQueryString("count((" . $uniqueClicksSelectPart . "))", static::UNIQUE_CLICKS);
     $selectQueryAdapter->addClauseByQueryString("count((" . $bouncedSelectPart . "))", static::BOUNCED);
     $selectQueryAdapter->addClauseByQueryString("count((" . $optedOutSelectPart . "))", static::UNSUBSCRIBED);
     $joinTablesAdapter->addLeftTableAndGetAliasName($autoresponderItemTableName, 'id', $autoresponderTableName, 'autoresponder_id');
     $joinTablesAdapter->addLeftTableAndGetAliasName($emailMessageTableName, 'emailmessage_id', $autoresponderItemTableName, 'id');
     $where = RedBeanModelDataProvider::makeWhere('Autoresponder', $searchAttributeData, $joinTablesAdapter);
     $sql = SQLQueryUtil::makeQuery($autoresponderTableName, $selectQueryAdapter, $joinTablesAdapter, null, null, $where);
     return $sql;
 }
 public function testRun()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $outboxFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_OUTBOX);
     $sentFolder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $emailMessage = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage->folder = $outboxFolder;
     $saved = $emailMessage->save();
     $this->assertTrue($saved);
     $emailMessageId = $emailMessage->id;
     $emailMessage->forget();
     unset($emailMessage);
     $emailMessage2 = EmailMessageTestHelper::createDraftSystemEmail('My Email Message', $super);
     $emailMessage2->folder = $outboxFolder;
     $saved = $emailMessage2->save();
     $this->assertTrue($saved);
     $emailMessage2Id = $emailMessage2->id;
     $emailMessage2->forget();
     unset($emailMessage2);
     $this->assertEquals(2, EmailMessage::getCount());
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(2, count($emailMessages));
     $emailMessage = EmailMessage::getById($emailMessageId);
     $this->assertEquals($sentFolder, $emailMessage->folder);
     $emailMessage2 = EmailMessage::getById($emailMessage2Id);
     $this->assertEquals($sentFolder, $emailMessage2->folder);
 }
 public static function resolveAndSaveEmailMessage($textContent, $htmlContent, Item $itemOwnerModel, Contact $contact, MarketingList $marketingList, $itemId, $folderId)
 {
     $recipient = static::resolveRecipient($contact);
     if (empty($recipient)) {
         throw new MissingRecipientsForEmailMessageException();
     }
     $userId = static::resolveCurrentUserId();
     if (get_class($itemOwnerModel) == 'Campaign') {
         $ownerId = $itemOwnerModel->owner->id;
     } else {
         $ownerId = $marketingList->owner->id;
     }
     $subject = $itemOwnerModel->subject;
     $serializedData = serialize($subject);
     $headers = static::resolveHeaders($itemId);
     $nowTimestamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $emailMessageData = compact('subject', 'serializedData', 'textContent', 'htmlContent', 'userId', 'ownerId', 'headers', 'attachments', 'folderId', 'nowTimestamp');
     $attachments = array('relatedModelType' => strtolower(get_class($itemOwnerModel)), 'relatedModelId' => $itemOwnerModel->id);
     $sender = static::resolveSender($marketingList, $itemOwnerModel);
     $emailMessageData = CMap::mergeArray($emailMessageData, $sender, $recipient, $attachments);
     $emailMessageId = static::saveEmailMessageWithRelated($emailMessageData);
     if (empty($emailMessageId)) {
         throw new FailedToSaveModelException();
     }
     $emailMessage = EmailMessage::getById($emailMessageId);
     return $emailMessage;
 }
 public function testRun()
 {
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(5);
     $workflow->setModuleClassName('WorkflowsTest2Module');
     $workflow->setName('myFirstWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add action that is missing required owner
     $action = new ActionForWorkflowForm('WorkflowModelTestItem2', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_CREATE;
     $action->relation = 'hasMany2';
     $attributes = array('string' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'), 'lastName' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'jason'));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new WorkflowValidityCheckJob();
     $this->assertTrue($job->run());
     $this->assertEquals(1, Notification::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
Exemplo n.º 11
0
 public function __construct(User $deletedUser, UserDto $to, UserSession $userSession)
 {
     parent::__construct($to->LanguageCode);
     $this->deletedUser = $deletedUser;
     $this->to = $to;
     $this->userSession = $userSession;
 }
Exemplo n.º 12
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the model id.
  * @throws CHttpException if the model is not found.
  * @return EmailMessage the model.
  */
 protected function loadModel($id)
 {
     $model = EmailMessage::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('email', 'Page not found.'));
     }
     return $model;
 }
Exemplo n.º 13
0
 /**
  * @param UserDto $adminDto
  * @param User $reservationOwner
  * @param ReservationSeries $reservationSeries
  * @param IResource $primaryResource
  * @param IAttributeRepository $attributeRepository
  */
 public function __construct(UserDto $adminDto, User $reservationOwner, ReservationSeries $reservationSeries, IResource $primaryResource, IAttributeRepository $attributeRepository)
 {
     parent::__construct($adminDto->Language());
     $this->adminDto = $adminDto;
     $this->reservationOwner = $reservationOwner;
     $this->reservationSeries = $reservationSeries;
     $this->resource = $primaryResource;
     $this->attributeRepository = $attributeRepository;
     $this->timezone = $adminDto->Timezone();
 }
Exemplo n.º 14
0
 public function __construct(User $reservationOwner, ReservationSeries $reservationSeries, $language = null, IAttributeRepository $attributeRepository)
 {
     if (empty($language)) {
         $language = $reservationOwner->Language();
     }
     parent::__construct($language);
     $this->reservationOwner = $reservationOwner;
     $this->reservationSeries = $reservationSeries;
     $this->timezone = $reservationOwner->Timezone();
     $this->attributeRepository = $attributeRepository;
 }
 public function testRun()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->assertEquals(0, EmailMessage::getCount());
     $job = new TestOutboundEmailJob();
     $this->assertTrue($job->run());
     $emailMessages = EmailMessage::getAll();
     $this->assertEquals(1, count($emailMessages));
     $this->assertEquals(EmailFolder::TYPE_SENT, $emailMessages[0]->folder->type);
 }
 public function testExportRelationAttributes()
 {
     $report = new Report();
     $report->setType(Report::TYPE_ROWS_AND_COLUMNS);
     $report->setModuleClassName('EmailMessagesModule');
     $report->setFiltersStructure('');
     $emailMessage = new EmailMessage();
     $emailMessage->owner = Yii::app()->user->userModel;
     $emailMessage->subject = 'A test email';
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = 'A test text message from Zurmo.';
     $emailContent->htmlContent = 'A test text message from Zurmo.';
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = '*****@*****.**';
     $sender->fromName = 'super';
     $sender->personsOrAccounts->add(Yii::app()->user->userModel);
     $emailMessage->sender = $sender;
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = '*****@*****.**';
     $recipient->toName = 'Test Recipient';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_SENT);
     $this->assertTrue($emailMessage->save());
     $displayAttribute1 = new DisplayAttributeForReportForm('EmailMessagesModule', 'EmailMessage', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute1->setModelAliasUsingTableAliasName('relatedModel');
     $displayAttribute1->attributeIndexOrDerivedType = 'sender___User__personsOrAccounts__Inferred___firstName';
     $report->addDisplayAttribute($displayAttribute1);
     $displayAttribute2 = new DisplayAttributeForReportForm('EmailMessagesModule', 'EmailMessage', Report::TYPE_ROWS_AND_COLUMNS);
     $displayAttribute2->setModelAliasUsingTableAliasName('relatedModel');
     $displayAttribute2->attributeIndexOrDerivedType = 'sender___Contact__personsOrAccounts__Inferred___firstName';
     $report->addDisplayAttribute($displayAttribute2);
     $dataProvider = new RowsAndColumnsReportDataProvider($report);
     $adapter = ReportToExportAdapterFactory::createReportToExportAdapter($report, $dataProvider);
     $compareHeaderData = array('Sender >> Users >> First Name', 'Sender >> Contacts >> First Name');
     $compareRowData = array(array('Clark', ''));
     $this->assertEquals($compareHeaderData, $adapter->getHeaderData());
     $this->assertEquals($compareRowData, $adapter->getData());
 }
Exemplo n.º 17
0
 public function process($processor)
 {
     if (empty($processor->id)) {
         return;
     }
     $messages = $processor->w->Channel->getMessages($processor->channel_id);
     if (!empty($messages)) {
         foreach ($messages as $message) {
             if ($message->is_processed == 0) {
                 $rawdata = $message->getData();
                 if (!empty($rawdata)) {
                     $emailmessage = new EmailMessage($rawdata);
                     $email = $emailmessage->parse();
                     echo $email->getBodyText();
                     $message->is_processed = 1;
                     $message->update();
                 }
             }
         }
     }
 }
 public function testProcessWorkflowAfterSave()
 {
     $model = new WorkflowModelTestItem();
     $event = new CEvent($model);
     $observer = new WorkflowsObserver();
     $observer->setDepth(25);
     $this->assertEquals(0, Notification::getCount());
     $this->assertEquals(0, EmailMessage::getCount());
     $observer->processWorkflowAfterSave($event);
     $this->assertEquals(1, Notification::getCount());
     $this->assertEquals(1, EmailMessage::getCount());
 }
 /**
  * Notifies a user of a new comment in an article.
  *
  * @param notification The ArticleNotification object.
  * @param userInfo An UserInfo object with information about the user (we
  * mainly will need the email address!)
  * @param subject Subject of the message that will be sent to the user.
  * @param body Message that will be sent to the user.
  * @param charset the encoding that will be used in the message (it should be based
  * on the locale of the blog who is sending this message) It defaults to iso-8859-1
  * @return Returns true if the user was correctly notified or false otherwise.
  */
 function notifyUser($notification, $userInfo, $subject, $body, $charset = 'iso-8859-1')
 {
     //print( "sending notification to ".$userInfo->getEmail()."<br/>");
     $message = new EmailMessage();
     $message->setFrom($this->_config->getValue("post_notification_source_address"));
     $message->addTo($userInfo->getEmail());
     $message->setSubject("pLog Notification system");
     $message->setBody($body);
     $message->setCharset($charset);
     $service = new EmailService();
     return $service->sendMessage($message);
 }
Exemplo n.º 20
0
 /**
  * @param IGeneratedSavedReport $report
  * @param IReportDefinition $definition
  * @param string $toAddress
  * @param UserSession $reportUser
  */
 public function __construct($report, $definition, $toAddress, $reportUser)
 {
     parent::__construct($reportUser->LanguageCode);
     $this->to = $toAddress;
     $this->reportUser = $reportUser;
     $this->Set('Definition', $definition);
     $this->Set('Report', $report);
     $contents = $this->FetchTemplate('Reports/custom-csv.tpl');
     $name = $report->ReportName();
     if (!empty($name)) {
         $this->name = $name;
     }
     $this->AddStringAttachment($contents, "{$this->name}.csv");
 }
 /**
  * Send system email message
  * @param string $subject
  * @param array $recipients
  * @param string $textContent
  * @param string $htmlContent
  * @throws NotSupportedException
  */
 public static function sendSystemEmail($subject, $recipients, $textContent = '', $htmlContent = '')
 {
     $emailMessage = new EmailMessage();
     $emailMessage->owner = BaseControlUserConfigUtil::getUserToRunAs();
     $emailMessage->subject = $subject;
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = $textContent;
     $emailContent->htmlContent = $htmlContent;
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser(Yii::app()->user->userModel);
     $sender->fromName = strval(Yii::app()->user->userModel);
     $sender->personsOrAccounts->add(Yii::app()->user->userModel);
     $emailMessage->sender = $sender;
     foreach ($recipients as $recipientEmail) {
         $recipient = new EmailMessageRecipient();
         $recipient->toAddress = $recipientEmail;
         $recipient->type = EmailMessageRecipient::TYPE_TO;
         $emailMessage->recipients->add($recipient);
     }
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     $validated = $emailMessage->validate();
     if (!$validated) {
         throw new NotSupportedException();
     }
     Yii::app()->emailHelper->sendImmediately($emailMessage);
     $saved = $emailMessage->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
     if (!$emailMessage->hasSendError()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  *
  * (non-PHPdoc)
  * @see BaseJob::run()
  */
 public function run()
 {
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $oneWeekAgoTimeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 7);
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'modifiedDateTime', 'operatorType' => 'lessThan', 'value' => $oneWeekAgoTimeStamp), 2 => array('attributeName' => 'folder', 'relatedAttributeName' => 'type', 'operatorType' => 'equals', 'value' => EmailFolder::TYPE_SENT), 3 => array('attributeName' => 'folder', 'relatedAttributeName' => 'emailBox', 'operatorType' => 'equals', 'value' => $box->id));
     $searchAttributeData['structure'] = '1 and 2 and 3';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage');
     $where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter);
     $emailMessageModels = EmailMessage::getSubset($joinTablesAdapter, null, self::$pageSize, $where, null);
     foreach ($emailMessageModels as $emailMessage) {
         $emailMessage->delete();
     }
     return true;
 }
 function sendNotificationEmail($userInfo)
 {
     // if everything went fine, we can now send the confirmation email
     // only if the user specified a valid email address
     if ($userInfo->getEmail() != "") {
         // build an email message
         $message = new EmailMessage();
         $message->setBody($this->_notificationText);
         $message->setSubject("pLog Notification");
         $message->addTo($userInfo->getEmail());
         $message->setFrom($this->_userInfo->getEmail());
         // and finally send it
         $emailService = new EmailService();
         $emailService->sendMessage($message);
     }
     return true;
 }
 public function init()
 {
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenATaskIsCompleted()) {
         $eventHandler = array($this, 'updateContactLatestActivityDateTimeByTask');
         Task::model()->attachEventHandler('onAfterSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['Task'] = array('onAfterSave', $eventHandler);
     }
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenANoteIsCreated()) {
         $eventHandler = array($this, 'updateContactLatestActivityDateTimeByNote');
         Note::model()->attachEventHandler('onAfterSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['Note'] = array('onAfterSave', $eventHandler);
     }
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenAnEmailIsSentOrArchived()) {
         $eventHandler = array($this, 'updateContactLatestActivityDateTimeByEmailMessage');
         EmailMessage::model()->attachEventHandler('onAfterSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['EmailMessage'] = array('onAfterSave', $eventHandler);
     }
     if (ContactsModule::shouldUpdateLatestActivityDateTimeWhenAMeetingIsInThePast()) {
         $eventHandler = array($this, 'resolveModelLatestActivityDateTimeProcessFlagByMeeting');
         Meeting::model()->attachEventHandler('onBeforeSave', $eventHandler);
         $this->attachedEventHandlersIndexedByModelClassName['Meeting'] = array('onBeforeSave', $eventHandler);
     }
 }
 /**
  * sends the email with the request
  * @private
  */
 function sendResetEmail($userInfo, $url)
 {
     // prepare the template
     $templateService = new TemplateService();
     $template = $templateService->Template("resetpasswordemail", "summary");
     $template->assign("locale", $this->_locale);
     $template->assign("reseturl", $url);
     // render it and keep its contents
     $emailBody = $template->fetch();
     $message = new EmailMessage();
     $config =& Config::getConfig();
     $message->setFrom($config->getValue("post_notification_source_address"));
     $message->addTo($userInfo->getEmail());
     $message->setSubject("pLog Password Reset Request");
     $message->setBody($emailBody);
     $service = new EmailService();
     return $service->sendMessage($message);
 }
 /**
  *
  * (non-PHPdoc)
  * @see BaseJob::run()
  */
 public function run()
 {
     $messageContent = null;
     $userToSendMessagesFrom = BaseControlUserConfigUtil::getUserToRunAs();
     $emailMessage = new EmailMessage();
     $emailMessage->owner = Yii::app()->user->userModel;
     $emailMessage->subject = Zurmo::t('EmailMessagesModule', 'A test email from Zurmo', LabelUtil::getTranslationParamsForAllModules());
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules());
     $emailContent->htmlContent = Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules());
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = Yii::app()->emailHelper->resolveFromAddressByUser($userToSendMessagesFrom);
     $sender->fromName = Yii::app()->emailHelper->resolveFromNameForSystemUser($userToSendMessagesFrom);
     $emailMessage->sender = $sender;
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = Yii::app()->emailHelper->defaultTestToAddress;
     $recipient->toName = 'Test Recipient';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     $validatedAndSaved = $emailMessage->save();
     if (!$validatedAndSaved) {
         throw new NotSupportedException();
     }
     Yii::app()->emailHelper->sendImmediately($emailMessage);
     if (!$emailMessage->hasSendError()) {
         $messageContent .= Zurmo::t('EmailMessagesModule', 'Message successfully sent') . "\n";
         return true;
     } else {
         $messageContent .= Zurmo::t('EmailMessagesModule', 'Message failed to send') . "\n";
         $messageContent .= $emailMessage->error . "\n";
         $this->errorMessage = $messageContent;
         return false;
     }
 }
Exemplo n.º 27
0
 /**
  * Send a test email.
  * $from('name' => 'fromName', 'address' => 'fromAddress')
  * @param EmailHelper $emailHelper
  * @param Array $from
  * @param string $toAddress
  */
 public static function sendTestEmail(EmailHelper $emailHelper, array $from, $toAddress)
 {
     assert('is_string($from["name"])');
     assert('is_string($from["address"])');
     $emailMessage = new EmailMessage();
     $emailMessage->owner = Yii::app()->user->userModel;
     $emailMessage->subject = Zurmo::t('EmailMessagesModule', 'A test email from Zurmo', LabelUtil::getTranslationParamsForAllModules());
     $emailContent = new EmailMessageContent();
     $emailContent->textContent = EmailNotificationUtil::resolveNotificationTextTemplate(Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules()));
     $emailContent->htmlContent = EmailNotificationUtil::resolveNotificationHtmlTemplate(Zurmo::t('EmailMessagesModule', 'A test text message from Zurmo.', LabelUtil::getTranslationParamsForAllModules()));
     $emailMessage->content = $emailContent;
     $sender = new EmailMessageSender();
     $sender->fromAddress = $from['address'];
     $sender->fromName = $from['name'];
     $emailMessage->sender = $sender;
     $recipient = new EmailMessageRecipient();
     $recipient->toAddress = $toAddress;
     $recipient->toName = 'Test Recipient';
     $recipient->type = EmailMessageRecipient::TYPE_TO;
     $emailMessage->recipients->add($recipient);
     $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME);
     $emailMessage->folder = EmailFolder::getByBoxAndType($box, EmailFolder::TYPE_DRAFT);
     $validated = $emailMessage->validate();
     if ($validated) {
         $emailHelper->sendImmediately($emailMessage);
     }
     return $emailMessage;
 }
Exemplo n.º 28
0
 public function __construct(User $user, $userSession = null)
 {
     $this->user = $user;
     $this->userSession = $userSession;
     parent::__construct(Configuration::Instance()->GetKey(ConfigKeys::LANGUAGE));
 }
 public function testRedeemReward()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $super->primaryEmail->emailAddress = '*****@*****.**';
     $super->save();
     Yii::app()->user->userModel = $super;
     $gameRewards = GameReward::getByName('myNewGameReward');
     //not enough coins
     $this->setGetArray(array('id' => $gameRewards[0]->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward');
     $this->assertContains('You do not have enough coins to redeem this reward', $content);
     //enough coins
     $gameCoin = new GameCoin();
     $gameCoin->person = $super;
     $gameCoin->value = 100;
     $this->assertTrue($gameCoin->save());
     $notifications = Notification::getAll();
     //check for no notification
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(0, count($notifications));
     $this->setGetArray(array('id' => $gameRewards[0]->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('gameRewards/default/redeemReward');
     $this->assertContains('myNewGameReward has been redeemed.', $content);
     //check for notification
     $notifications = Notification::getAll();
     $this->assertEquals(1, count($notifications));
     //email content
     $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $notifications[0]->notificationMessage->htmlContent);
     //check url
     $this->assertContains('/gameRewards/default/details?id=13', $notifications[0]->notificationMessage->htmlContent);
     // Not Coding Standard
     //check for email notification
     $emailMessages = EmailMessage::getAll();
     $this->assertCount(1, $emailMessages);
     $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->htmlContent);
     $this->assertContains('myNewGameReward was redeemed by Clark Kent.', $emailMessages[0]->content->textContent);
 }
 public function testRunWithCampaignPausedAfterAllItemsGeneratedAndThenUnpaused()
 {
     // Cleanup
     Campaign::deleteAll();
     $this->assertEquals(0, Campaign::getCount());
     $this->assertEquals(0, CampaignItem::getCount());
     $this->assertEquals(0, CampaignItemActivity::getCount());
     MarketingList::deleteAll();
     $this->assertEquals(0, MarketingList::getCount());
     $this->assertEquals(0, MarketingListMember::getCount());
     EmailMessage::deleteAll();
     $this->assertEquals(0, EmailMessage::getCount());
     $this->assertEquals(0, EmailMessageContent::getCount());
     $this->assertEquals(0, EmailMessageSender::getCount());
     $this->assertEquals(0, EmailMessageRecipient::getCount());
     Contact::deleteAll();
     $this->assertEquals(0, Contact::getCount());
     // setup an email address for contacts
     $email = new Email();
     $email->emailAddress = '*****@*****.**';
     // create a marketing list with 5 members
     $marketingList = MarketingListTestHelper::createMarketingListByName('marketingList 05');
     $marketingListId = $marketingList->id;
     for ($i = 1; $i <= 5; $i++) {
         $contact = ContactTestHelper::createContactByNameForOwner('campaignContact 0' . $i, $this->user);
         $contact->primaryEmail = $email;
         $this->assertTrue($contact->save());
         MarketingListMemberTestHelper::createMarketingListMember(0, $marketingList, $contact);
     }
     $marketingList->forgetAll();
     // create a due campaign with that marketing list
     $campaign = CampaignTestHelper::createCampaign('campaign 04', 'subject', 'text Content', 'Html Content', null, null, null, null, null, null, MarketingList::getById($marketingListId));
     $campaignId = $campaign->id;
     /*
      * Run 1:
      * CampaignGenerateDueCampaignItemsJob
      * status == processing
      * items generated but unprocessed
      *
      * CampaignQueueMessagesInOutboxJob
      * status == processing
      * items processed with email messages generated and queued
      *
      * ProcessOutboundEmailJob
      * status == processing
      * email items attempted to be sent
      *
      * Run 2:
      * Pause the campaign
      * items are processed and still present
      *
      * Unpause the campaign
      * status == active
      * items are processed and still present
      *
      * CampaignGenerateDueCampaignItemsJob
      * status == processing
      * ensure all items are present and processed
      *
      * CampaignQueueMessagesInOutboxJob
      * status == processing
      * ensure all items are present and processed
      * ensure all email messages are present with correct folder type
      *
      * ProcessOutboundEmailJob
      * ensure all email messages are present with correct folder type
      * status == processing
      *
      *
      * Run 3:
      * Mark Campaign as Completed
      * status == completed
      */
     // we have to do this to ensure when we retrieve the data status is updated from db.
     $campaign->forgetAll();
     $this->assertEmpty(CampaignItem::getAll());
     // Run 1 starts here
     // Run CampaignGenerateDueCampaignItemsJob
     $job = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($job->run());
     $campaign = Campaign::getById($campaignId);
     // ensure status is processing
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure 5 campaign items have been generated
     $this->assertEquals(5, CampaignItem::getCount());
     // ensure all 5 campaign items are unprocessed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(0, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Run CampaignQueueMessagesInOutboxJob
     $job = new CampaignQueueMessagesInOutboxJob();
     $this->assertTrue($job->run());
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure all 5 campaign items are processed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Ensure 5 new email messages
     $this->assertEquals(5, EmailMessage::getCount());
     $this->assertEquals(5, EmailHelper::getQueuedCount());
     // Run ProcessOutboundEmail
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     // Ensure all email were sent
     $this->assertEquals(5, EmailMessage::getCount());
     $this->assertEquals(0, EmailHelper::getQueuedCount());
     foreach (EmailMessage::getAll() as $emailMessage) {
         $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT);
     }
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // end of Run 1
     // Run 2 starts here
     // Pause the campaign
     $campaign->status = Campaign::STATUS_PAUSED;
     $this->assertTrue($campaign->save());
     // ensure campaign items are still there
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertCount(5, $campaignItems);
     $this->assertNotEmpty($campaignItems);
     // Unpause campaign
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PAUSED, $campaign->status);
     $campaign->status = Campaign::STATUS_ACTIVE;
     $this->assertTrue($campaign->save());
     // ensure campaign items are still there
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertCount(5, $campaignItems);
     $this->assertNotEmpty($campaignItems);
     // Ensure status change
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_ACTIVE, $campaign->status);
     // Run CampaignGenerateDueCampaignItemsJob
     $job = new CampaignGenerateDueCampaignItemsJob();
     $this->assertTrue($job->run());
     // Ensure campaign status change
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure all 5 (previously created in run1) campaign items are still processed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Run CampaignQueueMessagesInOutboxJob
     $job = new CampaignQueueMessagesInOutboxJob();
     $this->assertTrue($job->run());
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // ensure all 5 (previously created in run1) campaign items are still processed
     $campaignItems = CampaignItem::getByProcessedAndCampaignId(1, $campaignId);
     $this->assertNotEmpty($campaignItems);
     $this->assertCount(5, $campaignItems);
     // Ensure all 5 (previously created and sent in run1) emails are sent.
     $this->assertEquals(5, EmailMessage::getCount());
     foreach (EmailMessage::getAll() as $emailMessage) {
         $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT);
     }
     // Run ProcessOutboundEmail
     $job = new ProcessOutboundEmailJob();
     $this->assertTrue($job->run());
     // Ensure all 5 (previously created and sent in run1) emails are sent.
     $this->assertEquals(5, EmailMessage::getCount());
     foreach (EmailMessage::getAll() as $emailMessage) {
         $this->assertEquals($emailMessage->folder->type, EmailFolder::TYPE_SENT);
     }
     // Ensure campaign status
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_PROCESSING, $campaign->status);
     // end of Run 2
     // Run 3 starts here
     // Run CampaignMarkCompleted
     $job = new CampaignMarkCompletedJob();
     $this->assertTrue($job->run());
     // Ensure campaign status change
     $campaign = Campaign::getById($campaignId);
     $this->assertEquals(Campaign::STATUS_COMPLETED, $campaign->status);
     // end of Run 3
 }