$target]);if(!$email||$email->getEmail()!==$target)throw new Exception('Support identity mismatch'); foreach(['mailbox','smtp']as$type){$a=$type==='mailbox'?$email->getMailBoxAccount():$email->getSmtpAccount();$spec=$entry[$type==='mailbox'?'imap':'smtp']??$data[$type==='mailbox'?'imap':'smtp'];$a->host=$spec['host'];$a->port=(int)$spec['port'];$a->protocol=$type==='mailbox'?'IMAP':'SMTP';$a->active=0;if($type==='mailbox'){$a->folder='DuneRealmsTickets';$a->fetchfreq=5;$a->fetchmax=20;$a->postfetch='nothing';}else $a->allow_spoofing=0;if(!$a->save())throw new Exception('Could not save '.$type);$errors=[];if(!$a->updateCredentials('basic',['username'=>$entry['username'],'passwd'=>$entry['password']],$errors)){echo $type.' authentication failed: '.json_encode($errors).PHP_EOL;exit(1);}if($type==='smtp'){$a->active=1;$a->save();}echo $type.' authentication verified and credentials encrypted'.PHP_EOL;} echo 'SMTP enabled; inbound fetching held pending account intake policy.'.PHP_EOL;