When an image is uploaded to an imagefield cck field and that image has spaces in the name, that image is often not displayed well in the HTML mail.

In the resulting email the url of that image has 2 spaces in stead of one.

the image uploaded is called Only local images are allowed.. In the nodeview of the newsletter node on the site it is displayed ok. in the email the url is changed to
Only local images are allowed.
The one space is replace by 2x %20, which off course results in a 404 for that image.

The problem seems to be when drupal_mail is called. Before that the node_body is ok, after that the "message" often contains a new_line after the space, which is then translated by mimemail into 2 spaces (%20).

This could be seen as a mimemail problem or a drupal_mail problem, but I place it here because simplenews calls them both.

I could only solve it by rewriting the simplenews-newsletter-body.tpl.php for the images:

             <?php
                  $image = $node->field_newsletterimage[0];
            
	          $path = substr($image['filepath'], 0, strrpos($image['filepath'],"/"));
	          $file = substr($image['filepath'], strrpos($image['filepath'],"/"));
	          $url = $path."/".rawurlencode($file);
            ?>
  	    <img src="<?php print $GLOBALS['base_url'].'/'.$url;?>" title='<?php print ($image["data"]["title"]) ?>' />

(rawurlencode gives a + with a space and that is not abbreviated by drupal_mail)

But this is not a proper solution.

I think simplenews somewhere has to do this better (with some $regexp magic that I'm not familiar enough with), to solve it.

Comments

catorghans’s picture

Should have done a preview:

The line that starts with: the image uploaded...

should be
the image uploaded is called <img src="/sites/default/files/testimagewitha space.jpg" />. In the nodeview of the newsletter node on the site it is displayed ok. in the email the url is changed to
<img src="#siteurl/sites/default/files/testimagewitha%20%20space.jpg" />

pharoz’s picture

Subscribing. I'm also seeing the same issue.

catorghans, I tried applying your rewrite, but I'm still getting the same result. Images with spaces in them don't render due to the extra space.

pharoz’s picture

I'm testing this out with the transliteration module to remove space in file uploads. Hope this works....

http://drupal.org/project/transliteration

EDIT: Cool! This works... uploaded images with spaces gets the spaces replace with underscore (_).

sutharsan’s picture

This can be solved with some additional code in simplenews_html_to_text() which performs the right conversion on the image src attribute. In a similar manner as _simplenews_absolute_mail_urls() handles href attributes in a tags. Anyone want to write this?

sutharsan’s picture

Status: Active » Closed (duplicate)

This issue is a duplicate of #348327: Soft-wrapping in drupal_wrap_mail() breaks URLs with white-spaces which is a Mime mail issue. On second thought it can not be solved in Simplenews.