Problem description
The message settings are confusing and over-complex. We are starting a new branch so it's a great time to make it better.
1. The existing defaults are wrong. The main purpose of using this module as the mail formatter is for HTML mails - for plain text might as well use the Default PHP mailer. So HTML should be the default and also a plain text version is a good idea.
2. The GUI is confusing. Improve the descriptions. Improve the terminology, in particular the word "format" is unfortunate because "Text formats" are something else entirely, and something that we do want to configure in this module in future. Remove the setting "Respect format" which is hard to understand how it relates to "Format". Basically there are three options and so we should have a single field with three values: "always plain", "always HTML" and "keep existing".
3. Fix confusing configuration names to match the correct terminology:
convert_modeto
generate_plain</code</li> <li><code>formatto
content_type.filter_formattotext_format.
Do the same for message parameters, but continue to accept the old values for back-compatibility.
4. Fix some inconsistent and confusing logic.
- The setting
character_setshould not be affected configuration of content type (respect_format). - The parameter
$message['params']['content_type']should take precedence over any other input - the purpose of these parameters is to allow specific override of the normal settings.
5. Add a GUI for the filter format setting, restricting to formats that escape HTML. This should avoid confusion and improve security concerns about using an unsafe format.
Proposed resolution
Included in the above.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | swiftmailer.respect_format.3125041-interdiff-33-36.txt | 997 bytes | adamps |
| #36 | swiftmailer.respect_format.3125041-36.patch | 30.37 KB | adamps |
| #33 | swiftmailer.respect_format.3125041-33.patch | 30.26 KB | adamps |
Comments
Comment #2
geek-merlinThanks for fucusing the reasoning and pointing out what this ultimately is: A D7 zombie.
Let's give it a honorable thanks and put it to rest.
Comment #3
adamps commentedHere's a patch. I've not properly tested it yet but it gives an idea what we have in mind.
Comment #4
adamps commentedComment #6
adamps commentedComment #7
adamps commentedComment #9
adamps commentedComment #10
geek-merlinGreat stab at this! Code looks quite straightforward.
You hardly ever want to use
==in PHP. Use===.What the heck does this? If it need be that complicated, let's add a code comment. Or is it simply
rtrim($header_value, ';')?Comment #11
berdirFirst, more or less random thoughts:
Not sure if we should treat this and #3125041: Clarify and simplify message settings as separate issues, as usually you'd use them together. Disable respect format and configure a text format so that all plain mails are converted to basic HTML.
A bit hard to keep it separate when reviewing/discussing. As @AdamPS said in #3125042: [META] New & improved format conversions, this was a valid option to send out simple but decently looking e-mails that did not require custom code or extra modules and a lot of configuration/overrides. I'm pretty sure that there are plenty of sites out there where the user.module e-mail configuration contains huge chunks of HTML, because it works in combination with those settings. And that's not really a security issue for those e-mails because configuring them requires administer users permission anyway. But yes, it might be for others if they put unvalidated user input directly in the mail body.
I'm not sure about the exact attack vectors, since e-mail HTML has to be treated as unsafe anyway as everyone can just send you whatever they want directly anyway. But I suppose you could at least trick site admins into doing things as they might trust the e-mails they receive from Drupal and what they show as links and so on.
If we'd keep the other setting then this would indeed be fine to remove, since the other would create markup objects of everything anyway then. If we want to remove that too it's a bit more complicated IMHO.
I agree that these features and options are tricky, but the problem is that the mail API is pretty weird and only saw very limited changes in D8, so it's a bit too simplified to say it's just a D7 leftover and is fine to remove everything. There are a few cases where core actually does pass through markup objects, for example contact_mail() #2666160: contact_mail() casts rendered markup to string, but most e-mails don't and swiftmailer doesn't actually define the API, so it has to deal with what it gets (or rely on other modules and custom code to do so, but that does seem like a bit of a UX regression?)
I still feel like it would be acceptable in terms of security to make the format setting visible, remove this and have very clear descriptions and instructions in the UI that say that you either need to make sure that the only e-mails that are sent contain only trusted content (which I think is the case for most sites) and that misconfiguring it is not a security issue. Having it in the UI actually gives us a place to explain it, as exposed to people using config import/export or drush to change it. Core isn't different, nothing stops you from granting anonymous users access to the Full HTML format, the only "protection" is the help text that says "Improper text format configuration is a security risk. Learn more on the Filter module help page." on /admin/config/content/formats.
Comment #12
adamps commentedThanks @Berdir. That makes sense.
There's one part that I don't understand, which is why you feel the two issues are related. With my current level of understanding, this issue is safe and removes something that's of no use. The other issue is complicated and we need to think carefully about what to do considering the points that you raise. I imagine that your comments here apply to the other issue.
NB This issue will make the code run as if "Respect format" is always false. From reading your comments I wonder if you imagine the opposite??
If you feel we might need this setting then please can you explain a case where it is useful to have "Respect format" set to true? I explain in the issue summary "proposed resolution" that I believe there are better solutions available.
Comment #13
berdirYeah, I missed that this would make the setting always FALSE. But wouldn't that mean that it would be impossible to *not* send some mails als plain text and some as HTML? I'm not sure if that should really be the goal here, I'm sure some prefer to only send plain text HTML mails, also because sending out good looking HTML mails takes time.
Per your own suggestion, I would propose that we first have real-life functional tests at least for contact and user e-mails, to see what exactly is being sent with common setting combinations for format, respect format, and filter format (plain text | basic html)? And it might also be a good idea to include an integration test with simplenews, which has per-newsletter settings to send or not send HTML mails, removing the respect format setting would break those configuration settings?
Comment #14
geek-merlin> But wouldn't that mean that it would be impossible to *not* send some mails als plain text and some as HTML?
Hmm, good point. Re-thinking about this.
Comment #15
adamps commented@Berdir yes good points.
See the IS. Can use mailsystem to configure mails that should be plain text to use the default PHP formatter not swiftmailer.
That's a good case. It will be important to know what simplenews sets for the content type header and whether the body implements MarkupInterface.
I propose that it's not the job of Swiftmailer Core to allow detailed per module/id config of the format. However there are perhaps three valid cases:
A complication in the third case is how to decide that the existing format is. Drupal Core sometimes sends mails with body containing markup but with content header of plain.
Comment #16
adamps commentedSo in conclusion, the function being offered here is fine, it's just the presentation that's confusing. As we are starting a new major version we have a chance to fix this. I've updated the IS accordingly.
Comment #17
adamps commentedComment #18
adamps commentedI've tried to simplify and remove some really baffling behaviour but minimise breakage to existing sites.
The idea is the same as we have been discussing in other issues: the mail plug-in should not be globally altering content. Instead we can do that case-by-case at the application layer, see #3125477: Add sub-module for more advanced format conversions.
Let's see how the patch works. Comments welcome.
Comment #20
adamps commentedNo I discarded too much. Here's a new version that should be good for BC.
Comment #22
adamps commentedComment #24
adamps commentedComment #25
adamps commentedOK I took out one more part, so now it's just some remapping in preparation for other issues that allow configuration of text format.
Comment #26
adamps commentedComment #27
adamps commentedMinor optimisation
Comment #29
adamps commentedComment #30
adamps commentedPatch coming up soon to match the latest IS. I feel this one is nearly ready now.
Sorry it's been another of my "evolving" issues that keep changing title. At first I wanted to cut some options. After some detailed research and checking I concluded that the existing settings each have a purpose - just that it wasn't clearly explained.
Comment #31
adamps commentedComment #33
adamps commentedComment #34
adamps commentedOK I think I'm ready on this one now. Comments welcome. I will commit after 1 more week anyway because this blocks working on other issues.
This issue doesn't remove any features but it does make things clearer and safer.
Comment #35
geek-merlinNice!
I did not thoroughly review it yet, but the configuration sounds more intuitive really. Will look at this later again.
And yes, this should not block other patches for too long.
Comment #36
adamps commentedCouple of small fixes
Comment #37
adamps commentedThis issue is blocking a stable release and also a beta that supports Drupal 9. After waiting one month I propose that we need to move on, so I will commit it at the start of next week. It would be great to have any more comments first, thanks.
Comment #38
berdirWe have a task to try it out in our project, but didn't get to it yet. Hectic times :) I'll try to have a quick look at least over the weekend.
Comment #39
adamps commentedGreat thanks Berdir. Yes we are all busy. Hopefully it will be worth it to get a stable release with D9 support.
Comment #40
geek-merlinWhen that patch was uploaded, i thoroughly reviewed it.
I thought a can test it soon-ish and give feedback then, but then also got hectic times.
So let's at least give feedback on the code: I like it code-wise as a big win.
So when someone did a manual test, let's get it in and build on it.
Comment #42
adamps commentedThanks @geek-merlin. We need to press on as this is blocking progress to D9 support and stable release.
Now that the general principle and ideas are supported I propose that's enough to commit. If someone tests it and finds a bug then we can raise another issue to fix it.
Comment #43
berdirI've been testing this and 2.x in general a bit over the last days and it seems to work well.
Comment #44
adamps commented@Berdir Great thanks for confirmation. One last key non-BC issue #3126935: Improvements to plaintext conversion before I create a beta later in the week if you have a chance to look.