Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Fixes #73 : allow Message to not has "To" header #160

Closed
wants to merge 3 commits into from

Conversation

samsonasik
Copy link
Contributor

Fixes #73

Check at least one of "To", "Cc", and "Bcc"

@glensc
Copy link
Contributor

glensc commented Jul 20, 2017

LGTM

@oodgaard
Copy link

oodgaard commented Feb 27, 2018

+1
Just hit this issue. Am forced to change to SMTP, if possible.

$this->transport->send($message);
}

public function testDonotAllowMessageDoesnotHasToAndCcAndBccHeader()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix test method name, I think it should be:
testDoNotAllowMessageWithoutToAndCcAndBccHeaders

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


public function testDonotAllowMessageDoesnotHasToAndCcAndBccHeader()
{
$this->expectException('Zend\Mail\Exception\RuntimeException');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this before line which should thrown an exception. Like that it's confusing, and the exception could be thrown anywhere below. Can we also use ::class notation, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -148,8 +148,14 @@ protected function prepareRecipients(Mail\Message $message)
{
$headers = $message->getHeaders();

if (! $headers->has('to')) {
throw new Exception\RuntimeException('Invalid email; contains no "To" header');
if (! ($hasTo = $headers->has('to')) && ! $headers->has('cc') && ! $headers->has('bcc')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a bit confused with this assignment in if statement, in general I like them, but only when we have single condition, here it's more tricky so I would suggest to move assignment before the if statement and then use the variable in the statement with other checks:

$hasTo = $headers->has('to');
if (! $hasTo && ! $headers->has('cc') && ! $headers->has('bcc')) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Ocramius Ocramius self-assigned this Mar 1, 2018
@Ocramius Ocramius added this to the 2.9.0 milestone Mar 1, 2018
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

Ocramius added a commit that referenced this pull request Mar 1, 2018
@Ocramius
Copy link
Member

Ocramius commented Mar 1, 2018

Manually merged via 8ca640a, thanks!

@Ocramius Ocramius closed this Mar 1, 2018
@samsonasik samsonasik deleted the fix-73 branch March 1, 2018 20:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants