display all emails to an user (check more addresses)
add method to get all email addresses that are associated to an account, use list of addresses to allow access to emails (mail ping issue #834 #845) modified: manager/application/configs/application.ini modified: manager/application/controllers/MailController.php new file: manager/library/CAcert/User/Emails.php
This commit is contained in:
parent
5d25f68378
commit
79b16d2a04
3 changed files with 71 additions and 2 deletions
|
@ -10,6 +10,7 @@ resources.frontController.noErrorHandler = 0
|
||||||
resources.frontController.useDefaultControllerAlways = 0
|
resources.frontController.useDefaultControllerAlways = 0
|
||||||
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
|
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
|
||||||
resources.view[] =
|
resources.view[] =
|
||||||
|
autoloadernamespaces.0 = "CAcert_"
|
||||||
|
|
||||||
; Database settings for Session DB
|
; Database settings for Session DB
|
||||||
ca_mgr.db.session.pdo = "Pdo_Mysql"
|
ca_mgr.db.session.pdo = "Pdo_Mysql"
|
||||||
|
|
|
@ -8,6 +8,11 @@ require_once(LIBRARY_PATH . '/imap/imapConnection.php');
|
||||||
|
|
||||||
class MailController extends Zend_Controller_Action
|
class MailController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* list of email addresses associated with that account
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $addresses = array();
|
||||||
|
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
@ -25,6 +30,11 @@ class MailController extends Zend_Controller_Action
|
||||||
$this->view->url(array('controller' => 'mail', 'action' => 'full'), 'default', true) .
|
$this->view->url(array('controller' => 'mail', 'action' => 'full'), 'default', true) .
|
||||||
'"' . (($action == 'full')?' class="active"':'') . '>' . I18n::_('View all Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 2);
|
'"' . (($action == 'full')?' class="active"':'') . '>' . I18n::_('View all Mails') . '</a>', Zend_View_Helper_Placeholder_Container_Abstract::SET, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$emails = new CAcert_User_Emails();
|
||||||
|
|
||||||
|
$this->addresses = $emails->getEmailAddressesByLogin($session->authdata['authed_username']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAction()
|
public function indexAction()
|
||||||
|
@ -43,7 +53,7 @@ class MailController extends Zend_Controller_Action
|
||||||
$header = $imap->imapHeader($i+1);
|
$header = $imap->imapHeader($i+1);
|
||||||
|
|
||||||
// skip all emails that do not belong to the user
|
// skip all emails that do not belong to the user
|
||||||
if ($header->toaddress != $session->authdata['authed_username'])
|
if (!in_array($header->toaddress, $this->addresses))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$header->uid = $imap->imapUID($i+1);
|
$header->uid = $imap->imapUID($i+1);
|
||||||
|
@ -114,7 +124,8 @@ class MailController extends Zend_Controller_Action
|
||||||
$header = $imap->imapFetchOverview($uid);
|
$header = $imap->imapFetchOverview($uid);
|
||||||
|
|
||||||
$session = Zend_Registry::get('session');
|
$session = Zend_Registry::get('session');
|
||||||
if ($session->authdata['authed_role'] != 'Admin' && $header->to != $session->authdata['authed_username']) {
|
|
||||||
|
if ($session->authdata['authed_role'] != 'Admin' && !in_array($header->to, $this->addresses)) {
|
||||||
$this->view->message = I18n::_('This message does not belong to you');
|
$this->view->message = I18n::_('This message does not belong to you');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
57
manager/library/CAcert/User/Emails.php
Normal file
57
manager/library/CAcert/User/Emails.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class CAcert_User_Emails {
|
||||||
|
public function __construct() {
|
||||||
|
Log::Log()->debug(__METHOD__);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get list of email addresses by login, needed to be able to filter emails
|
||||||
|
* @param string $addr
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getEmailAddressesByLogin($addr) {
|
||||||
|
$db = Zend_Registry::get('auth2_dbc');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* find out user id by email address
|
||||||
|
*/
|
||||||
|
$sql = 'select users.id from users where email=?';
|
||||||
|
|
||||||
|
$id = $db->fetchOne($sql, array($addr));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get secondary email addresses
|
||||||
|
*/
|
||||||
|
$sql = 'select email.email from email where memid=?';
|
||||||
|
|
||||||
|
$res = $db->query($sql, array($id));
|
||||||
|
|
||||||
|
$emails = array();
|
||||||
|
|
||||||
|
$num = $res->rowCount();
|
||||||
|
for ($i = 0; $i < $num; $i++) {
|
||||||
|
$row = $res->fetch(PDO::FETCH_ASSOC);
|
||||||
|
$emails[] = $row['email'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get additional addresses by domains
|
||||||
|
*/
|
||||||
|
$sql = 'select domains.domain from domains where memid=?';
|
||||||
|
|
||||||
|
$res = $db->query($sql, array($id));
|
||||||
|
$num = $res->rowCount();
|
||||||
|
$variants = array('root','hostmaster','postmaster','admin','webmaster');
|
||||||
|
for ($i = 0; $i < $num; $i++) {
|
||||||
|
$row = $res->fetch(PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
foreach ($variants as $variant) {
|
||||||
|
$emails[] = $variants . '@' . $row['domain'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::Log()->debug(__METHOD__ . ' mail addresses ' . var_export($emails, true));
|
||||||
|
return $emails;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue