public function itSetsFromAndReplyToHeaders() { $mail_enhancer = new MailEnhancer(); $mail = new Codendi_Mail(); $from_mail = '*****@*****.**'; $replyto_mail = '*****@*****.**'; $mail_enhancer->addHeader('From', $from_mail); $mail_enhancer->addHeader('Reply-To', $replyto_mail); $mail_enhancer->enhanceMail($mail); $this->assertEqual($mail->getFrom(), $from_mail); $mail_headers = $mail->getMail()->getHeaders(); $this->assertEqual($mail_headers['reply-to'][0], $replyto_mail); }
private function buildEmail(Project $project, Notification $notification, MailEnhancer $mail_enhancer, $email) { $mail = $this->getMailSender(); $mail->setFrom(ForgeConfig::get('sys_noreply')); $mail->setTo($email); if ($project->getTruncatedEmailsUsage()) { $presenter = new MailPresenter($notification->getServiceName(), $notification->getGotoLink(), ForgeConfig::get('sys_fullname')); $mail->setSubject($this->renderer->renderToString(self::TRUNCATED_SUBJECT_TEMPLATE, $presenter)); $mail->setBodyHtml($this->renderer->renderToString(self::TRUNCATED_BODY_TEMPLATE, $presenter)); } else { $mail_enhancer->enhanceMail($mail); if ($notification->hasHTMLBody()) { $mail->setBodyHtml($notification->getHTMLBody()); } if ($notification->hasTextBody()) { $mail->setBodyText($notification->getTextBody()); } $mail->setSubject($notification->getSubject()); } return $mail; }
/** * Send a notification * * @param array $recipients the list of recipients * @param array $headers the additional headers * @param string $from the mail of the sender * @param string $subject the subject of the message * @param string $htmlBody the html content of the message * @param string $txtBody the text content of the message * @param string $message_id the id of the message * * @return void */ protected function sendNotification($recipients, $headers, $from, $subject, $htmlBody, $txtBody, $message_id) { $hp = Codendi_HTMLPurifier::instance(); $breadcrumbs = array(); $tracker = $this->getTracker(); $project = $tracker->getProject(); $artifactId = $this->getArtifact()->getID(); $project_unix_name = $project->getUnixName(true); $tracker_name = $tracker->getItemName(); $mail_enhancer = new MailEnhancer(); if ($message_id) { $mail_enhancer->setMessageId($message_id); } $breadcrumbs[] = '<a href="' . get_server_url() . '/projects/' . $project_unix_name . '" />' . $project->getPublicName() . '</a>'; $breadcrumbs[] = '<a href="' . get_server_url() . '/plugins/tracker/?tracker=' . (int) $tracker->getId() . '" />' . $hp->purify($this->getTracker()->getName()) . '</a>'; $breadcrumbs[] = '<a href="' . get_server_url() . '/plugins/tracker/?aid=' . (int) $artifactId . '" />' . $hp->purify($this->getTracker()->getName() . ' #' . $artifactId) . '</a>'; $mail_enhancer->addPropertiesToLookAndFeel('breadcrumbs', $breadcrumbs); $mail_enhancer->addPropertiesToLookAndFeel('unsubscribe_link', $this->getUnsubscribeLink()); $mail_enhancer->addPropertiesToLookAndFeel('title', $hp->purify($subject)); $mail_enhancer->addHeader("X-Codendi-Project", $project->getUnixName()); $mail_enhancer->addHeader("X-Codendi-Tracker", $tracker_name); $mail_enhancer->addHeader("X-Codendi-Artifact-ID", $this->artifact->getId()); $mail_enhancer->addHeader('From', $from); foreach ($headers as $header) { $mail_enhancer->addHeader($header['name'], $header['value']); } if ($htmlBody) { $htmlBody .= $this->getHTMLBodyFilter($project_unix_name, $tracker_name); } $txtBody .= $this->getTextBodyFilter($project_unix_name, $tracker_name); $mail_notification_builder = new MailNotificationBuilder(new MailBuilder(TemplateRendererFactory::build())); $mail_notification_builder->buildAndSendEmail($project, $recipients, $subject, $htmlBody, $txtBody, get_server_url() . $this->getUri(), trackerPlugin::TRUNCATED_SERVICE_NAME, $mail_enhancer); }
private function addAdditionalMailHeaders(MailEnhancer $mail_enhancer, $mail_raw_output) { foreach (array_slice($mail_raw_output, 1, 4) as $raw_header) { $header = explode(':', $raw_header); $mail_enhancer->addHeader($header[0], $header[1]); } }