Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.

Allow specifying delivery whitelists for the redirect plugin #19

Merged
merged 5 commits into from
Aug 29, 2012
Merged

Allow specifying delivery whitelists for the redirect plugin #19

merged 5 commits into from
Aug 29, 2012

Conversation

lstrojny
Copy link
Contributor

This PR is related to swiftmailer/swiftmailer#234 and allows Symfony users to configure delivery whitelists for the SwiftMailer RedirectingPlugin.

@@ -126,6 +126,13 @@ public function load(array $configs, ContainerBuilder $container)
} else {
$container->setParameter('swiftmailer.single_address', null);
}

if (isset($config['delivery_whitelist']) && $config['delivery_whitelist']) {
Copy link
Member

Choose a reason for hiding this comment

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

it will always be set as a prototyped array node defaults to an empty array. So setting the parameter can be done by $container->setParameter('swiftmailer.delivery_whitelist', $config['delivery_whitelist']); for all cases.

And I don't think it makes sense to enable the plugin if the delivery_address is not set but only the whitelist (I even think that it may break things when sending a mail to a non-whitelisted message).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, fixed.

@lstrojny
Copy link
Contributor Author

Squashed. Ready to merge from my POV.

@stof
Copy link
Member

stof commented Aug 22, 2012

no, it is not ready as the Swiftmailer PR is not merged yet :)

@fabpot
Copy link
Member

fabpot commented Aug 22, 2012

The Resources/config/schema/swiftmailer-1.0.xsd file must be updated too for people using XML as a configuration format.

@lstrojny
Copy link
Contributor Author

@fabpot can you point out an example of a list definition in an xsd?

@lstrojny
Copy link
Contributor Author

@fabpot, @stof I'm not 100% sure with the XSD, could you have a look?

@@ -62,4 +63,10 @@
<xsd:enumeration value="none" />
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="delivery_whitelist">
Copy link
Member

Choose a reason for hiding this comment

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

should be "delivery-whitelist" (notice the dash instead of the underscode)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change that, but it’s the same convention as in auth-mode (the name) vs. auth_mode (the type).

Copy link
Member

Choose a reason for hiding this comment

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

nevermind.

@lstrojny
Copy link
Contributor Author

PR squashed.

<xsd:sequence>
<xsd:element name="pattern" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Copy link
Member

Choose a reason for hiding this comment

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

this is not the right thing. It will not work properly (add some unit tests loading a file with a whitelist containing 1 element and with a whitelist with several elements and you will see it fail).
This is an prototyped array node, so it should simply be a direct child of the config appearing many times (to be consistent with the other places using it and avoiding a hack to remove the extra level when coming from XML), and then using ->fixXmlConfig in the Configuration class (which is needed as XML would give us a different result for a single element or a collection of elements so we need tell the processor to take care of it)

@stof
Copy link
Member

stof commented Aug 22, 2012

btw, if you want an example loading fixture files in the testsuite, look at the MonologBundle setup

@lstrojny
Copy link
Contributor Author

Added a bunch of unit tests for various configuration scenarios. Could you review again?

@stof
Copy link
Member

stof commented Aug 28, 2012

Please also add a test with a single entry in the whitelist as it is a different case in XML

$container->setParameter('kernel.cache_dir', '/tmp');

$container->registerExtension(new SwiftmailerExtension());
$locator = new \Symfony\Component\Config\FileLocator(__DIR__ . '/Fixtures/config/' . $type);
Copy link
Member

Choose a reason for hiding this comment

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

Please add a use statement for the class

@lstrojny
Copy link
Contributor Author

Fixed. Thanks for the heads up regarding XML configuration.

@lstrojny
Copy link
Contributor Author

Schema uses xsd:all egain. Unused use statement removed.

@lstrojny
Copy link
Contributor Author

So, ready for (hopefully) final review.

@lstrojny
Copy link
Contributor Author

Squashed to ease review.

@@ -62,6 +62,8 @@ public function getConfigTreeBuilder()
->thenInvalid('The %s encryption is not supported')
->end()
->end()
->end()
->children()
Copy link
Member

Choose a reason for hiding this comment

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

this is useless. Please revert it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright

@stof
Copy link
Member

stof commented Aug 28, 2012

note that if the XSD does not allow to allow any number of whietlist-pattern chidlren (or whatever their name) andonly a single antiflod, it is not a big deal. The XSD should be as good as possible so that the autocompletion is good, but the final validation is handled bythe Configuration class anyway

@lstrojny
Copy link
Contributor Author

That’s actually the XSD for the pattern element, not the delivery_whitelist element. That's why it is unbounded. The delivery_whitelist element is only allowed once (as are spool and antiflood).

@lstrojny
Copy link
Contributor Author

To demonstrate, added full.(xml|yml|php) test case.

@stof
Copy link
Member

stof commented Aug 28, 2012

@lstrojny exactly, and this is not consistent with all the other Symfony configurations for their XMLr representations.
The previous one was better, even if the XSD was not perfect but I'm not sure it is possible to make it perfect (and I think there was a buggy case to fix).

@stof
Copy link
Member

stof commented Aug 29, 2012

@lstrojny The master branch now has a Travis config. Please rebase your branch so that it can test the PR:

$ git fetch upstream
$ git rebase upstream/master
$ git push origin delivery-whitelist --force

@lstrojny
Copy link
Contributor Author

Done.

@travisbot
Copy link

This pull request fails (merged 4addbfe into fcacc9e).

@lstrojny
Copy link
Contributor Author

@stof anything I can do about the failing pull request.

@stof
Copy link
Member

stof commented Aug 29, 2012

oups, I forgot the minimum-stability. Please add "minimum-stability": "dev" in the composer.json (you can do it in this PR)

@lstrojny
Copy link
Contributor Author

Done.

@travisbot
Copy link

This pull request passes (merged 7067ca9 into fcacc9e).

@stof
Copy link
Member

stof commented Aug 29, 2012

@lstrojny now, you still need to take into account my previous comment about the XML config and it will be fine

@lstrojny
Copy link
Contributor Author

OK, here is the alternative which I find way worse:

<swiftmailer:config>
   <swiftmailer:delivery-whitelist-patterns>
      <swiftmailer:delivery-whitelist>/foo\.com$/</swiftmailer:delivery-whitelist>
      <swiftmailer:delivery-whitelist>/bar\.com$/</swiftmailer:delivery-whitelist>
   </swiftmailer:delivery-whitelist-patterns>
<swiftmailer:config>

And in YAML:

swiftmailer:
  delivery_whitelist_patterns:
    - /foo\.com$/
    - /bar\.com$/

Both variants are worse than what we currently have.

@stof
Copy link
Member

stof commented Aug 29, 2012

I would keep a singular in YAML (there is only 1 whitelist) and use

<swiftmailer:config>
   <swiftmailer:delivery-whitelist-pattern>/foo\.com$/</swiftmailer:delivery-whitelist-pattern>
   <swiftmailer:delivery-whitelist-pattern>/bar\.com$/</swiftmailer:delivery-whitelist-pattern>
<swiftmailer:config>

This would allow you to simplify the Configuration class (the only thing needed to support the XML config is ->fixXmlConfig('delivery_whitelist_pattern', 'delivery_whitelist'))

@stof
Copy link
Member

stof commented Aug 29, 2012

Btw, looking at your proposal, it is still not following what I asked several types about prototyped array nodes as you are still suggesting a wrapper node :)

@lstrojny
Copy link
Contributor Author

Alright, I can change that but I feel that the XML is much less XMLish (if that’s even a word).

@lstrojny
Copy link
Contributor Author

So, the from my POV worse XML structure is implemented. We need to use a <xsd:choice/> instead of <xsd:all/> there to allow unbounded <delivery-whitelist-pattern/> which forces an order of elements.

@travisbot
Copy link

This pull request passes (merged 3930be7 into fcacc9e).

@stof
Copy link
Member

stof commented Aug 29, 2012

@lstrojny why much less XMLish ? XML does not require a wrapping tag around a set of children, and this will now be consistent with the way it is done everywhere else in Symfony

@lstrojny
Copy link
Contributor Author

It just doesn’t feel like idiomatic XML. Have a look at MathML, XHTML, Docbook, SOAP etc. If there is a list, it’s always <list><item/></list>. But it’s not worth a fight. If that's the way Symfony wants its XML configuration structured, let’s do it that way. I don’t need to agree.

stof added a commit that referenced this pull request Aug 29, 2012
Allow specifying delivery whitelists for the redirect plugin
@stof stof merged commit d2eae93 into symfony:master Aug 29, 2012
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Feb 24, 2015
…ct (TerjeBr)

This PR was submitted for the 2.6 branch but it was merged into the 2.3 branch instead (closes #4924).

Discussion
----------

[swiftmailer] Document whitelist option to email redirect

The redirectPlugin in switfmailer allows you to specify a white-list of regex's that matches email addresses that are still sent to, when redirecting all email to one address.

Code was added in PR [switfmailer/SwiftmailerBundle#19](symfony/swiftmailer-bundle#19)

Commits
-------

1448f58 More xml fixes
16907ed Xml changes and line-break changes
747199c Swiched mydomain and specialdomain
c35a26f Changes recommended by @cordoval
8c1da8a Changes recommended by @javierguiluz
4aa58a4 Changed line-breaks in text
217811d Added improvments from @wouterj
a4af6a0 fixed typo in "except"
6f64fdb Document whitelist option to email redirect
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants