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/PostRestore.php
<?php

namespace MailChannels;

class PostRestore extends Hook {
    public function execute($hookData) {
        if (!isset($hookData['data']) || !isset($hookData['data']['user'])) {
            return array(false, "no user parameter");
        }

        $username = $hookData['data']['user'];
        $result = true;
        $message = "";

        try {
            $domains = $this->getOutboundSMTPService()->getAllDomainsForUser($username);
            foreach ($domains as $domain) {
                $domainName = $domain->getDomain();
                try {
                    if ($this->outboundEnabled() && $this->outboundConfig->autoUpdateSPFRecords()) {
                        $this->getOutboundSMTPService()->addMCSPFForDomain($domainName);
                        $message .= " mailchannels spf record added for user '$username' (domain: $domainName);";
                    } else {
                        $isOutbound = var_export($this->outboundEnabled(), true);
                        $isOutboundAutoUpdateSPFRecordsOn = $this->outboundEnabled() ? var_export($this->outboundConfig->autoUpdateSPFRecords(), true) : "false";
                        $message .= " not adding the mailchannels spf record for user '$username' (domain: $domainName), outbound enabled: $isOutbound, autoUpdateSPFRecords: $isOutboundAutoUpdateSPFRecordsOn;";
                    }
                } catch (\Exception $e) {
                    $errorMessage = $e->getMessage();
                    $message .= " An error occurred while restoring a domain in the PostRestore hook (domain: $domainName, user: $username): $errorMessage;";
                    $result = false;
                }
            }
        } catch (OutboundSMTPServiceInternalErrorException $e) {
            $message .= "An unexpected error occurred while fetching domains for user '$username' (PostRestore): " . $e->getMessage();
            $result = false;
        }

        return array($result, $message);
    }

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

    public static function event() {
        return 'Restore';
    }

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