Skip to content

Support absolute paths in setHTMLBody for automatic CID embedding#103

Merged
dg merged 1 commit into
nette:masterfrom
Kaczmi:allow-leading-slash-4.0.3
Apr 23, 2026
Merged

Support absolute paths in setHTMLBody for automatic CID embedding#103
dg merged 1 commit into
nette:masterfrom
Kaczmi:allow-leading-slash-4.0.3

Conversation

@Kaczmi
Copy link
Copy Markdown
Contributor

@Kaczmi Kaczmi commented Oct 9, 2025

  • bug fix / new feature? not sure
  • BC break? yes

Currently, setHTMLBody in Nette\Mail supports a basePath for automatically embedding local images as CID attachments. Relative paths like img/logo.svg work correctly, but absolute paths starting with a slash (e.g. /img/logo.svg) are ignored and not embedded.

This PR updates the logic so that images referenced with a leading slash are correctly resolved relative to the provided basePath, allowing projects that use Webpack-generated assets (which always output to a fixed public folder with leading slashes) to work without breaking existing templates that rely on relative paths.

Here, basePath for mails is intended to represent the www folder of the application, making it clear that absolute paths are resolved relative to the web root.

@Kaczmi Kaczmi force-pushed the allow-leading-slash-4.0.3 branch from aa94a75 to 941ea7c Compare October 9, 2025 13:35
@dg dg force-pushed the master branch 4 times, most recently from af1d65e to 93bc1c9 Compare December 30, 2025 00:48
@dg dg force-pushed the master branch 2 times, most recently from 5aeaf1e to 82f31ef Compare February 10, 2026 02:48
@dg dg force-pushed the master branch 5 times, most recently from e5578f0 to e220d35 Compare February 24, 2026 16:12
@dg dg force-pushed the master branch 10 times, most recently from d266800 to 189277a Compare March 31, 2026 17:42
@dg dg merged commit d356e6e into nette:master Apr 23, 2026
@dg
Copy link
Copy Markdown
Member

dg commented Apr 23, 2026

Thanks for the PR, but I'd like to pass on this one.

The title says „absolute paths", but the change actually reinterprets root-relative paths (/foo.png) as relative to $basePath. That only works when $basePath equals the document root and images live directly under it. I'd prefer to keep setHtmlBody predictable: relative paths are resolved against $basePath, everything else is left alone.

If you need root-relative URLs from templates to be embedded, a cleaner approach would be an explicit opt-in, e.g. a URL prefix that gets stripped before resolving against $basePath. That keeps the semantics of / clear and gives the caller a real knob for URL-to-filesystem mapping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants