Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions plugins/auto-domain-grab/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function Init()
}

/**
* This function detects the IMAP Host, and if it is set to "auto", replaces it with the email domain.
* This function detects the IMAP Host, and if it is set to "auto", replaces it with the MX or email domain.
*
* @param \RainLoop\Model\Account $oAccount
* @param array $aImapCredentials
Expand All @@ -36,13 +36,21 @@ public function FilterImapCredentials($oAccount, &$aImapCredentials)
if (!empty($aImapCredentials['Host']) && 'auto' === $aImapCredentials['Host'])
{
$domain = substr(strrchr($oAccount->Email(), "@"), 1);
$aImapCredentials['Host'] = $this->imap_prefix.$domain;
$mxhosts = array();
if(getmxrr($domain, $mxhosts) && sizeof($mxhosts) > 0)
{
$aImapCredentials['Host'] = $mxhosts[0];
}
else
{
$aImapCredentials['Host'] = $this->imap_prefix.$domain;
}
}
}
}

/**
* This function detects the SMTP Host, and if it is set to "auto", replaces it with the email domain.
* This function detects the SMTP Host, and if it is set to "auto", replaces it with the MX or email domain.
*
* @param \RainLoop\Model\Account $oAccount
* @param array $aSmtpCredentials
Expand All @@ -55,7 +63,15 @@ public function FilterSmtpCredentials($oAccount, &$aSmtpCredentials)
if (!empty($aSmtpCredentials['Host']) && 'auto' === $aSmtpCredentials['Host'])
{
$domain = substr(strrchr($oAccount->Email(), "@"), 1);
$aSmtpCredentials['Host'] = $this->smtp_prefix.$domain;
$mxhosts = array();
if(getmxrr($domain, $mxhosts) && sizeof($mxhosts) > 0)
{
$aSmtpCredentials['Host'] = $mxhosts[0];
}
else
{
$aSmtpCredentials['Host'] = $this->smtp_prefix.$domain;
}
}
}
}
Expand Down