-
-
Notifications
You must be signed in to change notification settings - Fork 152
Allow specifying delivery whitelists for the redirect plugin #19
Conversation
@@ -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']) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, fixed.
Squashed. Ready to merge from my POV. |
no, it is not ready as the Swiftmailer PR is not merged yet :) |
The |
@fabpot can you point out an example of a list definition in an xsd? |
@@ -62,4 +63,10 @@ | |||
<xsd:enumeration value="none" /> | |||
</xsd:restriction> | |||
</xsd:simpleType> | |||
|
|||
<xsd:complexType name="delivery_whitelist"> |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind.
PR squashed. |
<xsd:sequence> | ||
<xsd:element name="pattern" type="xsd:string" minOccurs="0" maxOccurs="unbounded" /> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
</xsd:schema> |
There was a problem hiding this comment.
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)
btw, if you want an example loading fixture files in the testsuite, look at the MonologBundle setup |
Added a bunch of unit tests for various configuration scenarios. Could you review again? |
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); |
There was a problem hiding this comment.
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
Fixed. Thanks for the heads up regarding XML configuration. |
Schema uses xsd:all egain. Unused use statement removed. |
So, ready for (hopefully) final review. |
Squashed to ease review. |
@@ -62,6 +62,8 @@ public function getConfigTreeBuilder() | |||
->thenInvalid('The %s encryption is not supported') | |||
->end() | |||
->end() | |||
->end() | |||
->children() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
note that if the XSD does not allow to allow any number of |
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). |
To demonstrate, added full.(xml|yml|php) test case. |
@lstrojny exactly, and this is not consistent with all the other Symfony configurations for their XMLr representations. |
@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 |
Done. |
@stof anything I can do about the failing pull request. |
oups, I forgot the minimum-stability. Please add |
Done. |
@lstrojny now, you still need to take into account my previous comment about the XML config and it will be fine |
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. |
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 |
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 :) |
Alright, I can change that but I feel that the XML is much less XMLish (if that’s even a word). |
So, the from my POV worse XML structure is implemented. We need to use a |
@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 |
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 |
Allow specifying delivery whitelists for the redirect plugin
…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
This PR is related to swiftmailer/swiftmailer#234 and allows Symfony users to configure delivery whitelists for the SwiftMailer RedirectingPlugin.