Пример #1
0
 public function enhanceMail(Codendi_Mail $mail)
 {
     foreach ($this->getAdditionalHeaders() 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
 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();
 }
Пример #3
0
 /** for a certain set of users being part of the same ugroups
  * create the mail body containing only fields that they have the permission to read
  */
 function createHTMLMailForUsers($ugroups, $changes, $group_id, $group_artifact_id, &$ok, &$subject)
 {
     global $art_field_fact, $art_fieldset_fact, $Language;
     $artifact_href = get_server_url() . "/tracker/?func=detail&aid=" . $this->getID() . "&atid={$group_artifact_id}&group_id={$group_id}";
     $used_fields = $art_field_fact->getAllUsedFields();
     $art_fieldset_fact = new ArtifactFieldsetFactory($this->ArtifactType);
     $used_fieldsets = $art_fieldset_fact->getAllFieldSetsContainingUsedFields();
     $ok = false;
     $hp = $this->getHTMLPurifier();
     $body = '';
     //generate the field permissions (TRACKER_FIELD_READ, TRACKER_FIEDL_UPDATE or nothing)
     //for all fields of this tracker given the $ugroups the user is part of
     $field_perm = false;
     if ($ugroups) {
         $field_perm = $this->ArtifactType->getFieldPermissions($ugroups);
     }
     $summ = "";
     if ($field_perm === false || isset($field_perm['summary']) && $field_perm['summary'] && permission_can_read_field($field_perm['summary'])) {
         $summ = util_unconvert_htmlspecialchars($this->getValue('summary'));
     }
     $subject = '[' . $this->ArtifactType->getCapsItemName() . ' #' . $this->getID() . '] ' . $summ;
     // artifact fields
     // Generate the message preamble with all required
     // artifact fields - Changes first if there are some.
     $body .= '<h1>' . $summ . '</h1>';
     if ($changes) {
         $body .= $this->formatChangesHTML($changes, $field_perm, $artifact_href, $visible_change);
         if (!$visible_change) {
             return;
         }
     }
     $ok = true;
     // Snapshot
     $fields_per_line = 2;
     // the column number is the number of field per line * 2 (label + value)
     // + the number of field per line -1 (a blank column between each pair "label-value" to give more space)
     $columns_number = $fields_per_line * 2 + ($fields_per_line - 1);
     $max_size = 40;
     $snapshot = '';
     foreach ($used_fieldsets as $fieldset_id => $result_fieldset) {
         // this variable will tell us if we have to display the fieldset or not (if there is at least one field to display or not)
         $display_fieldset = false;
         $fieldset_html = '';
         $i = 0;
         $fields_in_fieldset = $result_fieldset->getAllUsedFields();
         foreach ($fields_in_fieldset as $key => $field) {
             if ($field->getName() != 'comment_type_id' && $field->getName() != 'artifact_id') {
                 $field_html = $this->_getFieldLabelAndValueForHTMLMail($group_id, $group_artifact_id, $field, $field_perm);
                 if ($field_html) {
                     // if the user can read at least one field, we can display the fieldset this field is within
                     $display_fieldset = true;
                     list($sz, ) = explode("/", $field->getDisplaySize());
                     // Details field must be on one row
                     if ($sz > $max_size || $field->getName() == 'details') {
                         $fieldset_html .= "\n<TR>" . '<TD align="left" valign="top" width="10%" nowrap="nowrap">' . $field_html['label'] . '</td>' . '<TD valign="top" width="90%" colspan="' . ($columns_number - 1) . '">' . $field_html['value'] . '</TD>' . "\n</TR>";
                         $i = 0;
                     } else {
                         $fieldset_html .= $i % $fields_per_line ? '' : "\n<TR>";
                         $fieldset_html .= '<TD align="left" valign="top" width="10%" nowrap="nowrap">' . $field_html['label'] . '</td>' . '<TD width="38%" valign="top">' . $field_html['value'] . '</TD>';
                         $i++;
                         // if the line is not full, we add a additional column to give more space
                         $fieldset_html .= $i % $fields_per_line ? '<td class="artifact_spacer" width="4%">&nbsp;</td>' : "\n</TR>";
                     }
                 }
             }
         }
         // We display the fieldset only if there is at least one field inside that we can display
         if ($display_fieldset) {
             $snapshot .= '<TR style="color: #444444; background-color: #F6F6F6;"><TD COLSPAN="' . (int) $columns_number . '">&nbsp;<span title="' . $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getDescriptionText()), CODENDI_PURIFIER_CONVERT_HTML) . '">' . $hp->purify(SimpleSanitizer::unsanitize($result_fieldset->getLabel()), CODENDI_PURIFIER_CONVERT_HTML) . '</span></TD></TR>';
             $snapshot .= $fieldset_html;
         }
     }
     if ($snapshot) {
         $body .= '<h2>' . $GLOBALS['Language']->getText('tracker_include_artifact', 'mail_snapshot_title') . '</h2>';
         $body .= '<table>';
         $body .= $snapshot;
         $body .= '</table>';
         if (!$changes) {
             $body .= $this->fetchHtmlAnswerButton($artifact_href);
         }
     }
     $result = $this->getFollowups();
     if (db_numrows($result)) {
         $body .= '<h2>' . $GLOBALS['Language']->getText('tracker_include_artifact', 'mail_comment_title') . '</h2>';
         $body .= '<dl>';
         while ($row = db_fetch_array($result)) {
             $orig_subm = $this->getOriginalCommentSubmitter($row['artifact_history_id']);
             $orig_sub_mod_by = db_result($orig_subm, 0, 'mod_by');
             if ($orig_sub_mod_by == 100) {
                 $submitter_real_name = db_result($orig_subm, 0, 'email');
             } else {
                 $submitter = UserManager::instance()->getUserById($orig_sub_mod_by);
                 $submitter_real_name = $submitter->getRealName();
             }
             $orig_date = $this->getOriginalCommentDate($row['artifact_history_id']);
             $subm_date = format_date($GLOBALS['Language']->getText('system', 'datefmt'), db_result($orig_date, 0, 'date'));
             $body .= '<dt><strong>' . $submitter_real_name . '</strong> <span style="color:#bbb">' . $subm_date . '</span></dt>';
             $body .= '<dd>' . $this->formatFollowUp($group_id, $row['format'], $row['new_value'], self::OUTPUT_BROWSER) . '</dd>';
         }
         $body .= '</dl>';
     }
     // Finaly, transform relatives URLs to absolute
     // I'm Nicolas Terray and I approve this hack.
     $body = preg_replace('%<a href="/%', '<a href="' . get_server_url() . '/', $body);
     // Mail is ready, we can create it
     if ($ok) {
         $project = ProjectManager::instance()->getProject($group_id);
         $breadcrumbs = array();
         $breadcrumbs[] = '<a href="' . get_server_url() . '/projects/' . $project->getUnixName($tolower = true) . '" />' . $project->getPublicName() . '</a>';
         $breadcrumbs[] = '<a href="' . get_server_url() . '/tracker/?group_id=' . (int) $group_id . '&amp;atid=' . (int) $group_artifact_id . '" />' . $hp->purify(SimpleSanitizer::unsanitize($this->ArtifactType->getName())) . '</a>';
         $breadcrumbs[] = '<a href="' . $artifact_href . '" />' . $hp->purify($this->ArtifactType->getItemName() . ' #' . $this->getID()) . '</a>';
         $mail = new Codendi_Mail();
         $mail->getLookAndFeelTemplate()->set('breadcrumbs', $breadcrumbs);
         $mail->getLookAndFeelTemplate()->set('title', $hp->purify($subject, CODENDI_PURIFIER_CONVERT_HTML));
         $mail->getLookAndFeelTemplate()->set('additional_footer_link', '<a href="' . $artifact_href . '">' . $GLOBALS['Language']->getText('tracker_include_artifact', 'mail_direct_link') . '</a>');
         $mail->setBodyHtml($body);
         return $mail;
     } else {
         return null;
     }
 }
Пример #4
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());
     }
 }
 /**
  * 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();
 }