Exemplo n.º 1
0
 /**
  * Send mail to project administrators after daliy user sync.
  *
  * @param String  $recipients  List of project administrators emails we want to notify
  * @param String  $projectName Public name of the project we want to notify its administrators
  * @param PFUser  $user        Suspended user after LDAP daily synchro
  * @param String  $subject     The subject of the notification mail
  * @param String  $body        The content of the notification mail
  *
  * @return boolean
  */
 public function notifyProjectsAdmins($recipients, $projectName, $user, $subject, $body)
 {
     $notificationStatus = true;
     try {
         $mail = $this->prepareMail($recipients, $projectName, $subject, $body);
         if (!$mail->send()) {
             $this->logger->error("LDAP daily synchro job has suspended this user " . $user->getRealName() . " (" . $user->getEmail() . ", but failed to notify administrators of <{$projectName}> project :" . $e->getMessage());
             $notificationStatus = false;
         }
     } catch (InvalidArgumentException $e) {
         $this->logger->warn("LDAP daily synchro job has suspended this user " . $user->getRealName() . " (" . $user->getEmail() . ":" . $e->getMessage());
         $notificationStatus = false;
     } catch (Zend_Mail_Exception $e) {
         $this->logger->error("LDAP daily synchro job has suspended this user " . $user->getRealName() . " (" . $user->getEmail() . "), but faced an issue during project administrators notification :" . $e->getMessage());
     }
     return $notificationStatus;
 }
Exemplo n.º 2
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;
 }
 private function doesRequestAppearToBeValid(Tracker_Artifact $artifact, array $fields_data, PFUser $submitter)
 {
     if ($submitter->isAnonymous() && !trim($submitter->getEmail())) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_artifact', 'email_required'));
         return false;
     }
     if (!$this->fields_validator->validate($artifact, $fields_data)) {
         return false;
     }
     return true;
 }
Exemplo n.º 4
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();
 }
 /**
  * Do all the synchronization between an ldap result and a Tuleap user.
  *
  * This method returns if it modified the user or not. This is usefull during
  * batch process in order to limit computing.
  *
  * @param PFUser       $user User
  * @param LDAPResult $lr   Ldap result
  *
  * @return Boolean True if the method modified the user object
  */
 public function sync(PFUser $user, LDAPResult $lr)
 {
     $modified = false;
     $ldapEmail = $lr->getEmail();
     $realname = ucwords(preg_replace('/^(\\w+).(\\w+)@.*/', '\\1 \\2', $ldapEmail));
     if ($realname !== null && $user->getRealName() != substr($realname, 0, 32)) {
         $user->setRealName($realname);
         $modified = true;
     }
     if ($ldapEmail !== null && $user->getEmail() != $ldapEmail) {
         $user->setEmail($ldapEmail);
         $modified = true;
     }
     return $modified;
 }
 /**
  * Update an artifact (means create a new changeset)
  *
  * @param array   $fields_data       Artifact fields values
  * @param string  $comment           The comment (follow-up) associated with the artifact update
  * @param PFUser  $submitter         The user who is doing the update
  * @param boolean $send_notification true if a notification must be sent, false otherwise
  * @param string  $comment_format    The comment (follow-up) type ("text" | "html")
  *
  * @throws Tracker_Exception In the validation
  * @throws Tracker_NoChangeException In the validation
  *
  * @return Tracker_Artifact_Changeset|Boolean The new changeset if update is done without error, false otherwise
  */
 public function create(Tracker_Artifact $artifact, array $fields_data, $comment, PFUser $submitter, $submitted_on, $send_notification, $comment_format)
 {
     $this->changeset_dao->startTransaction();
     $comment = trim($comment);
     $email = null;
     if ($submitter->isAnonymous()) {
         $email = $submitter->getEmail();
     }
     $this->validateNewChangeset($artifact, $fields_data, $comment, $submitter, $email);
     $previous_changeset = $artifact->getLastChangeset();
     /*
      * Post actions were run by validateNewChangeset but they modified a
      * different set of $fields_data in the case of massChange or soap requests;
      * we run them again for the current $fields_data
      */
     $artifact->getWorkflow()->before($fields_data, $submitter, $artifact);
     $changeset_id = $this->changeset_dao->create($artifact->getId(), $submitter->getId(), $email, $submitted_on);
     if (!$changeset_id) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_artifact', 'unable_update'));
         $this->changeset_dao->rollBack();
         throw new Tracker_ChangesetNotCreatedException();
     }
     if (!$this->storeComment($artifact, $comment, $submitter, $submitted_on, $comment_format, $changeset_id)) {
         $this->changeset_dao->rollBack();
         throw new Tracker_CommentNotStoredException();
     }
     $this->storeFieldsValues($artifact, $previous_changeset, $fields_data, $submitter, $changeset_id);
     $new_changeset = new Tracker_Artifact_Changeset($changeset_id, $artifact, $submitter->getId(), $submitted_on, $email);
     $artifact->addChangeset($new_changeset);
     $save_after_ok = $this->saveArtifactAfterNewChangeset($artifact, $fields_data, $submitter, $new_changeset, $previous_changeset);
     if (!$save_after_ok) {
         $this->changeset_dao->rollBack();
         throw new Tracker_AfterSaveException();
     }
     $this->event_manager->processEvent(TRACKER_EVENT_ARTIFACT_POST_UPDATE, array('artifact' => $artifact));
     try {
         $this->changeset_dao->commit();
     } catch (Exception $exception) {
         throw new Tracker_ChangesetCommitException();
     }
     if ($send_notification) {
         $artifact->getChangeset($changeset_id)->notify();
     }
     return $new_changeset;
 }
 /**
  * Manage the mail content and send it
  * 
  * @param PFUser    $user
  * @param FRSFile $file
  * @param String  $bodyContent
  * @param Array   $option
  * 
  * @return Boolean
  */
 function sendNotificationMail($user, $file, $bodyContent, $option)
 {
     $mail = new Mail();
     $language = new BaseLanguage($GLOBALS['sys_supported_languages'], $GLOBALS['sys_lang']);
     $language->loadLanguage($user->getLanguageID());
     $subject = $GLOBALS['sys_name'] . ' Error in ' . $file->getFileLocation();
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setBcc($user->getEmail());
     $mail->setSubject($subject);
     $mail->setBody($language->getText('mail_system_event', $bodyContent, $option));
     return $mail->send();
 }
 /**
  * Prepare the body of the notification mail
  *
  * @param Integer $projectName Public name of the project we want to notify its administrators
  * @param PFUser  $user        Suspended user after LDAP daily synchro
  *
  * @return String
  */
 private function getBody($projectName, $user)
 {
     return $GLOBALS['Language']->getText('plugin_ldap', 'ldap_sync_mail_notification_body', array($user->getRealName(), $user->getEmail(), $projectName, $this->retentionPeriod));
 }
Exemplo n.º 9
0
 /**
  * Create new account
  *
  * @param PFUser $user
  *
  * @return PFUser
  */
 function createAccount($user)
 {
     $dao = $this->getDao();
     $user_id = $dao->create($user->getUserName(), $user->getEmail(), $user->getPassword(), $user->getRealName(), $user->getRegisterPurpose(), $user->getStatus(), $user->getShell(), $user->getUnixStatus(), $user->getUnixUid(), $user->getUnixBox(), $user->getLdapId(), $_SERVER['REQUEST_TIME'], $user->getConfirmHash(), $user->getMailSiteUpdates(), $user->getMailVA(), $user->getStickyLogin(), $user->getAuthorizedKeys(), $user->getNewMail(), $user->getTimeZone(), $user->getTheme(), $user->getLanguageID(), $user->getExpiryDate(), $_SERVER['REQUEST_TIME']);
     if (!$user_id) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('include_exit', 'error'));
         return 0;
     } else {
         $user->setId($user_id);
         $this->assignNextUnixUid($user);
         $em = $this->_getEventManager();
         $em->processEvent(Event::USER_MANAGER_CREATE_ACCOUNT, array('user' => $user));
         // Create the first layout for the user and add some initial widgets
         $lm = $this->_getWidgetLayoutManager();
         $lm->createDefaultLayoutForUser($user_id);
         switch ($user->getStatus()) {
             case PFUser::STATUS_PENDING:
                 if (ForgeConfig::get('sys_user_approval')) {
                     $this->pending_user_notifier->notifyAdministrator($user);
                 }
                 break;
             case PFUser::STATUS_ACTIVE:
             case PFUser::STATUS_RESTRICTED:
                 $em->processEvent('project_admin_activate_user', array('user_id' => $user_id));
                 break;
         }
         return $user;
     }
 }
 private function fetchFormattedMailUserInfo(PFUser $user)
 {
     $hp = Codendi_HTMLPurifier::instance();
     if ($user && !$user->isAnonymous()) {
         $user_info = '<a href="mailto:' . $hp->purify($user->getEmail()) . '">' . $hp->purify($user->getRealName()) . ' (' . $hp->purify($user->getUserName()) . ')
             </a>';
     } else {
         $user = UserManager::instance()->getUserAnonymous();
         $user->setEmail($this->changeset->getEmail());
         $user_info = $GLOBALS['Language']->getText('tracker_include_artifact', 'anon_user');
     }
     return $user_info;
 }
 /**
  * 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;
 }
 protected function _addMessage(PFUser $to, $subject, $msg, $link)
 {
     if (!isset($this->notifications[$msg])) {
         $subject = '[' . util_unconvert_htmlspecialchars($this->_group_name) . ' - Documents] ' . $subject;
         $this->notifications[$msg] = new Notification(array(), $subject, nl2br($msg), $msg, $link, 'Documents');
     }
     $this->notifications[$msg]->addEmail($to->getEmail());
 }
 /**
  * @return Notification
  */
 private function getNotification(FRSPackage $package, PFUser $user, $html_body, $text_body)
 {
     $subject = $GLOBALS['Language']->getText('file_filemodule_monitor', 'mail_subject', array($GLOBALS['sys_name'], $package->getName()));
     $emails = array($user->getEmail());
     $service_name = 'Files';
     $goto_link = get_server_url() . '/file/showfiles.php?group_id=' . $package->getGroupID() . '&package_id=' . $package->getPackageID();
     return new Notification($emails, $subject, $html_body, $text_body, $goto_link, $service_name);
 }
Exemplo n.º 14
0
 public function getEmail()
 {
     return $this->user->getEmail();
 }
Exemplo n.º 15
0
 /**
  * Do all the synchronization between an ldap result and a Codendi user.
  *
  * This method returns if it modified the user or not. This is usefull during
  * batch process in order to limit computing.
  *
  * @param PFUser       $user Codendi user
  * @param LDAPResult $lr   Ldap result
  *
  * @return Boolean True if the method modified the user object
  */
 public function sync(PFUser $user, LDAPResult $lr)
 {
     $modified = false;
     if ($lr->getCommonName() !== null && $user->getRealName() != substr($lr->getCommonName(), 0, 32)) {
         $user->setRealName($this->getCommonName($lr));
         $modified = true;
     }
     if ($lr->getEmail() !== null && $user->getEmail() != $lr->getEmail()) {
         $user->setEmail($lr->getEmail());
         $modified = true;
     }
     return $modified;
 }
 public function user_email_value()
 {
     return $this->user->getEmail();
 }
 /**
  * Send mail to administrators with the apropriate subject and body   
  * 
  * @param Project $project
  * @param PFUser    $user
  * @param String  $urlData
  * @param String  $hrefApproval
  * @param String  $messageToAdmin
  */
 function sendMail($project, $user, $urlData, $hrefApproval, $messageToAdmin)
 {
     $mail = new Mail();
     //to
     $adminList = $this->extractReceiver($project, $urlData);
     $admins = array_unique($adminList['admins']);
     $to = implode(',', $admins);
     $mail->setTo($to);
     //from
     $from = $user->getEmail();
     $hdrs = 'From: ' . $from . "\n";
     $mail->setFrom($from);
     $mail->setSubject($GLOBALS['Language']->getText($this->getTextBase(), 'mail_subject_' . $this->getType(), array($project->getPublicName(), $user->getRealName())));
     $link = $this->getRedirectLink($urlData, $GLOBALS['Language']);
     $body = $GLOBALS['Language']->getText($this->getTextBase(), 'mail_content_' . $this->getType(), array($user->getRealName(), $user->getName(), $link, $project->getPublicName(), $hrefApproval, $messageToAdmin, $user->getEmail()));
     if ($adminList['status'] == false) {
         $body .= "\n\n" . $GLOBALS['Language']->getText($this->getTextBase(), 'mail_content_unvalid_ugroup', array($project->getPublicName()));
     }
     $mail->setBody($body);
     if (!$mail->send()) {
         exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'mail_failed', array($GLOBALS['sys_email_admin'])));
     }
     $GLOBALS['Response']->addFeedback('info', $GLOBALS['Language']->getText('include_exit', 'request_sent'), CODENDI_PURIFIER_DISABLED);
     $GLOBALS['Response']->redirect('/my');
     exit;
 }
Exemplo n.º 18
0
 private function addUser(array &$recipients, PFUser $user)
 {
     $recipients[] = array('email' => $user->getEmail(), 'real_name' => $user->getRealName());
 }
 /**
  * Build the reminder messages
  *
  * @param Tracker_DateReminder $reminder Reminder that will send notifications
  * @param Tracker_Artifact $artifact Artifact for which reminders will be sent
  * @param Array            $messages Messages
  * @param PFUser             $user     Receipient
  *
  * return Array
  */
 protected function buildMessage(Tracker_DateReminder $reminder, Tracker_Artifact $artifact, &$messages, $user)
 {
     $mailManager = new MailManager();
     $recipient = $user->getEmail();
     $lang = $user->getLanguage();
     $format = $mailManager->getMailPreferencesByUser($user);
     //We send multipart mail: html & text body in case of preferences set to html
     $htmlBody = '';
     if ($format == Codendi_Mail_Interface::FORMAT_HTML) {
         $htmlBody .= $this->getBodyHtml($reminder, $artifact, $user, $lang);
     }
     $txtBody = $this->getBodyText($reminder, $artifact, $user, $lang);
     $subject = $this->getSubject($reminder, $artifact, $user);
     $headers = array();
     $hash = md5($htmlBody . $txtBody . serialize($headers) . serialize($subject));
     if (isset($messages[$hash])) {
         $messages[$hash]['recipients'][] = $recipient;
     } else {
         $messages[$hash] = array('headers' => $headers, 'htmlBody' => $htmlBody, 'txtBody' => $txtBody, 'subject' => $subject, 'recipients' => array($recipient));
     }
 }