# Email reply includes inline styles with "incoming email prefer html" site setting on

**URL:** https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639
**Category:** Support
**Created:** [26 Aprile 2017, 1:33pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639 "2017-04-26T13:33:20Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)
#### Post date: [26 Aprile 2017, 1:33pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/1 "2017-04-26T13:33:20Z")

</div>

We have had the Site Setting “[incoming email prefer html](https://meta.discourse.org/t/linebreaks-in-posts-created-via-email-in-from-gmail/44676/12)” turned on for the past year.

It’s been working great, but yesterday, an email reply from a user came in with a bunch of inline styles showing up:

```plaintext
a {word-wrap:normal;word-break:break-word;}.background-contain {background-size:contain;}@media only screen and (max-width:600px) {.container {-webkit-text-size-adjust:none !important;}.container,.palm-one-whole {width:100% !important;min-width:100% !important;}.palm-one-half {width:50% !important;min-width:50% !important;box-sizing:border-box;}blockquote .container,blockquote .container div,blockquote .container table {width:auto !important;min-width:0 !important;position:relative !important;}img {max-width:100%;}.border-outer,.border-middle,.border-inner,.inner,[title="separator"] {width:100% !important;}.innercell {padding:8px !important;}.palm-block {display:block !important;}td.palm-one-whole {display:inline-block !important;padding:0;}td.palm-one-whole:first-child:not(:only-child) {margin-bottom:16px;}td.hostname {padding-top:3px !important;}}@media only screen and (min-width:601px) {.preview-card {max-width:600px !important;}}@media only screen and (min-device-width :320px) and (max-device-width :568px),only screen and (min-device-width :768px) and (max-device-width :1024px),only screen and (max-device-width:640px),only screen and (max-device-width:667px),only screen and (max-width:480px){.container {width:100% !important;min-width:100% !important;}.p,.small,li,font[size="2"],font[size="3"] {font-size:1em !important;}}@media only screen and (min-device-width :320px) and (max-device-width :568px),only screen and (min-device-width :768px) and (max-device-width :1024px),only screen and (min-device-width :1224px) {.message-wrapper {padding-top:6px;}.apple-only[style] {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.no-apple {display:none !important;}form {font-size:inherit;}input[type="text"] {height:43px;padding-left:4px !important;}button:hover {cursor:pointer;}}@media only screen and (min-device-width :1224px) {.apple-mail-form {display:block !important;background-color:white !important;}}* [office365] .outlook-com-hidden {display:none !important;}* [office365] .outlook-com-button {display:block;}* [office365] .outlook-com-only {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.ExternalClass {width:100%;}.ExternalClass .outlook-com-button {display:block;}.ExternalClass button {height:auto;}.ExternalClass .outlook-com-hidden {display:none !important;}.ExternalClass .outlook-com-only {display:block !important;max-height:none !important;line-height:normal !important;overflow:visible !important;height:auto !important;width:100% !important;position:relative !important;}.ExternalClass .ecxlabels {display:none !important;}.ExternalClass .ecxlabels {display:none !important;}.ExternalClass .ecxarrow {display:none !important;}.ExternalClass cite >div + div {padding:0 0 4px 0;}.ExternalClass .h1 {padding-bottom:5px;}.ExternalClass .h2 {padding-bottom:5px;}.ExternalClass .h3 {padding-bottom:5px;}.ExternalClass [lang="brand-pinterest"] {width:280px !important;}Duly noted. Thanks for the tip.

```

But if I click the email icon on the post, and then look at the HTML tab, it looks fine.

Any ideas how to fix this? I have the raw email saved which I can PM if there is any interest from someone on the team in helping to take a look.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [26 Aprile 2017, 1:45pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/2 "2017-04-26T13:45:01Z")

</div>

Now that we have a [Html To Markdown](https://github.com/discourse/discourse/blob/master/lib/html_to_markdown.rb) converter, I was thinking of ditching that setting and always converting HTML to Markdown. This would fix a lot of issues with HTML.

Would you be on-board with this or do you need HTML?

---

<div class="post-metadata">

### Author: ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)
#### Post date: [26 Aprile 2017, 1:46pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/3 "2017-04-26T13:46:44Z")

</div>

The main reason we are using this is because of the funky line break issues referenced in the topic I linked to in the OP. Would prefer things as markdown if it works well enough.

Happy to PM you this email as an example to try that with if you’d like.

**Update** pretty pleased with the test results @zogstrip showed me.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [26 Aprile 2017, 2:52pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/4 "2017-04-26T14:52:41Z")

</div>

Here’s to better 📨

[https://github.com/discourse/discourse/commit/b76674f6406f94539e6b3060d60c010f2de99d19](https://github.com/discourse/discourse/commit/b76674f6406f94539e6b3060d60c010f2de99d19)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [27 Aprile 2017, 2:05am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/5 "2017-04-27T02:05:33Z")

</div>

I don’t think this response is very clear..

1. We _always_ prefer plain text to html

2. If we cannot get the plain text we will use html because we were forced to

3. If we are forced to use HTML we will (now, this is new) convert it to Markdown

Can you confirm?

---

<div class="post-metadata">

### Author: ![mcwumbly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mcwumbly/32/103861_2.png) [@mcwumbly](https://meta.discourse.org/u/mcwumbly)
#### Post date: [27 Aprile 2017, 2:41am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/6 "2017-04-27T02:41:54Z")

</div>

If that’s the case then I think we should keep the site setting to prefer HTML so we can avoid he linebreak issue

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [27 Aprile 2017, 4:30am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/7 "2017-04-27T04:30:22Z")

</div>

My worry is switching the whole pipeline from plain text to HTML is a radical change this late in a release.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [27 Aprile 2017, 4:59am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/8 "2017-04-27T04:59:54Z")

</div>

The setting `incoming_email_prefer_html` has already existed for a year, this commit removes it.

I agree that this late in the game it probably does not make sense to switch everyone to the new converter, it is guaranteed to have edge cases, but stripping a “site setting” just cause we fixed the implementation of the “site setting” does not really make sense to me.

Instead if we feel this has too much risk just revert the commit for now. Or leave the setting and mark in (experimental)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [27 Aprile 2017, 5:06am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/9 "2017-04-27T05:06:46Z")

</div>

I am referring to what @mcwumbly proposed, not what @zogstrip implemented.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [27 Aprile 2017, 5:08am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/10 "2017-04-27T05:08:30Z")

</div>

Not following, @zogstrip removed the site setting in the commit he linked. There is no longer any way to prefer html.

> [@zogstrip](#):
>
> Now that we have a Html To Markdown converter, I was thinking of ditching that setting and always converting HTML to Markdown. This would fix a lot of issues with HTML.

In particular, I am not following how fixing the parsing and dropping the setting are in any way related.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [27 Aprile 2017, 5:35am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/12 "2017-04-27T05:35:36Z")

</div>

We should decide on one or the other paths. As I recall there were technical problems using the HTML as the preferred source. We should either

- resolve those problems and always prefer HTML

or

- give up and always prefer plain text

I don’t like carrying around random secondary code paths hidden behind Booleans that we aren’t even testing, and we have no idea if they even work. Sextuply so for the wild world of email…

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [27 Aprile 2017, 5:39am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/13 "2017-04-27T05:39:56Z")

</div>

The code path already hits, all the setting does is makes it hit more, and makes it easier for us to transition to HTML preferred

For example I would recommend turning that setting on, on meta, so we live with the new HTML to markdown converter

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [27 Aprile 2017, 1:15pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/14 "2017-04-27T13:15:14Z")

</div>

As it turns out, it’s sometimes better to use the markdown generated from the HTML rather than using the text version of the email.

So, I restored the site setting and enabled it here on meta so that we can exercise it 😉

[https://github.com/discourse/discourse/commit/0ec15af970e53abc0503ef867f9400a245e57845](https://github.com/discourse/discourse/commit/0ec15af970e53abc0503ef867f9400a245e57845)

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [26 Settembre 2017, 10:14am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/15 "2017-09-26T10:14:30Z")

</div>

> [@zogstrip](#):
>
> Now that we have a Html To Markdown converter, I was thinking of ditching that setting and always converting HTML to Markdown.

If the Html to Markdown converter works so well, might it also help better [identifying the breakpoint from where to strip previous posts](https://meta.discourse.org/t/previous-post-not-stripped-from-reply-by-email/63949)?

In a recent reply-by-email post where it completely failed to strip the previous post, I noticed that in the text part of email, the break point looked like this:

```plaintext
	username Full Name Title=20
September 25
Hi Name!

```

Whereas the html version looked like this:

```plaintext
  <div></div>

    <div style="margin-bottom:25px;">
  <table cellspacing="0" cellpadding="0" border="0">
    <tbody><tr>
      <td style="vertical-align:top;width:55px;">
        <img src="http://forum.mydomain.com/user_avatar/forum.mydomain.com/username/45/26_1.png" title="username" width="45" height="45">
      </td>
      <td>
        <a href="http://forum.mydomain.com/u/username" target="_blank" style="text-decoration: none; font-weight: bold; color: #006699;; font-size:13px;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;color:#3b5998;text-decoration:none;font-weight:bold">username</a>
          <a href="http://forum.mydomain.com/u/username" target="_blank" style="text-decoration: none; font-weight: bold; color: #006699;; font-size:13px;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;text-decoration:none;margin-left:7px;color: #3b5998;font-weight:normal;">Full Name</a>
          <span style="font-size:13px;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;text-decoration:none;margin-left:7px;color: #999;">Title</span>
        <br>
        <span style="text-align:right;color:#999999;padding-right:5px;font-family:'lucida grande',tahoma,verdana,arial,sans-serif;font-size:11px">September 25</span>
      </td>
    </tr>
  </tbody></table>
  <div style="padding-top:5px;">
<p style="margin-top:0; border: 0;">Hi Name</p>

```

In other words, I can see why discourse fails to identify the breakpoint based on the text version…

---

<div class="post-metadata">

### Author: ![tophee](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tophee/32/73406_2.png) [@tophee](https://meta.discourse.org/u/tophee)
#### Post date: [14 Aprile 2018, 10:33pm UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/16 "2018-04-14T22:33:35Z")

</div>

> [@tophee](#):
>
> If the Html to Markdown converter works so well, might it also help better identifying the breakpoint from where to strip previous posts?

Has this been considered?

In any case, I had another reply-by-email post today that failed to be stripped of any of the replied-to post and when I wanted to do that manually, I couldn’t do it because the resulting post would have been under 20 characters. So it struck me whether the min character requirement might at some point affect the processing of incoming emails? In other words: if someone replies by emails saying just “yes”, how is that email going to be processed?

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [27 Agosto 2020, 10:23am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/17 "2020-08-27T10:23:05Z")

</div>



---

<div class="post-metadata">

### Author: ![schleifer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schleifer/32/86416_2.png) [@schleifer](https://meta.discourse.org/u/schleifer)
#### Post date: [27 Agosto 2020, 10:34am UTC](https://meta.discourse.org/t/email-reply-includes-inline-styles-with-incoming-email-prefer-html-site-setting-on/61639/18 "2020-08-27T10:34:23Z")

</div>


