Changeset View
Changeset View
Standalone View
Standalone View
src/app/Mail/Helper.php
Show First 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | class Helper | ||||
* | * | ||||
* @param \App\User $user The user | * @param \App\User $user The user | ||||
* @param bool $external Include users's external email | * @param bool $external Include users's external email | ||||
* | * | ||||
* @return array To address as the first element, Cc address(es) as the second. | * @return array To address as the first element, Cc address(es) as the second. | ||||
*/ | */ | ||||
public static function userEmails(\App\User $user, bool $external = false): array | public static function userEmails(\App\User $user, bool $external = false): array | ||||
{ | { | ||||
$to = $user->email; | $active = $user->isLdapReady() && $user->isImapReady(); | ||||
// Sending an email to non-(ldap|imap)-ready user will fail, skip it | |||||
// (or send to the external email only, when appropriate) | |||||
$to = $active ? $user->email : null; | |||||
$cc = []; | $cc = []; | ||||
// If user has no mailbox entitlement we should not send | // If user has no mailbox entitlement we should not send | ||||
// the email to his main address, but use external address, if defined | // the email to his main address, but use external address, if defined | ||||
if (!$user->hasSku('mailbox')) { | if ($active && !$user->hasSku('mailbox')) { | ||||
$to = $user->getSetting('external_email'); | $to = $user->getSetting('external_email'); | ||||
} elseif ($external) { | } elseif ($external) { | ||||
$ext_email = $user->getSetting('external_email'); | $ext_email = $user->getSetting('external_email'); | ||||
if ($ext_email && $ext_email != $to) { | if ($ext_email && $ext_email != $to) { | ||||
$cc[] = $ext_email; | $cc[] = $ext_email; | ||||
} | } | ||||
} | } | ||||
return [$to, $cc]; | return [$to, $cc]; | ||||
} | } | ||||
} | } |