Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php
index f390ff27df..6ea2c9de5a 100644
--- a/src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php
+++ b/src/applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php
@@ -1,236 +1,233 @@
<?php
final class PhabricatorMailManagementSendTestWorkflow
extends PhabricatorMailManagementWorkflow {
protected function didConstruct() {
$this
->setName('send-test')
->setSynopsis(
pht(
'Simulate sending mail. This may be useful to test your mail '.
'configuration, or while developing new mail adapters.'))
->setExamples('**send-test** --to alincoln --subject hi < body.txt')
->setArguments(
array(
array(
'name' => 'from',
'param' => 'user',
'help' => pht('Send mail from the specified user.'),
),
array(
'name' => 'to',
'param' => 'user',
'help' => pht('Send mail "To:" the specified users.'),
'repeat' => true,
),
array(
'name' => 'cc',
'param' => 'user',
'help' => pht('Send mail which "Cc:"s the specified users.'),
'repeat' => true,
),
array(
'name' => 'subject',
'param' => 'text',
'help' => pht('Use the provided subject.'),
),
array(
'name' => 'tag',
'param' => 'text',
'help' => pht('Add the given mail tags.'),
'repeat' => true,
),
array(
'name' => 'attach',
'param' => 'file',
'help' => pht('Attach a file.'),
'repeat' => true,
),
array(
'name' => 'mailer',
'param' => 'key',
'help' => pht('Send with a specific configured mailer.'),
),
array(
'name' => 'html',
'help' => pht('Send as HTML mail.'),
),
array(
'name' => 'bulk',
'help' => pht('Send with bulk headers.'),
),
array(
'name' => 'type',
'param' => 'message-type',
+ 'default' => PhabricatorMailEmailMessage::MESSAGETYPE,
'help' => pht(
'Send the specified type of message (email, sms, ...).'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$viewer = $this->getViewer();
$type = $args->getArg('type');
- if (!strlen($type)) {
- $type = PhabricatorMailEmailMessage::MESSAGETYPE;
- }
-
$type_map = PhabricatorMailExternalMessage::getAllMessageTypes();
if (!isset($type_map[$type])) {
throw new PhutilArgumentUsageException(
pht(
'Message type "%s" is unknown, supported message types are: %s.',
$type,
implode(', ', array_keys($type_map))));
}
$from = $args->getArg('from');
if ($from) {
$user = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withUsernames(array($from))
->executeOne();
if (!$user) {
throw new PhutilArgumentUsageException(
pht("No such user '%s' exists.", $from));
}
$from = $user;
}
$tos = $args->getArg('to');
$ccs = $args->getArg('cc');
if (!$tos && !$ccs) {
throw new PhutilArgumentUsageException(
pht(
'Specify one or more users to send a message to with "--to" and/or '.
'"--cc".'));
}
$names = array_merge($tos, $ccs);
$users = id(new PhabricatorPeopleQuery())
->setViewer($viewer)
->withUsernames($names)
->execute();
$users = mpull($users, null, 'getUsername');
$raw_tos = array();
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])) {
throw new PhutilArgumentUsageException(
pht("No such user '%s' exists.", $username));
}
$tos[$key] = $users[$username]->getPHID();
}
foreach ($ccs as $key => $username) {
if (empty($users[$username])) {
throw new PhutilArgumentUsageException(
pht("No such user '%s' exists.", $username));
}
$ccs[$key] = $users[$username]->getPHID();
}
$subject = $args->getArg('subject');
if ($subject === null) {
$subject = pht('No Subject');
}
$tags = $args->getArg('tag');
$attach = $args->getArg('attach');
$is_bulk = $args->getArg('bulk');
$console->writeErr("%s\n", pht('Reading message body from stdin...'));
$body = file_get_contents('php://stdin');
$mail = id(new PhabricatorMetaMTAMail())
->addCCs($ccs)
->setSubject($subject)
->setBody($body)
->setIsBulk($is_bulk)
->setMailTags($tags);
if ($tos) {
$mail->addTos($tos);
}
if ($raw_tos) {
$mail->addRawTos($raw_tos);
}
if ($args->getArg('html')) {
$mail->setBody(
pht(
'(This is a placeholder plaintext email body for a test message '.
'sent with %s.)',
'--html'));
$mail->setHTMLBody($body);
} else {
$mail->setBody($body);
}
if ($from) {
$mail->setFrom($from->getPHID());
}
$mailers = PhabricatorMetaMTAMail::newMailers(
array(
'media' => array($type),
'outbound' => true,
));
$mailers = mpull($mailers, null, 'getKey');
if (!$mailers) {
throw new PhutilArgumentUsageException(
pht(
'No configured mailers support outbound messages of type "%s".',
$type));
}
$mailer_key = $args->getArg('mailer');
if ($mailer_key !== null) {
if (!isset($mailers[$mailer_key])) {
throw new PhutilArgumentUsageException(
pht(
'Mailer key ("%s") is not configured, or does not support '.
'outbound messages of type "%s". Available mailers are: %s.',
$mailer_key,
$type,
implode(', ', array_keys($mailers))));
}
$mail->setTryMailers(array($mailer_key));
}
foreach ($attach as $attachment) {
$data = Filesystem::readFile($attachment);
$name = basename($attachment);
$mime = Filesystem::getMimeType($attachment);
$file = new PhabricatorMailAttachment($data, $name, $mime);
$mail->addAttachment($file);
}
$mail->setMessageType($type);
PhabricatorWorker::setRunAllTasksInProcess(true);
$mail->save();
$console->writeErr(
"%s\n\n phabricator/ $ ./bin/mail show-outbound --id %d\n\n",
pht('Mail sent! You can view details by running this command:'),
$mail->getID());
}
}
diff --git a/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php
index f29a63c2eb..1f4f5a3e2a 100644
--- a/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php
+++ b/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php
@@ -1,230 +1,230 @@
<?php
final class PhabricatorMailManagementShowOutboundWorkflow
extends PhabricatorMailManagementWorkflow {
protected function didConstruct() {
$this
->setName('show-outbound')
->setSynopsis(pht('Show diagnostic details about outbound mail.'))
->setExamples(
'**show-outbound** --id 1 --id 2')
->setArguments(
array(
array(
'name' => 'id',
'param' => 'id',
'help' => pht('Show details about outbound mail with given ID.'),
'repeat' => true,
),
array(
'name' => 'dump-html',
'help' => pht(
'Dump the HTML body of the mail. You can redirect it to a '.
'file and then open it in a browser.'),
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$ids = $args->getArg('id');
if (!$ids) {
throw new PhutilArgumentUsageException(
pht(
"Use the '%s' flag to specify one or more messages to show.",
'--id'));
}
foreach ($ids as $id) {
if (!ctype_digit($id)) {
throw new PhutilArgumentUsageException(
pht(
'Argument "%s" is not a valid message ID.',
$id));
}
}
$messages = id(new PhabricatorMetaMTAMail())->loadAllWhere(
'id IN (%Ld)',
$ids);
if ($ids) {
$ids = array_fuse($ids);
$missing = array_diff_key($ids, $messages);
if ($missing) {
throw new PhutilArgumentUsageException(
pht(
'Some specified messages do not exist: %s',
implode(', ', array_keys($missing))));
}
}
$last_key = last_key($messages);
foreach ($messages as $message_key => $message) {
if ($args->getArg('dump-html')) {
$html_body = $message->getHTMLBody();
- if (strlen($html_body)) {
+ if (phutil_nonempty_string($html_body)) {
$template =
"<!doctype html><html><body>{$html_body}</body></html>";
$console->writeOut("%s\n", $html_body);
} else {
$console->writeErr(
"%s\n",
pht('(This message has no HTML body.)'));
}
continue;
}
$info = array();
$info[] = $this->newSectionHeader(pht('PROPERTIES'));
$info[] = pht('ID: %d', $message->getID());
$info[] = pht('Status: %s', $message->getStatus());
$info[] = pht('Related PHID: %s', $message->getRelatedPHID());
$info[] = pht('Message: %s', $message->getMessage());
$ignore = array(
'body' => true,
'body.sent' => true,
'html-body' => true,
'headers' => true,
'attachments' => true,
'headers.sent' => true,
'headers.unfiltered' => true,
'authors.sent' => true,
);
$info[] = null;
$info[] = $this->newSectionHeader(pht('PARAMETERS'));
$parameters = $message->getParameters();
foreach ($parameters as $key => $value) {
if (isset($ignore[$key])) {
continue;
}
if (!is_scalar($value)) {
$value = json_encode($value);
}
$info[] = pht('%s: %s', $key, $value);
}
$info[] = null;
$info[] = $this->newSectionHeader(pht('HEADERS'));
$headers = $message->getDeliveredHeaders();
if (!$headers) {
$headers = array();
}
$unfiltered = $message->getUnfilteredHeaders();
if (!$unfiltered) {
$unfiltered = array();
}
$header_map = array();
foreach ($headers as $header) {
list($name, $value) = $header;
$header_map[$name.':'.$value] = true;
}
foreach ($unfiltered as $header) {
list($name, $value) = $header;
$was_sent = isset($header_map[$name.':'.$value]);
if ($was_sent) {
$marker = ' ';
} else {
$marker = '#';
}
$info[] = "{$marker} {$name}: {$value}";
}
$attachments = idx($parameters, 'attachments');
if ($attachments) {
$info[] = null;
$info[] = $this->newSectionHeader(pht('ATTACHMENTS'));
foreach ($attachments as $attachment) {
$info[] = idx($attachment, 'filename', pht('Unnamed File'));
}
}
$all_actors = $message->loadAllActors();
$actors = $message->getDeliveredActors();
if ($actors) {
$info[] = null;
$info[] = $this->newSectionHeader(pht('RECIPIENTS'));
foreach ($actors as $actor_phid => $actor_info) {
$actor = idx($all_actors, $actor_phid);
if ($actor) {
$actor_name = coalesce($actor->getName(), $actor_phid);
} else {
$actor_name = $actor_phid;
}
$deliverable = $actor_info['deliverable'];
if ($deliverable) {
$info[] = ' '.$actor_name;
} else {
$info[] = '! '.$actor_name;
}
$reasons = $actor_info['reasons'];
foreach ($reasons as $reason) {
$name = PhabricatorMetaMTAActor::getReasonName($reason);
$desc = PhabricatorMetaMTAActor::getReasonDescription($reason);
$info[] = ' - '.$name.': '.$desc;
}
}
}
$info[] = null;
$info[] = $this->newSectionHeader(pht('TEXT BODY'));
- if (strlen($message->getBody())) {
+ if (phutil_nonempty_string($message->getBody())) {
$info[] = tsprintf('%B', $message->getBody());
} else {
$info[] = pht('(This message has no text body.)');
}
$delivered_body = $message->getDeliveredBody();
if ($delivered_body !== null) {
$info[] = null;
$info[] = $this->newSectionHeader(pht('BODY AS DELIVERED'), true);
$info[] = tsprintf('%B', $delivered_body);
}
$info[] = null;
$info[] = $this->newSectionHeader(pht('HTML BODY'));
- if (strlen($message->getHTMLBody())) {
+ if (phutil_nonempty_string($message->getHTMLBody())) {
$info[] = $message->getHTMLBody();
$info[] = null;
} else {
$info[] = pht('(This message has no HTML body.)');
$info[] = null;
}
$console->writeOut('%s', implode("\n", $info));
if ($message_key != $last_key) {
$console->writeOut("\n%s\n\n", str_repeat('-', 80));
}
}
}
private function newSectionHeader($label, $emphasize = false) {
if ($emphasize) {
return tsprintf('**<bg:yellow> %s </bg>**', $label);
} else {
return tsprintf('**<bg:blue> %s </bg>**', $label);
}
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Aug 14, 3:58 AM (3 d, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
194877
Default Alt Text
(14 KB)

Event Timeline