contao / core

Contao 3 → see contao/contao for Contao 4
GNU Lesser General Public License v3.0
492 stars 213 forks source link

Newsletter (SMTP) chokes on inline images, fix proposed #5942

Closed felixww closed 11 years ago

felixww commented 11 years ago

Version: 3.0.3

Embedded images (using the data:image notation, RFC 2396) do work well in the email template, as long as you send using vanilla mail().

BUT as soon as you configure a SMTP server for the newsletter, a fatal error is thrown for /system/modules/core/library/Contao/Email.php:469 (for calling file_exists with a path containing the whole data:image blob). Also, Swiftmailer fopen will fail later.

I propose the following fix:

468-469: old version:

// Embed the image if the URL is now relative
if (!preg_match('@^https?://@', $src) && file_exists($this->strImageDir . $src))

468-469: fixed version:

// Embed the image if the URL is now relative
if (!preg_match('@^https?://@', $src) && (substr($src,0,5)!='data:') && file_exists($this->strImageDir . $src))

...since there's no need to embed an image already embedded.

Works for me with open_basedir both on and off.

(btw. the fix should also apply to Contao 2.11.x, here for /system/libraries/Email.php, line 444.)

Best flx.

leofeyer commented 11 years ago

Does this issue occur in Contao 3.1 as well? If so, how do I reproduce it?

felixww commented 11 years ago

to reproduce, insert an inline image into the standard newsletter template, e.g. the wikipedia example:

<img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Roter Punkt" />

I think yep, it should persist in 3.1, but cannot test, since i'm on bike holiday.

best, felix

leofeyer commented 11 years ago

I cannot reproduce the issue. The mail with the red dot was delivered correctly on my system.

felixww commented 11 years ago

Hallo Leo, ich werds mir in der 3.1x noch mal ansehen, sobald ich was besseres als ein Handy habe. Vielleicht hab ich eine Randbedingung uebersehen. Ich wuerd mich freuen, mal was konstruktives zu Contao beizusteuern. Viele Gruesse, Johannes