function testMultipleEmailsMultipleSeparator() { $r = new Rule_Email('[,;]'); $this->assertTrue($r->isValid("*****@*****.**")); $this->assertTrue($r->isValid("user@codendi.domain.com, user2@codendi.domain.com")); $this->assertTrue($r->isValid("user@codendi.domain.com; user2@codendi.domain.com")); $this->assertTrue($r->isValid("user@codendi.domain.com; user2@codendi.domain.com, user3@codendi.domain.com")); $this->assertFalse($r->isValid("user@codendi.domain.com; toto l'asticot, user3@codendi.domain.com")); }
/** * Send mail to recipient after ticket submission * * @param Array $params collection of data used to build the mail * * @return void */ function sendMail($params) { $um = $this->_getUserManager(); $user = $um->getCurrentUser(); $ticketId = $params['ticket_id']; $requestType = $params['text_type']; $severity = $params['text_severity']; $summary = $params['summary']; $messageToSd = $params['description']; $cc = $params['cc']; $pluginManager = $this->_getPluginManager(); $p = $pluginManager->getPluginByName('requesthelp'); if (!($from = $p->getProperty('send_notif_mail_from'))) { $from = '*****@*****.**'; } // Send a notification message to the SD and CodexCC $mail = $this->_getCodendiMail(); $mail->setFrom($from); $separator = '<tr><td><HR color="midnightblue" size="3"></td></tr>'; $noreply_alert = '<tr><td><span style="font-size:10.0pt;font-family:Verdana,font:sans-serif;color:red">' . $GLOBALS['Language']->getText('plugin_requesthelp', 'requesthelp_mail_noreply') . '.</span></td><tr></table>'; $section_span = '<span style="font-size:10.0pt;font-family:Verdana,font:sans-serif;color:#009900">'; $title_span = '<span style="font-size:10.0pt;font-family:Verdana;font:sans-serif;color:navy" >'; $content_span = '<span style="font-size:10.0pt;font-family:Verdana,font:sans-serif" >'; $core_mail = $separator . $section_span . '<b>Ticket Details</b></span>' . '<table>' . '<tr><td>' . $title_span . '<b>Ticket : </b></span></td><td>' . $content_span . $ticketId . '</span></td></tr>' . '<tr><td>' . $title_span . '<b>' . $GLOBALS['Language']->getText('plugin_requesthelp', 'type') . ' : </b></span></td><td>' . $content_span . $requestType . '</span></td></tr>' . '<tr><td>' . $title_span . '<b>' . $GLOBALS['Language']->getText('plugin_requesthelp', 'severity') . ' : </b></span></td><td>' . $content_span . $severity . '</span></td></tr>' . '<tr><td>' . $title_span . '<b>' . $GLOBALS['Language']->getText('plugin_requesthelp', 'summary') . ' : </b></span></td><td>' . $content_span . '<pre>' . $summary . '</pre></span></td></tr>' . '<tr><td>' . $title_span . '<b>Description : </b></span></td></tr><tr></table><p>' . $content_span . '<pre>' . $messageToSd . '</pre></span></p>' . $separator . $section_span . '<b>Requester and notification details</b></span>' . '<table>' . '<tr><p><td>' . $title_span . '<b>' . $GLOBALS['Language']->getText('plugin_requesthelp', 'requesthelp_mail_submitter') . ' : </b></span></td><td>' . $content_span . $user->getRealName() . ' (<em>' . $user->getName() . '</em>) <a href="mailto:' . $user->getEmail() . '">' . $user->getEmail() . '</a></td></span></tr>'; if ($cc != '') { $core_mail .= '<tr><td>' . $title_span . '<b>' . $GLOBALS['Language']->getText('plugin_requesthelp', 'requesthelp_mail_cc') . ' : </b></span></td><td>' . $content_span; $ccMails = array_map('trim', preg_split('/[;]/', $cc)); $rule = new Rule_Email(); foreach ($ccMails as $ccMail) { if ($rule->isValid($ccMail)) { $core_mail .= ' <a href="mailto:' . $ccMail . '">' . $ccMail . '</a>'; } else { $email = $um->getUserByUserName($ccMail)->getEmail(); $core_mail .= ' <a href="mailto:' . $ccMail . '">' . $email . '</a>'; } } $core_mail .= '</td></span></p></tr>'; } $core_mail .= '</table>'; if (!($to = $p->getProperty('send_notif_mail_sd'))) { $to = '*****@*****.**'; } $mail->setSubject($GLOBALS['Language']->getText('plugin_requesthelp', 'requesthelp_mail_subject', array($severity, $summary))); $body = '<table><tr><td>' . $GLOBALS['Language']->getText('plugin_requesthelp', 'requesthelp_mail_support', $user->getRealName()) . '.</td></tr>' . $noreply_alert . $core_mail; $mail->setTo($to); $mail->setBodyHtml($body, Codendi_Mail::DISCARD_COMMON_LOOK_AND_FEEL); try { if (!$mail->send()) { $requestStatus = false; } else { $requestStatus = true; } } catch (Zend_Mail_Transport_Exception $e) { $GLOBALS['Response']->addFeedBack('error', $GLOBALS['Language']->getText('plugin_requesthelp', 'requesthelp_mail_failed')); $requestStatus = false; } return $requestStatus; }
private function processRepoManagementNotifications($pane, $repoId, $repositoryName, $user) { $this->addView('repoManagement'); if ($this->request->exist('mail_prefix')) { $valid = new Valid_String('mail_prefix'); $valid->required(); $mailPrefix = $this->request->getValidated('mail_prefix', $valid, ''); $this->addAction('notificationUpdatePrefix', array($this->groupId, $repoId, $mailPrefix, $pane)); } $add_mail = $this->request->getValidated('add_mail'); if ($add_mail) { $validMails = array(); $mails = array_map('trim', preg_split('/[,;]/', $add_mail)); $rule = new Rule_Email(); $um = UserManager::instance(); foreach ($mails as $mail) { if ($rule->isValid($mail)) { $validMails[] = $mail; } else { $user = $um->findUser($mail); if ($user) { $mail = $user->getEmail(); if ($mail) { $validMails[] = $mail; } else { $this->addError($this->getText('no_user_mail', array($mail))); } } else { $this->addError($this->getText('no_user', array($mail))); } } } $this->addAction('notificationAddMail', array($this->groupId, $repoId, $validMails, $pane)); } $remove_mail = $this->request->get('remove_mail'); if (is_array($remove_mail)) { $mails = array(); $valid = new Valid_Email('remove_mail'); $valid->required(); if ($this->request->validArray($valid)) { $mails = $this->request->get('remove_mail'); } if (count($mails) > 0) { $this->addAction('notificationRemoveMail', array($this->groupId, $repoId, $mails, $pane)); } } $this->addAction('redirectToRepoManagement', array($this->groupId, $repoId, $pane)); }
function validate_email($address) { $rule = new Rule_Email(); return $rule->isValid($address); }
public function isValid($value) { if ($value) { $values = explode(',', $value); foreach ($values as $v) { if (stripos($v, '!') !== false) { //we check the string is an email $rule = new Rule_Email(); if (!$rule->isValid($v)) { //we check the string correspond to a username if (!$this->userManager->getUserByIdentifier(substr($v, 1))) { return false; } } } } } return true; }
public function _dispatchActionAndView($action, $repoId, $repositoryName, $user) { switch ($action) { #CREATE REF case 'create': $this->addView('create'); break; #admin #admin case 'view': $this->addAction('getRepositoryDetails', array($this->groupId, $repoId)); $this->addView('view'); break; #ADD REF #ADD REF case 'add': $this->addAction('createReference', array($this->groupId, $repositoryName)); $this->addView('index'); break; #DELETE a repository #DELETE a repository case 'del': $this->addAction('deleteRepository', array($this->groupId, $repoId)); $this->addView('index'); break; #EDIT #EDIT case 'edit': if ($this->isAPermittedAction('clone') && $this->request->get('clone')) { $valid = new Valid_UInt('parent_id'); $valid->required(); if ($this->request->valid($valid)) { $parentId = (int) $this->request->get('parent_id'); } $this->addAction('cloneRepository', array($this->groupId, $repositoryName, $parentId)); $this->addAction('getRepositoryDetails', array($this->groupId, $parentId)); $this->addView('view'); } else { if ($this->isAPermittedAction('confirm_deletion') && $this->request->get('confirm_deletion')) { $this->addAction('confirmDeletion', array($this->groupId, $repoId)); $this->addView('confirm_deletion', array(0 => array('repo_id' => $repoId))); } else { if ($this->isAPermittedAction('save') && $this->request->get('save')) { $valid = new Valid_Text('repo_desc'); $valid->required(); if ($this->request->valid($valid)) { $repoDesc = $this->request->get('repo_desc'); } $valid = new Valid_String('repo_access'); $valid->required(); if ($this->request->valid($valid) || is_array($this->request->get('repo_access'))) { $repoAccess = $this->request->get('repo_access'); } $this->addAction('save', array($this->groupId, $repoId, $repoAccess, $repoDesc)); $this->addView('view'); } else { $this->addError($this->getText('controller_access_denied')); $this->redirect('/plugins/git/?group_id=' . $this->groupId); } } } break; #repo_management #repo_management case 'repo_management': $this->addAction('repoManagement', array($this->groupId, $repoId)); $this->addView('repoManagement'); break; #mail prefix #mail prefix case 'mail_prefix': $valid = new Valid_String('mail_prefix'); $valid->required(); if ($this->request->valid($valid)) { $mailPrefix = $this->request->get('mail_prefix'); } else { $mailPrefix = ''; } $this->addAction('notificationUpdatePrefix', array($this->groupId, $repoId, $mailPrefix)); $this->addView('repoManagement'); break; #add mail #add mail case 'add_mail': $validMails = array(); $mails = array_map('trim', preg_split('/[,;]/', $this->request->get('add_mail'))); $rule = new Rule_Email(); $um = UserManager::instance(); foreach ($mails as $mail) { if ($rule->isValid($mail)) { $validMails[] = $mail; } else { $user = $um->findUser($mail); if ($user) { $mail = $user->getEmail(); if ($mail) { $validMails[] = $mail; } else { $this->addError($this->getText('no_user_mail', array($mail))); } } else { $this->addError($this->getText('no_user', array($mail))); } } } $this->addAction('notificationAddMail', array($this->groupId, $repoId, $validMails)); $this->addView('repoManagement'); break; #remove mail #remove mail case 'remove_mail': $mails = array(); $valid = new Valid_Email('mail'); $valid->required(); if ($this->request->validArray($valid)) { $mails = $this->request->get('mail'); } if (count($mails) > 0) { $this->addAction('notificationRemoveMail', array($this->groupId, $repoId, $mails)); $this->addView('repoManagement'); } else { $this->addAction('repoManagement', array($this->groupId, $repoId)); $this->addView('repoManagement'); } break; #fork #fork case 'fork': $this->addAction('repoManagement', array($this->groupId, $repoId)); $this->addView('forkRepositories'); break; #confirm_private #confirm_private case 'confirm_private': if ($this->isAPermittedAction('confirm_deletion') && $this->request->get('confirm_deletion')) { $this->addAction('confirmDeletion', array($this->groupId, $repoId)); $this->addView('confirm_deletion', array(0 => array('repo_id' => $repoId))); } else { if ($this->isAPermittedAction('save') && $this->request->get('save')) { $valid = new Valid_Text('repo_desc'); $valid->required(); if ($this->request->valid($valid)) { $repoDesc = $this->request->get('repo_desc'); } $valid = new Valid_String('repo_access'); $valid->required(); if ($this->request->valid($valid)) { $repoAccess = $this->request->get('repo_access'); } $this->addAction('confirmPrivate', array($this->groupId, $repoId, $repoAccess, $repoDesc)); $this->addView('confirmPrivate'); } } break; #SET TO PRIVATE #SET TO PRIVATE case 'set_private': $this->addAction('setPrivate', array($this->groupId, $repoId)); $this->addView('view'); break; case 'fork_repositories': $this->addAction('getProjectRepositoryList', array($this->groupId)); $this->addView('forkRepositories'); break; case 'do_fork_repositories': try { if ($this->request->get('choose_destination') == 'personal') { $this->_doDispatchForkRepositories($this->request, $user); } else { $this->_doDispatchForkCrossProject($this->request, $user); } } catch (MalformedPathException $e) { $this->addError($this->getText('fork_malformed_path')); } $this->addAction('getProjectRepositoryList', array($this->groupId)); $this->addView('forkRepositories'); break; case "view_last_git_pushes": $vGroupId = new Valid_GroupId(); $vGroupId->required(); if ($this->request->valid($vGroupId)) { $groupId = $this->request->get('group_id'); } $vWeeksNumber = new Valid_UInt('weeks_number'); if ($this->request->valid($vWeeksNumber)) { $weeksNumber = $this->request->get('weeks_number'); } if (empty($weeksNumber) || $weeksNumber > Git_LastPushesGraph::MAX_WEEKSNUMBER) { $weeksNumber = 12; } $imageRenderer = new Git_LastPushesGraph($groupId, $weeksNumber); $imageRenderer->display(); break; #LIST #LIST default: $user_id = null; $valid = new Valid_UInt('user'); $valid->required(); if ($this->request->valid($valid)) { $user_id = $this->request->get('user'); $this->addData(array('user' => $user_id)); } $this->addAction('getProjectRepositoryList', array($this->groupId, $user_id)); $this->addView('index'); break; } }
$mail->setBcc($tolist, true); $mail->setTo($GLOBALS['sys_noreply'], true); if ($mail->send()) { print "<br><br>" . $Language->getText('admin_massmail_execute', 'sending') . ": " . $tolist . "<br><br>"; } else { print "<br><br>" . $GLOBALS['Language']->getText('global', 'mail_failed', array($GLOBALS['sys_email_admin'])) . ": " . $tolist . "<br><br>"; } } print "<br>" . $Language->getText('admin_massmail_execute', 'done') . "<br>"; flush(); $HTML->footer(array()); } else { // This part would send a preview email, parameters are retrieved within the function sendPreview() in MassMail.js $validMails = array(); $addresses = array_map('trim', preg_split('/[,;]/', $request->get('preview_destination'))); $rule = new Rule_Email(); $um = UserManager::instance(); foreach ($addresses as $address) { if ($rule->isValid($address)) { $validMails[] = $address; } else { $user = $um->findUser($address); if ($user) { $address = $user->getEmail(); if ($address) { $validMails[] = $address; } else { print "\n" . $Language->getText('admin_massmail_execute', 'no_user_mail', array($user->getUserName())) . "\n"; } } else { print "\n" . $Language->getText('admin_massmail_execute', 'no_user', array($address)) . "\n";