Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow custom HTML in HTML Emails #8026

Merged
merged 3 commits into from
Feb 26, 2018

Conversation

nickvergessen
Copy link
Member

We need to allow custom HTML, so e.g. the activity app can link file names to the file in the web view.
Currently that is not possible because all HTML is escaped.

The question is if we want to do it the simple way like this, or if we want to add a flag/new method that does not automatically-escape the input.

@MorrisJobke
Copy link
Member

Then we need to check if all callers properly escape this and document this in the PHPDoc of the method, but I'm fine with that to not clutter the API even more.

@codecov
Copy link

codecov bot commented Jan 24, 2018

Codecov Report

Merging #8026 into master will decrease coverage by <.01%.
The diff coverage is 56.25%.

@@             Coverage Diff              @@
##             master    #8026      +/-   ##
============================================
- Coverage     51.69%   51.69%   -0.01%     
  Complexity    25395    25395              
============================================
  Files          1599     1599              
  Lines         95114    95120       +6     
  Branches       1377     1377              
============================================
+ Hits          49167    49168       +1     
- Misses        45947    45952       +5
Impacted Files Coverage Δ Complexity Δ
lib/private/Share20/Manager.php 86.64% <0%> (ø) 236 <0> (ø) ⬇️
core/Controller/LostController.php 80.39% <100%> (ø) 32 <0> (ø) ⬇️
apps/sharebymail/lib/ShareByMailProvider.php 58.8% <50%> (ø) 85 <0> (ø) ⬇️
lib/private/Mail/EMailTemplate.php 60% <54.54%> (-0.45%) 43 <0> (ø)
lib/private/Security/CertificateManager.php 91% <0%> (-3%) 39% <0%> (ø)
lib/private/Server.php 83.28% <0%> (+0.09%) 282% <0%> (ø) ⬇️

@rullzer
Copy link
Member

rullzer commented Jan 24, 2018

Mmmm yes. lets do it like this for now we can always improve later.

@nickvergessen
Copy link
Member Author

@MorrisJobke can you generate a list for the appstore submissions?

@MorrisJobke
Copy link
Member

@MorrisJobke can you generate a list for the appstore submissions?

What do you mean by that?

@nickvergessen
Copy link
Member Author

which apps are using that method and might need adjustment

@MorrisJobke
Copy link
Member

addBodyText:

bildschirmfoto 2018-02-01 um 14 17 24

addBodyListItem:

bildschirmfoto 2018-02-01 um 14 19 34

addBodyButton:

bildschirmfoto 2018-02-01 um 14 20 52

@nickvergessen
Copy link
Member Author

Hmm while looking into a patch for the calendar, I realize why a parameter or second method would be better:

// before
$emailTemplate->addBodyText($this->l10n->t('We wanted to inform you that %s has published the calendar »%s«.', [$displayName, $calendarName]));

// after
$emailTemplate->addBodyText(
    htmlspecialchars($this->l10n->t('We wanted to inform you that %s has published the calendar »%s«.', [$displayName, $calendarName])),
    $this->l10n->t('We wanted to inform you that %s has published the calendar »%s«.', [$displayName, $calendarName])
);

basically we need to touch all usages of those methods which use fallback $plain = ''.

Or we automatically encode when plain is the fallback, because that means you want to display the same string and there should not be HTML inside, so we need to special char it.

@MorrisJobke
Copy link
Member

Hmm while looking into a patch for the calendar, I realize why a parameter or second method would be better:

I'm fine with that. You need to provide the HTML and the plain text separately. If you want to put HTML in there it should also not present in the plain text (or at least in a different way). So this is okay. Let's go for the "two strings needs to be passed" method I would say.

Signed-off-by: Joas Schilling <coding@schilljs.com>
@juliusknorr
Copy link
Member

Or we automatically encode when plain is the fallback, because that means you want to display the same string and there should not be HTML inside, so we need to special char it.

I think a fallback makes sense here - use the text for both and escape the html if only one string is provided.

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen nickvergessen force-pushed the feature/noid/allow-custom-html-in-html-emails branch from 8a9089f to 339e320 Compare February 15, 2018 11:20
@nickvergessen
Copy link
Member Author

I think a fallback makes sense here - use the text for both and escape the html if only one string is provided.

That's what we do now, I talked to morris a bit more and explained the use cases.

@@ -420,7 +420,7 @@ protected function ensureBodyIsOpened() {
/**
* Adds a paragraph to the body of the email
*
* @param string $text
* @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
Copy link
Member

Choose a reason for hiding this comment

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

Please put this also in the public interface ;)

Signed-off-by: Joas Schilling <coding@schilljs.com>
@nickvergessen nickvergessen merged commit 226e636 into master Feb 26, 2018
@nickvergessen nickvergessen deleted the feature/noid/allow-custom-html-in-html-emails branch February 26, 2018 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants