Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
Show First 20 Lines • Show All 514 Lines • ▼ Show 20 Lines | PhutilTypeSpec::checkMap( | ||||
'types' => 'optional list<string>', | 'types' => 'optional list<string>', | ||||
'inbound' => 'optional bool', | 'inbound' => 'optional bool', | ||||
'outbound' => 'optional bool', | 'outbound' => 'optional bool', | ||||
)); | )); | ||||
$mailers = array(); | $mailers = array(); | ||||
$config = PhabricatorEnv::getEnvConfig('cluster.mailers'); | $config = PhabricatorEnv::getEnvConfig('cluster.mailers'); | ||||
if ($config === null) { | |||||
$mailer = PhabricatorEnv::newObjectFromConfig('metamta.mail-adapter'); | |||||
$defaults = $mailer->newDefaultOptions(); | |||||
$options = $mailer->newLegacyOptions(); | |||||
$options = $options + $defaults; | |||||
$mailer | |||||
->setKey('default') | |||||
->setPriority(-1) | |||||
->setOptions($options); | |||||
$mailers[] = $mailer; | |||||
} else { | |||||
$adapters = PhabricatorMailImplementationAdapter::getAllAdapters(); | $adapters = PhabricatorMailImplementationAdapter::getAllAdapters(); | ||||
$next_priority = -1; | $next_priority = -1; | ||||
foreach ($config as $spec) { | foreach ($config as $spec) { | ||||
$type = $spec['type']; | $type = $spec['type']; | ||||
if (!isset($adapters[$type])) { | if (!isset($adapters[$type])) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'Unknown mailer ("%s")!', | 'Unknown mailer ("%s")!', | ||||
$type)); | $type)); | ||||
} | } | ||||
$key = $spec['key']; | $key = $spec['key']; | ||||
$mailer = id(clone $adapters[$type]) | $mailer = id(clone $adapters[$type]) | ||||
->setKey($key); | ->setKey($key); | ||||
$priority = idx($spec, 'priority'); | $priority = idx($spec, 'priority'); | ||||
if (!$priority) { | if (!$priority) { | ||||
$priority = $next_priority; | $priority = $next_priority; | ||||
$next_priority--; | $next_priority--; | ||||
} | } | ||||
$mailer->setPriority($priority); | $mailer->setPriority($priority); | ||||
$defaults = $mailer->newDefaultOptions(); | $defaults = $mailer->newDefaultOptions(); | ||||
$options = idx($spec, 'options', array()) + $defaults; | $options = idx($spec, 'options', array()) + $defaults; | ||||
$mailer->setOptions($options); | $mailer->setOptions($options); | ||||
$mailer->setSupportsInbound(idx($spec, 'inbound', true)); | $mailer->setSupportsInbound(idx($spec, 'inbound', true)); | ||||
$mailer->setSupportsOutbound(idx($spec, 'outbound', true)); | $mailer->setSupportsOutbound(idx($spec, 'outbound', true)); | ||||
$mailers[] = $mailer; | $mailers[] = $mailer; | ||||
} | } | ||||
} | |||||
// Remove mailers with the wrong types. | // Remove mailers with the wrong types. | ||||
if (isset($constraints['types'])) { | if (isset($constraints['types'])) { | ||||
$types = $constraints['types']; | $types = $constraints['types']; | ||||
$types = array_fuse($types); | $types = array_fuse($types); | ||||
foreach ($mailers as $key => $mailer) { | foreach ($mailers as $key => $mailer) { | ||||
$mailer_type = $mailer->getAdapterType(); | $mailer_type = $mailer->getAdapterType(); | ||||
if (!isset($types[$mailer_type])) { | if (!isset($types[$mailer_type])) { | ||||
▲ Show 20 Lines • Show All 1,063 Lines • Show Last 20 Lines |