The discussion revolves around the behavior of iframes within oneboxes in emails. fefrei has developed a Onebox plugin that embeds interactive elements when certain links are posted, but it doesn’t work in emails due to iframes being replaced with a paragraph and a link.
simon explains that the replacement occurs in lib/email/styles.rb where iframes are removed and replaced with clickable links due to not being compatible with emails. The replacement code is also responsible for generating incorrect links, as seen in fefrei’s case.
simon provides a possible solution by modifying the plugin_styles method, but notes that it’s called after onebox_styles which makes it difficult to achieve the desired outcome. As an alternative, he suggests requiring sidekiq/testing to avoid caching issues.
fefrei proposes a fix to the general bug that generated the incorrect link and is waiting to see if it resolves the issue with their emails.
Obviously, this won’t work in emails and needs special handling. There already is some special handling for this by default – the iframe is replaced by a paragraph with a very strange link inside it:
What is causing this replacement? How can I modify how the onebox behaves in email? Can I simply disable it for emails and show the original link instead?
def onebox_styles
...
# iframes can't go in emails, so replace them with clickable links
@fragment.css('iframe').each do |i|
begin
src_uri = URI(i['src'])
# If an iframe is protocol relative, use SSL when displaying it
display_src = "#{src_uri.scheme || 'https://'}#{src_uri.host}#{src_uri.path}"
i.replace "<p><a href='#{src_uri.to_s}'>#{display_src}</a><p>"
rescue URI::InvalidURIError
# If the URL is weird, remove it
i.remove
end
end
You can add a plugin_callback to modify the html.
# this method is reserved for styles specific to plugin
def plugin_styles
@@plugin_callbacks.each { |block| block.call(@fragment, @opts) }
end
Unfortunately, plugin_styles is called after onebox_styles in the format_html method. If that order was reversed you could do what you want.
Doing any work with this file is slow because the methods are being cached by Sidekiq. To get around that I’ve been requiring sidekiq/testing at the start of 100-sidekiq.rb instead of sidekiq/pausable. To do that you have to comment out calls to Sidekiq.pause! in restorer.rb and backuper.rb.
The other option is to restart sidekiq every time you change the code.
display_src = "#{src_uri.scheme || 'https://'}#{src_uri.host}#{src_uri.path}"
```[/quote]
This is the culprit and generated the incorrect `httpspseuco.com`-link. I think this is a general bug and [proposed a fix](https://github.com/discourse/discourse/pull/4042) – with this, my emails should at least look okay.