public function testEmailFormatter()
 {
     $pattern = '/%%(.*?)%%/is';
     // Single email mode
     $textFormatter = new EchoTextEmailFormatter($this->emailSingle);
     $this->assertRegExp($pattern, $this->emailSingle->getTextTemplate());
     $this->assertEquals(0, preg_match($pattern, $textFormatter->formatEmail()));
     $htmlFormatter = new EchoHTMLEmailFormatter($this->emailSingle);
     $this->assertRegExp($pattern, $this->emailSingle->getHTMLTemplate());
     $this->assertEquals(0, preg_match($pattern, $htmlFormatter->formatEmail()));
     // Digest email mode
     $textFormatter = new EchoTextEmailFormatter($this->emailDigest);
     $this->assertRegExp($pattern, $this->emailSingle->getTextTemplate());
     $this->assertEquals(0, preg_match($pattern, $textFormatter->formatEmail()));
     $htmlFormatter = new EchoHTMLEmailFormatter($this->emailDigest);
     $this->assertRegExp($pattern, $this->emailSingle->getHTMLTemplate());
     $this->assertEquals(0, preg_match($pattern, $htmlFormatter->formatEmail()));
 }
 /**
  * Create text version and/or html version for email notification
  *
  * @param $event EchoEvent
  * @param $user User
  * @param $type string deprecated
  * @return array
  */
 protected function formatEmail($event, $user, $type)
 {
     // Email should be always sent in user language
     $this->language = $user->getOption('language');
     // Email digest
     if ($this->distributionType === 'emaildigest') {
         return $this->formatEmailDigest($event, $user);
     }
     // Echo single email
     $emailSingle = new BsEchoEmailSingle($this, $event, $user);
     $textEmailFormatter = new BsEchoTextEmailFormatter($emailSingle);
     global $wgSitename;
     $content = array('subject' => "[{$wgSitename}] " . $this->formatFragment($this->email['subject'], $event, $user)->text(), 'body' => $textEmailFormatter->formatEmail());
     $format = MWEchoNotifUser::newFromUser($user)->getEmailFormat();
     if ($format == EchoHooks::EMAIL_FORMAT_HTML) {
         $htmlEmailFormatter = new EchoHTMLEmailFormatter($emailSingle);
         $outputFormat = $this->outputFormat;
         $this->setOutputFormat('htmlemail');
         // Add single email html body if user prefers html format
         $content['body'] = array('text' => $content['body'], 'html' => $htmlEmailFormatter->formatEmail());
         $this->setOutputFormat($outputFormat);
     }
     return $content;
 }
Beispiel #3
0
 /**
  * Send the batch email
  */
 public function sendEmail()
 {
     global $wgNotificationSender, $wgNotificationSenderName, $wgNotificationReplyName;
     // @Todo - replace them with the CONSTANT in 33810 once it is merged
     if ($this->mUser->getOption('echo-email-frequency') == 7) {
         $frequency = 'weekly';
         $emailDeliveryMode = 'weekly_digest';
     } else {
         $frequency = 'daily';
         $emailDeliveryMode = 'daily_digest';
     }
     // Echo digest email mode
     $emailDigest = new EchoEmailDigest($this->mUser, $this->content, $frequency);
     $textEmailFormatter = new EchoTextEmailFormatter($emailDigest);
     $body = $textEmailFormatter->formatEmail();
     $format = MWEchoNotifUser::newFromUser($this->mUser)->getEmailFormat();
     if ($format == EchoHooks::EMAIL_FORMAT_HTML) {
         $htmlEmailFormatter = new EchoHTMLEmailFormatter($emailDigest);
         $body = array('text' => $body, 'html' => $htmlEmailFormatter->formatEmail());
     }
     // email subject
     if ($this->count > self::$displaySize) {
         $count = wfMessage('echo-notification-count')->inLanguage($this->mUser->getOption('language'))->params(self::$displaySize)->text();
     } else {
         $count = $this->count;
     }
     // Give grep a chance to find the usages:
     // echo-email-batch-subject-daily, echo-email-batch-subject-weekly
     $subject = wfMessage('echo-email-batch-subject-' . $frequency)->inLanguage($this->mUser->getOption('language'))->params($count, $this->count)->text();
     $toAddress = new MailAddress($this->mUser);
     $fromAddress = new MailAddress($wgNotificationSender, $wgNotificationSenderName);
     $replyAddress = new MailAddress($wgNotificationSender, $wgNotificationReplyName);
     // @Todo Push the email to job queue or just send it out directly?
     UserMailer::send($toAddress, $fromAddress, $subject, $body, $replyAddress);
     MWEchoEventLogging::logSchemaEchoMail($this->mUser, $emailDeliveryMode);
 }