ryanb / letter_opener

Preview mail in the browser instead of sending.
MIT License
3.73k stars 237 forks source link

Avoid four slashes for `file` protocol #183

Closed phylor closed 2 years ago

phylor commented 3 years ago

To open the HTML rendering of mails, letter_opener uses the file protocol. It always adds three slashes /// and then concatenates the file name to it. If the file name starts with a slash as well (unix based systems and using absolute paths), we end up having 4 consecutive slashes.

On some systems (macOS as reported in #180 and - for me - on Linux) this results in invalid file paths and the file cannot be opened.

For me, this happens using xdg-open and qutebrowser as a browser. The following fails for me (qutebrowser is looking for file://tmp/test.html):

xdg-open file:////tmp/test.html

Both firefox file:////tmp/test.html and qutebrowser file:////tmp/test.html open the file correctly. So this could also be a problem with xdg-open. I don't think that 4 slashes are correct though.

So I would still propose to fix this (fixing it also for the macOS people). But there might be a cleaner solution than my proposal.

phylor commented 3 years ago

@ryanb @nashby I realize that the last release of this gem was in 2018. Are you still maintaining the gem or is it end of life?

nashby commented 3 years ago

@phylor hey! yes, we still maintain this gem. I'll try to look into this issue when I have time. As far as I remember 4 slashes is not a random thing here, it was optimal solution to work with many OSes as possible

phylor commented 3 years ago

@nashby Great, thanks! :tada:

nashby commented 2 years ago

@phylor hey! Could you please test current master and see if it works for you? By default we don't add file:// prefix anymore so it might work in your case by default. And if it's not then you can add any prefix with following config:

LetterOpener.configure do |config|
  config.file_uri_scheme = 'file://'
end
phylor commented 2 years ago

@nashby master works for me without any configuration option. Thank you very much! :+1: