Differential D17489 Diff 42058 src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | public function execute(PhutilArgumentParser $args) { | ||||
$names = array_merge($tos, $ccs); | $names = array_merge($tos, $ccs); | ||||
$users = id(new PhabricatorPeopleQuery()) | $users = id(new PhabricatorPeopleQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withUsernames($names) | ->withUsernames($names) | ||||
->execute(); | ->execute(); | ||||
$users = mpull($users, null, 'getUsername'); | $users = mpull($users, null, 'getUsername'); | ||||
$raw_tos = array(); | |||||
foreach ($tos as $key => $username) { | foreach ($tos as $key => $username) { | ||||
// If the recipient has an "@" in any noninitial position, treat this as | |||||
// a raw email address. | |||||
if (preg_match('/.@/', $username)) { | |||||
$raw_tos[] = $username; | |||||
unset($tos[$key]); | |||||
continue; | |||||
} | |||||
if (empty($users[$username])) { | if (empty($users[$username])) { | ||||
throw new PhutilArgumentUsageException( | throw new PhutilArgumentUsageException( | ||||
pht("No such user '%s' exists.", $username)); | pht("No such user '%s' exists.", $username)); | ||||
} | } | ||||
$tos[$key] = $users[$username]->getPHID(); | $tos[$key] = $users[$username]->getPHID(); | ||||
} | } | ||||
foreach ($ccs as $key => $username) { | foreach ($ccs as $key => $username) { | ||||
Show All 12 Lines | public function execute(PhutilArgumentParser $args) { | ||||
$tags = $args->getArg('tag'); | $tags = $args->getArg('tag'); | ||||
$attach = $args->getArg('attach'); | $attach = $args->getArg('attach'); | ||||
$is_bulk = $args->getArg('bulk'); | $is_bulk = $args->getArg('bulk'); | ||||
$console->writeErr("%s\n", pht('Reading message body from stdin...')); | $console->writeErr("%s\n", pht('Reading message body from stdin...')); | ||||
$body = file_get_contents('php://stdin'); | $body = file_get_contents('php://stdin'); | ||||
$mail = id(new PhabricatorMetaMTAMail()) | $mail = id(new PhabricatorMetaMTAMail()) | ||||
->addTos($tos) | |||||
->addCCs($ccs) | ->addCCs($ccs) | ||||
->setSubject($subject) | ->setSubject($subject) | ||||
->setBody($body) | ->setBody($body) | ||||
->setIsBulk($is_bulk) | ->setIsBulk($is_bulk) | ||||
->setMailTags($tags); | ->setMailTags($tags); | ||||
if ($tos) { | |||||
$mail->addTos($tos); | |||||
} | |||||
if ($raw_tos) { | |||||
$mail->addRawTos($raw_tos); | |||||
} | |||||
if ($args->getArg('html')) { | if ($args->getArg('html')) { | ||||
$mail->setBody( | $mail->setBody( | ||||
pht( | pht( | ||||
'(This is a placeholder plaintext email body for a test message '. | '(This is a placeholder plaintext email body for a test message '. | ||||
'sent with %s.)', | 'sent with %s.)', | ||||
'--html')); | '--html')); | ||||
$mail->setHTMLBody($body); | $mail->setHTMLBody($body); | ||||
Show All 26 Lines |