@ -221,12 +221,10 @@ class MailboxHandler extends PFAHandler {
}
}
protected function storemore() {
protected function storemore() {
if ($this->new) {
list(/*NULL*/,$domain) = explode('@', $this->id);
if ($this->new) {
if ( !$this->mailbox_postcreation($this->id,$domain,$this->values['maildir'], $this->values['quota']) ) {
if ( !$this->mailbox_post_script() ) {
$this->errormsg[] = Lang::read('pCreate_mailbox_result_error') . " ($this->id)";
# return false; # TODO: should this be fatal?
# return false; # TODO: should this be fatal?
}
}
@ -250,7 +248,6 @@ class MailboxHandler extends PFAHandler {
# postedit hook
# postedit hook
# TODO: implement a poststore() function? - would make handling of old and new values much easier...
# TODO: implement a poststore() function? - would make handling of old and new values much easier...
list(/*NULL*/,$domain) = explode('@', $this->id);
$old_mh = new MailboxHandler();
$old_mh = new MailboxHandler();
@ -268,8 +265,8 @@ class MailboxHandler extends PFAHandler {
$quota = $oldvalues['quota'];
$quota = $oldvalues['quota'];
}
}
if ( !$this->mailbox_postedit($this->id,$domain,$maildir, $quota) ) {
if ( !$this->mailbox_post_script() ) {
$this->errormsg[] = $PALANG['pEdit_mailbox_result_error']; # TODO: more specific error message
# TODO: should this be fatal?
}
}
}
}
}
}
@ -491,87 +488,53 @@ class MailboxHandler extends PFAHandler {
/**
/**
* Called after a mailbox has been created in the DBMS.
* Called after a mailbox has been created or edited in the DBMS.
*
*
* @param String $username
* @param String $domain
* @param String $maildir
* @param Integer $quota
* @return Boolean success/failure status
* @return Boolean success/failure status
*/
*/
# TODO: replace "print" with $this->errormsg (or infomsg?)
# TODO: replace "print" with $this->errormsg (or infomsg?)
# TODO: merge with mailbox_postedit?
function mailbox_post_script() {
function mailbox_postcreation($username,$domain,$maildir,$quota) {
if (empty($username) || empty($domain) || empty($maildir)) {
trigger_error('In '.__FUNCTION__.': empty username, domain and/or maildir parameter',E_USER_ERROR);
return FALSE;
}
$cmd = Config::read('mailbox_postcreation_script');
if ( empty($cmd) ) return TRUE;
$cmdarg1=escapeshellarg($username);
if ($this->new) {
$cmdarg2=escapeshellarg($domain);
$cmd = Config::read('mailbox_postcreation_script');
$cmdarg3=escapeshellarg($maildir);
$warnmsg = 'WARNING: Problems running mailbox postcreation script!'; # TODO: make translateable
if ($quota < = 0) $quota = 0;
} else {
$cmdarg4=escapeshellarg($quota);
$cmd = Config::read('mailbox_postedit_script');
$command= "$cmd $cmdarg1 $cmdarg2 $cmdarg3 $cmdarg4";
$warnmsg = 'WARNING: Problems running mailbox postedit script!'; # TODO: make translateable
$retval=0;
$output=array();
$firstline='';
$firstline=exec($command,$output,$retval);
if (0!=$retval) {
error_log("Running $command yielded return value=$retval, first line of output=$firstline");
print '< p > WARNING: Problems running mailbox postcreation script!< / p > ';
return FALSE;
}
}
return TRUE;
if ( empty($cmd) ) return TRUE; # nothing to do
}
/**
list(/*NULL*/,$domain) = explode('@', $this->id);
* Called after a mailbox has been altered in the DBMS.
$quota = $this->values['quota'];
*
* @param String $username
if ( empty($this->id) || empty($domain) || empty($this->values['maildir']) ) {
* @param String $domain
* @param String $maildir
* @param Integer $quota
* @return Boolean success/failure status
*/
# TODO: replace "print" with $this->errormsg (or infomsg?)
function mailbox_postedit($username,$domain,$maildir,$quota) {
if (empty($username) || empty($domain) || empty($maildir)) {
trigger_error('In '.__FUNCTION__.': empty username, domain and/or maildir parameter',E_USER_ERROR);
trigger_error('In '.__FUNCTION__.': empty username, domain and/or maildir parameter',E_USER_ERROR);
return FALSE;
return FALSE;
}
}
$cmd = Config::read('mailbox_postedit_script');
$cmdarg1=escapeshellarg($this->id);
if ( empty($cmd) ) return TRUE;
$cmdarg1=escapeshellarg($username);
$cmdarg2=escapeshellarg($domain);
$cmdarg2=escapeshellarg($domain);
$cmdarg3=escapeshellarg($maildir);
$cmdarg3=escapeshellarg($this->values['maildir']);
if ($quota < = 0) $quota = 0;
if ($quota < = 0) $quota = 0; # TODO: check if this is correct behaviour
$cmdarg4=escapeshellarg($quota);
$cmdarg4=escapeshellarg($quota);
$command = "$cmd $cmdarg1 $cmdarg2 $cmdarg3 $cmdarg4";
$command= "$cmd $cmdarg1 $cmdarg2 $cmdarg3 $cmdarg4";
$retval=0;
$retval=0;
$output=array();
$output=array();
$firstline='';
$firstline='';
$firstline=exec($command,$output,$retval);
$firstline=exec($command,$output,$retval);
if (0!=$retval) {
if (0!=$retval) {
error_log("Running $command yielded return value=$retval, first line of output=$firstline");
error_log("Running $command yielded return value=$retval, first line of output=$firstline");
print '< p > WARNING: Problems running mailbox postedit script!< / p > ' ;
$this->errormsg[] = $warnmsg ;
return FALSE;
return FALSE;
}
}
return TRUE;
return TRUE;
}
}
/**
/**
* Called by mailbox_postcreation() after a mailbox has been
* Called by storemore() after a mailbox has been created.
* created. Immediately returns, unless configuration indicates
* Immediately returns, unless configuration indicates
* that one or more sub-folders should be created.
* that one or more sub-folders should be created.
*
*
* Triggers E_USER_ERROR if configuration error is detected.
* Triggers E_USER_ERROR if configuration error is detected.