HEX
Server: Apache
System: Linux hz.vslconceptsdomains.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: dkfounda (3233)
PHP: 8.1.34
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/local/mailchannels/hooks/PostAccountsSuspend.php
<?php

namespace MailChannels;

class PostAccountsSuspend extends Hook {

    protected EximSuspendedListReader $eximSuspendedReader;

    /**
     * @throws StorageNotSetException
     * @throws FileNotReadableException
     */
    public function __construct(string $eximPath = "/etc/exim_suspended_list")
    {
        parent::__construct();
        $this->eximSuspendedReader = new EximSuspendedListReader($eximPath);
    }

    public function execute($hookData) {
        return array(true, "not deprovisioning any MailChannels protected domains");
    }

    protected function whostMgrAccountsDeProvisionEximCheck($user) {
        $isInboundEnabled = $this->inboundEnabled();
        if ($isInboundEnabled) {
            $autoDomainDeProvisioning = $this->inboundConfig->autoDomainDeProvisioning();
            if ($autoDomainDeProvisioning) {
                try {
                    $domains = $this->outboundSMTPService->getAllDomainsForUser($user);
                    $result = true;
                    $message = "";
                    foreach ($domains as $domain) {
                        $domainName = $domain->getDomain();
                        if ($this->eximSuspendedReader->getAction($domainName) == 'fail') {
                            try {
                                $deprovisionResult = $this->inboundSmtpService->deProvisionDomain($domainName);
                                if ($deprovisionResult) {
                                    $message .= " domain '$domainName' no longer uses MailChannels;";
                                } else {
                                    $message .= " action not taken; domain '$domainName' not found;";
                                }
                            } catch (InboundSMTPServiceInternalErrorException $e) {
                                $errorMessage = $e->getMessage() . ": " . $e->getTraceAsString();
                                $message .= " unexpected error deprovisioning domain '$domainName': $errorMessage;";

                                if( !is_a($e->getPrevious(), get_class(new InboundApiUnprocessableException())) ) {
                                    $result = false;
                                }
                            } catch (\Exception $e) {
                                $errorMessage = $e->getMessage() . ": " . $e->getTraceAsString();
                                $message .= " unexpected error deprovisioning domain '$domainName': $errorMessage;";
                                $result = false;
                            }
                        } else {
                            $message .= " action not taken; the Email Delivery Behavior for '$domainName' is not set to 'Reject messages at SMTP time';";
                        }

                    }
                    return array($result, $message);
                } catch (\Exception $e) {
                    $errorMessage = $e->getTraceAsString();
                    $message = "unexpected error getting domains for user '$user' (deprovisioning): $errorMessage";
                    return array(false, $message);
                }
            }
            $isAutoProtectionEnabled = var_export($autoDomainDeProvisioning, true);
            return array(true, "action not taken; autoDomainDeProvisioning: $isAutoProtectionEnabled");
        }
        return array(true, "action not taken; inbound not enabled");
    }

    public static function category() {
        return 'Whostmgr';
    }

    public static function event() {
        return 'Accounts::suspendacct';
    }

    public static function stage() {
        return 'post';
    }

}