Skip to content

Commit

Permalink
add more delimiters in ResendMailCommand prompts. (space and ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-d-h committed Jan 3, 2024
1 parent d66ff40 commit 1bfe419
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/Commands/ResendMailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,47 @@ public function handle(): int
{
$uuid = $this->argument('uuid');

$mail = Mail::where('uuid', $uuid)->first();
$mail = mail::where('uuid', $uuid)->first();

if (is_null($mail)) {
$this->components->error("Mail with UUID: \"{$uuid}\" does not exist");
$this->components->error("Mail with uuid: \"{$uuid}\" does not exist");

return Command::FAILURE;
}

info('For the next prompts you can input multiple email addresses by separating them with a comma.');

[$to, $cc, $bcc] = $this->promptEmailInputs($mail);
[$to, $cc, $bcc] = $this->promptemailinputs($mail);

ResendMailJob::dispatch($mail, $to, $cc, $bcc);

$this->comment('All done');
info('All done');

return self::SUCCESS;
}

protected function promptEmailInputs(Mail $mail): array
{
$to = $this->argument('to') ?: explode(',', text(
$to = implode(',', $this->argument('to')) ?: text(
label: 'What email address do you want to send the mail to?',
placeholder: '[email protected]',
));
);

$cc = $this->option('cc') ?: explode(',', text(
$cc = implode(',', $this->option('cc')) ?: text(
label: 'What email address should be included in the cc?',
placeholder: '[email protected]',
));
);

$bcc = $this->option('bcc') ?: explode(',', text(
$bcc = implode(',', $this->option('bcc')) ?: text(
label: 'What email address should be included in the bcc?',
placeholder: '[email protected]',
));
);

$inputs = [
[&$to, $mail->to],
[&$cc, $mail->cc ?? []],
[&$bcc, $mail->bcc ?? []],
];

foreach ($inputs as [&$array, $default]) {
$array = array_filter(array_map(fn ($email) => trim($email), $array)) ?: $default;
foreach ([&$to, &$cc, &$bcc] as &$input) {
$input = array_filter(array_map(fn ($s) => trim($s), explode(' ', str_replace([',', ';'], ' ', $input))));
}

return [$to, $cc, $bcc];
return [$to ?: $mail->to, $cc ?: $mail->cc ?? [], $bcc ?: $mail->bcc ?? []];
}

protected function promptForMissingArgumentsUsing()
Expand Down

0 comments on commit 1bfe419

Please sign in to comment.