@ -42,13 +42,9 @@ class AliasHandler extends PFAHandler {
/*options*/ '',
/*options*/ '',
/*not_in_db*/ 0,
/*not_in_db*/ 0,
/*dont_write_to_db*/ 1,
/*dont_write_to_db*/ 1,
/*select*/ 'coalesce(__is_mailbox,0) as is_mailbox, __mailbox_username',
/*select*/ 'coalesce(__is_mailbox,0) as is_mailbox' ),
# __mailbox_username is unused, but needed as workaround for a MariaDB bug
/*extrafrom set via set_is_mailbox_extrafrom() */
/*extrafrom*/ 'LEFT JOIN ( ' .
'__mailbox_username' => pacol( 0, 0, 1, 'vtxt', '' , '' , 0), # filled via is_mailbox
' SELECT 1 as __is_mailbox, username as __mailbox_username ' .
' FROM ' . table_by_key('mailbox') .
' WHERE username IS NOT NULL ' .
' ) AS __mailbox ON __mailbox_username = address' ),
'goto_mailbox' => pacol( $mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0,
'goto_mailbox' => pacol( $mbgoto, $mbgoto,$mbgoto,'bool', 'pEdit_alias_forward_and_store' , '' , 0,
/*options*/ '',
/*options*/ '',
/*not_in_db*/ 1 ), # read_from_db_postprocess() sets the value
/*not_in_db*/ 1 ), # read_from_db_postprocess() sets the value
@ -64,8 +60,37 @@ class AliasHandler extends PFAHandler {
array('select' => '1 as _can_delete') ), # read_from_db_postprocess() updates the value
array('select' => '1 as _can_delete') ), # read_from_db_postprocess() updates the value
# aliases listed in $CONF[default_aliases] are read-only for domain admins if $CONF[special_alias_control] is NO.
# aliases listed in $CONF[default_aliases] are read-only for domain admins if $CONF[special_alias_control] is NO.
);
);
$this->set_is_mailbox_extrafrom();
}
/*
* set $this->struct['is_mailbox']['extrafrom'] based on the search conditions.
* If a listing for a specific domain is requested, optimize the subquery to only return mailboxes from that domain.
* This doesn't change the result of the main query, but improves the performance a lot on setups with lots of mailboxes.
* When using this function to optimize the is_mailbox extrafrom, don't forget to reset it to the default value
* (all domains for this admin) afterwards.
*/
private function set_is_mailbox_extrafrom($condition=array(), $searchmode=array()) {
$extrafrom = 'LEFT JOIN ( ' .
' SELECT 1 as __is_mailbox, username as __mailbox_username ' .
' FROM ' . table_by_key('mailbox') .
' WHERE username IS NOT NULL ';
if(isset($condition['domain']) & & !isset($searchmode['domain']) & & in_array($condition['domain'], $this->allowed_domains)) {
# listing for a specific domain, so restrict subquery to that domain
$extrafrom .= ' AND ' . db_in_clause($this->domain_field, array($condition['domain']));
} else {
# restrict subquery to all domains accessible to this admin
$extrafrom .= ' AND ' . db_in_clause($this->domain_field, $this->allowed_domains);
}
}
$extrafrom .= ' ) AS __mailbox ON __mailbox_username = address';
$this->struct['is_mailbox']['extrafrom'] = $extrafrom;
}
protected function initMsg() {
protected function initMsg() {
$this->msg['error_already_exists'] = 'email_address_already_exists';
$this->msg['error_already_exists'] = 'email_address_already_exists';
$this->msg['error_does_not_exist'] = 'alias_does_not_exist';
$this->msg['error_does_not_exist'] = 'alias_does_not_exist';
@ -303,22 +328,34 @@ class AliasHandler extends PFAHandler {
return $db_result;
return $db_result;
}
}
public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1 ) {
private function condition_ignore_mailboxes($condition, $searchmode ) {
# only list aliases that do not belong to mailboxes
# only list aliases that do not belong to mailboxes
# TODO: breaks if $condition is an array
if (is_array($condition)) {
$condition['__mailbox_username'] = 1;
$searchmode['__mailbox_username'] = 'NULL';
} else {
if ($condition != '') {
if ($condition != '') {
$condition = " AND ( $condition ) ";
$condition = " ( $condition ) AND ";
}
$condition = " $condition __mailbox_username IS NULL ";
}
}
return parent::getList( "__mailbox_username IS NULL $condition", $searchmode, $limit, $offset);
return array($condition, $searchmode );
}
}
public function getPagebrowser($condition, $searchmode = array()) {
public function getList($condition, $searchmode = array(), $limit=-1, $offset=-1) {
# only list aliases that do not belong to mailboxes
list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode);
# TODO: breaks if $condition is an array
$this->set_is_mailbox_extrafrom($condition, $searchmode);
if ($condition != '') {
$result = parent::getList($condition, $searchmode, $limit, $offset);
$condition = " AND ( $condition ) ";
$this->set_is_mailbox_extrafrom(); # reset to default
return $result;
}
}
return parent::getPagebrowser( "__mailbox_username IS NULL $condition", $searchmode);
public function getPagebrowser($condition, $searchmode = array()) {
list($condition, $searchmode) = $this->condition_ignore_mailboxes($condition, $searchmode);
$this->set_is_mailbox_extrafrom($condition, $searchmode);
$result = parent::getPagebrowser($condition, $searchmode);
$this->set_is_mailbox_extrafrom(); # reset to default
return $result;
}
}