Skip to content

Commit

Permalink
remove email forwarders from an account #8 & #11
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesUbuntu committed May 27, 2020
1 parent 8d630f6 commit 47fa554
Showing 1 changed file with 49 additions and 3 deletions.
52 changes: 49 additions & 3 deletions virtualmin_blesta.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
set_time_limit(0);
/**
* Created by PhpStorm.
* User: Luke Hardiman
Expand Down Expand Up @@ -1834,7 +1833,7 @@ public function clientTabMail($package, $service, array $getRequest = null, arra
return $service_active;

//allowed request to clientTabMail
$allowedRequests = array("add_mail_account", "mail_delete_user", "mail_change_password", '');
$allowedRequests = array("add_mail_account", "mail_delete_user", "mail_change_password", 'mail_disable_forward');
$dataRequest = array(
'package' => $package,
'service' => $service,
Expand Down Expand Up @@ -2195,6 +2194,7 @@ public function addMailAccountRules(&$vars)
}

public function mail_disable_forward($postRequest, $dataRequest = array()){
// TODO allow to disable individual disable of mail forwarders this removes all forwarders on an account
$email_id = $postRequest['email_id'];
$email_address = $postRequest["email_address"];

Expand All @@ -2208,7 +2208,53 @@ public function mail_disable_forward($postRequest, $dataRequest = array()){
//get the mail accounts for domain
$account = array('domain' => $service_fields->virtualmin_domain);
$mail_accounts = $this->api()->list_users($account);
// virtualmin modify-user --domain domain.name
$mail_accounts = $this->getVirtualMinHelper()->cleanArray($mail_accounts);

// virtualmin modify-user --domain domain.name --del-forward address
// get the users forwarding address and remove them
$foundAccount = null;
foreach ($mail_accounts as $account) {

if ($account['email_address'] == $email_address){
$foundAccount = $account;
break;
}
}
if ($foundAccount == null){
$this->log(
$service_fields->virtualmin_domain . "| mail_disable_forward account failed mailAccount[$email_id] email address $email_address is not found on domain" .
serialize(array($service_fields->virtualmin_username, $package->meta->package)
), "output", true
);
$this->getVirtualMinHelper()->sendAjax("Something went wrong", false);
return;
}
$forwardAddress = $foundAccount['forward_mail_to'];

if (is_array($forwardAddress)){
foreach ($forwardAddress as $email) {
$prams = [
'user' => $foundAccount['unix_username'],
'domain' => $service_fields->virtualmin_domain,
'del-forward' => $email
];

$reponse = $this->api()->modify_user($prams);
print_r($reponse);
}

}else{
$prams = [
'user' => $foundAccount['unix_username'],
'domain' => $service_fields->virtualmin_domain,
'del-forward' => $forwardAddress
];
$reponse = $this->api()->modify_user($prams);
}

$this->getVirtualMinHelper()->sendAjax("Removed forward addresses");
// modify_user
//$this->api()->modify_user

}
/**
Expand Down

0 comments on commit 47fa554

Please sign in to comment.