예제 #1
0
 public function enhanceMail(Codendi_Mail $mail)
 {
     $headers = $this->getAdditionalHeaders();
     $from_mail = null;
     if (array_key_exists('from', $headers)) {
         $from_mail = $headers['from'];
         unset($headers['from']);
     }
     if ($from_mail === null && array_key_exists('reply-to', $headers)) {
         $from_mail = $headers['reply-to'];
     }
     if ($from_mail !== null) {
         $mail->clearFrom();
         $mail->setFrom($from_mail);
     }
     foreach ($headers as $name => $value) {
         $mail->addAdditionalHeader($name, $value);
     }
     foreach ($this->getAdditionalPropertiesForLookAndFeel() as $property => $value) {
         $mail->getLookAndFeelTemplate()->set($property, $value);
     }
     if ($this->getMessageId()) {
         $mail->getMail()->setMessageId($this->getMessageId());
     }
 }
예제 #2
0
 private function sendErrorMail($to, $subject, $message)
 {
     $mail = new Codendi_Mail();
     $mail->setFrom(ForgeConfig::get('sys_noreply'));
     $mail->setTo($to);
     $mail->setSubject($subject);
     $mail->setBody($message);
     $mail->send();
 }
예제 #3
0
function initializeMail($subject, $from, $to, $html, $text)
{
    $mail = new Codendi_Mail();
    $mail->setSubject($subject);
    $mail->setTo($to);
    $mail->setBodyHtml($html);
    $mail->setBodyText($text);
    $mail->setFrom($from);
    return $mail;
}
예제 #4
0
 public function itForcesFromHeader()
 {
     $mail_enhancer = new MailEnhancer();
     $mail = new Codendi_Mail();
     $mail->setFrom('*****@*****.**');
     $from_mail = '*****@*****.**';
     $mail_enhancer->addHeader('From', $from_mail);
     $mail_enhancer->enhanceMail($mail);
     $this->assertEqual($mail->getFrom(), $from_mail);
 }
예제 #5
0
 public function sendMail(PFUser $user, Project $project, $tv3_id, $tracker_name)
 {
     $mail = new Codendi_Mail();
     $breadcrumbs = array();
     $breadcrumbs[] = '<a href="' . get_server_url() . '/projects/' . $project->getUnixName(true) . '" />' . $project->getPublicName() . '</a>';
     $mail->getLookAndFeelTemplate()->set('breadcrumbs', $breadcrumbs);
     $mail->addAdditionalHeader("X-Codendi-Project", $project->getUnixName());
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setTo($user->getEmail());
     $mail->setSubject('Output of your migration TV3 -> TV5');
     $mail->setBody($this->getMailBody($tv3_id, $tracker_name));
     $mail->send();
     $this->purgeLogStack();
 }
예제 #6
0
 /**
  *
  * Send mails to a group of people and check the max number of emailed people limit.
  *
  * @param Project $project Project of the receivers
  * @param PFO_User $user Sender
  * @param string $subject
  * @param string $html_body
  * @param PFUser[] $receivers
  */
 public function sendMassmail(Project $project, PFUser $user, $subject, $html_body, array $receivers)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $project_name = $project->getPublicName();
     $sys_max_number_of_emailed_people = ForgeConfig::get('sys_max_number_of_emailed_people');
     if (count($receivers) > $sys_max_number_of_emailed_people && !$user->isSuperUser()) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('my_index', 'massmail_not_sent_max_users', $sys_max_number_of_emailed_people));
         return;
     }
     $mail = new Codendi_Mail();
     $mail->setFrom($user->getEmail());
     $mail->setTo($user->getEmail());
     $mail->setBccUser($receivers);
     $mail->setSubject("[" . $GLOBALS['sys_name'] . "] [" . $project_name . "] " . $subject);
     $mail->setBodyText($hp->purify($html_body, CODENDI_PURIFIER_STRIP_HTML));
     $mail->setBodyHtml($html_body);
     $is_sent = $mail->send();
     return $is_sent;
 }
예제 #7
0
 /**
  * @return Codendi_Mail
  */
 public function buildEmail(Project $project, Notification $notification)
 {
     $mail = new Codendi_Mail();
     $mail->setFrom(ForgeConfig::get('sys_noreply'));
     $mail->setBcc($this->getBcc($notification));
     $mail->setTo('');
     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 {
         if ($notification->hasHTMLBody()) {
             $mail->setBodyHtml($notification->getHTMLBody());
         }
         if ($notification->hasTextBody()) {
             $mail->setBodyText($notification->getTextBody());
         }
         $mail->setSubject($notification->getSubject());
     }
     return $mail;
 }
예제 #8
0
 /**
  * Prepare the mail to be sent after daily user sync
  *
  * @param String  $recipients  List of project administrators emails we want to notify
  * @param Integer $projectName Public name of the project we want to notify its administrators
  * @param String  $subject     The subject of the notification mail
  * @param String  $body        The content of the notification mail
  *
  * @return Codendi_Mail
  */
 protected function prepareMail($recipients, $projectName, $subject, $body)
 {
     $mail = new Codendi_Mail();
     $mail->setFrom($GLOBALS['sys_noreply']);
     if (empty($recipients)) {
         throw new InvalidArgumentException('Cannot send notification without any valid receiver, Perhaps the project <' . $projectName . '> has no administrators.');
     }
     $mail->setSubject($subject);
     $mail->setTo($recipients);
     $mail->setBody($body);
     return $mail;
 }
 /**
  * Send a notification
  *
  * @param array  $recipients the list of recipients
  * @param array  $headers    the additional headers
  * @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
  *
  * @return void
  */
 protected function sendNotification($recipients, $headers, $subject, $htmlBody, $txtBody)
 {
     $mail = new Codendi_Mail();
     $hp = Codendi_HTMLPurifier::instance();
     $breadcrumbs = array();
     $groupId = $this->getTracker()->getGroupId();
     $project = $this->getTracker()->getProject();
     $trackerId = $this->getTracker()->getID();
     $artifactId = $this->getArtifact()->getID();
     $breadcrumbs[] = '<a href="' . get_server_url() . '/projects/' . $project->getUnixName(true) . '" />' . $project->getPublicName() . '</a>';
     $breadcrumbs[] = '<a href="' . get_server_url() . '/plugins/tracker/?tracker=' . (int) $trackerId . '" />' . $hp->purify(SimpleSanitizer::unsanitize($this->getTracker()->getName())) . '</a>';
     $breadcrumbs[] = '<a href="' . get_server_url() . '/plugins/tracker/?aid=' . (int) $artifactId . '" />' . $hp->purify($this->getTracker()->getName() . ' #' . $artifactId) . '</a>';
     $mail->getLookAndFeelTemplate()->set('breadcrumbs', $breadcrumbs);
     $mail->getLookAndFeelTemplate()->set('title', $hp->purify($subject));
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->addAdditionalHeader("X-Codendi-Project", $this->getArtifact()->getTracker()->getProject()->getUnixName());
     $mail->addAdditionalHeader("X-Codendi-Tracker", $this->getArtifact()->getTracker()->getItemName());
     $mail->addAdditionalHeader("X-Codendi-Artifact-ID", $this->getId());
     foreach ($headers as $header) {
         $mail->addAdditionalHeader($header['name'], $header['value']);
     }
     $mail->setTo(implode(', ', $recipients));
     $mail->setSubject($subject);
     if ($htmlBody) {
         $mail->setBodyHTML($htmlBody);
     }
     $mail->setBodyText($txtBody);
     $mail->send();
 }
 /**
  * Send a notification
  *
  * @param array  $recipients the list of recipients
  * @param array  $headers    the additional headers
  * @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
  * @param string $from       the from email address
  *
  * @return void
  */
 protected function sendNotification($recipients, $headers, $subject, $htmlBody, $txtBody, $message_id, $from)
 {
     $mail = new Codendi_Mail();
     if ($message_id) {
         $mail->getMail()->setMessageId($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();
     $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->getLookAndFeelTemplate()->set('breadcrumbs', $breadcrumbs);
     $mail->getLookAndFeelTemplate()->set('unsubscribe_link', $this->getUnsubscribeLink());
     $mail->getLookAndFeelTemplate()->set('title', $hp->purify($subject));
     $mail->setFrom($from);
     $mail->addAdditionalHeader("X-Codendi-Project", $project->getUnixName());
     $mail->addAdditionalHeader("X-Codendi-Tracker", $tracker_name);
     $mail->addAdditionalHeader("X-Codendi-Artifact-ID", $this->getId());
     foreach ($headers as $header) {
         $mail->addAdditionalHeader($header['name'], $header['value']);
     }
     $mail->setTo(implode(', ', $recipients));
     $mail->setSubject($subject);
     if ($htmlBody) {
         $htmlBody .= $this->getHTMLBodyFilter($project_unix_name, $tracker_name);
         $mail->setBodyHTML($htmlBody);
     }
     $txtBody .= $this->getTextBodyFilter($project_unix_name, $tracker_name);
     $mail->setBodyText($txtBody);
     $mail->send();
 }
 /**
  * Prepare mail
  *
  * @param FRSPackage $package Id of th package
  * @param PFUser       $user    The deleted user
  *
  * @return Codendi_Mail
  */
 function prepareMail(FRSPackage $package, PFUser $user)
 {
     $subject = $GLOBALS['Language']->getText('file_filemodule_monitor', 'mail_subject', array($GLOBALS['sys_name'], $package->getName()));
     $mail = new Codendi_Mail();
     $mail->getLookAndFeelTemplate()->set('title', $subject);
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setTo($user->getEmail());
     $mail->setSubject($subject);
     return $mail;
 }
 /**
  * Remind a user about the document he is supposed to review
  *
  * @param Docman_ApprovalTable $table      Approval table
  * @param Integer              $reviewerId Id of the reviewer
  *
  * @return Boolean
  */
 private function notifyIndividual(Docman_ApprovalTable $table, $reviewerId)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $um = UserManager::instance();
     $reviewer = $um->getUserById($reviewerId);
     if ($table instanceof Docman_ApprovalTableFile) {
         $versionFactory = new Docman_VersionFactory();
         $version = $versionFactory->getSpecificVersionById($table->getVersionId(), 'plugin_docman_version');
         $itemId = $version->getItemId();
     } else {
         $itemId = $table->getItemId();
     }
     $itemFactory = new Docman_ItemFactory();
     $docmanItem = $itemFactory->getItemFromDb($itemId);
     $subject = $GLOBALS['Language']->getText('plugin_docman', 'approval_reminder_mail_subject', array($GLOBALS['sys_name'], $docmanItem->getTitle()));
     $mailMgr = new MailManager();
     $mailPrefs = $mailMgr->getMailPreferencesByUser($reviewer);
     $mail = new Codendi_Mail();
     $mail->getLookAndFeelTemplate()->set('title', $hp->purify($subject));
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setTo($reviewer->getEmail());
     $mail->setSubject($subject);
     if ($mailPrefs == Codendi_Mail_Interface::FORMAT_HTML) {
         $htmlBody = $this->getBodyHtml($table, $docmanItem);
         $mail->setBodyHtml($htmlBody);
     }
     $txtBody = $this->getBodyText($table, $docmanItem);
     $mail->setBodyText($txtBody);
     return $mail->send();
 }
예제 #13
0
function plugin_forumml_process_mail($plug, $reply = false)
{
    $request =& HTTPRequest::instance();
    $hp =& ForumML_HTMLPurifier::instance();
    // Instantiate a new Mail class
    $mail = new Codendi_Mail();
    // Build mail headers
    $to = mail_get_listname_from_list_id($request->get('list')) . "@" . $GLOBALS['sys_lists_host'];
    $mail->setTo($to);
    $from = user_getrealname(user_getid()) . " <" . user_getemail(user_getid()) . ">";
    $mail->setFrom($from);
    $vMsg = new Valid_Text('message');
    if ($request->valid($vMsg)) {
        $message = $request->get('message');
    }
    $subject = $request->get('subject');
    $mail->setSubject($subject);
    if ($reply) {
        // set In-Reply-To header
        $hres = plugin_forumml_get_message_headers($request->get('reply_to'));
        $reply_to = db_result($hres, 0, 'value');
        $mail->addAdditionalHeader("In-Reply-To", $reply_to);
    }
    $continue = true;
    if ($request->validArray(new Valid_Email('ccs')) && $request->exist('ccs')) {
        $cc_array = array();
        $idx = 0;
        foreach ($request->get('ccs') as $cc) {
            if (trim($cc) != "") {
                $cc_array[$idx] = $hp->purify($cc, CODENDI_PURIFIER_FULL);
                $idx++;
            }
        }
        // Checks sanity of CC List
        $err = '';
        if (!util_validateCCList($cc_array, $err)) {
            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_forumml', 'invalid_mail', $err));
            $continue = false;
        } else {
            // add list of cc users to mail mime
            if (count($cc_array) > 0) {
                $cc_list = util_normalize_emails(implode(',', $cc_array));
                $mail->setCc($cc_list, true);
            }
        }
    }
    if ($continue) {
        // Process attachments
        if (isset($_FILES["files"]) && count($_FILES["files"]['name']) > 0) {
            foreach ($_FILES["files"]['name'] as $i => $fileName) {
                $data = file_get_contents($_FILES["files"]["tmp_name"][$i]);
                $mime_type = $_FILES["files"]["type"][$i];
                $mail->addAttachment($data, $mime_type, $fileName);
            }
        }
        $mail->setBodyText($message);
        if ($mail->send()) {
            $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('plugin_forumml', 'mail_succeed'));
        } else {
            $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_forumml', 'mail_fail'));
            $continue = false;
        }
    }
    return $continue;
}