[Typo3] html mailer and stylesheets

Cédric CHAMPEAU cedric.champeau at e-manation.com
Wed Mar 23 11:55:36 CET 2005


Hi,
 
I had the following problem with Outlook : when I sent a newsletter from
Typo3 based on CSS stylesheets, the images used in the stylesheet were not
displayed unless Outlook was configured to display all images whatever the
site. The reason is that Outlook disables image downloading by default for
"untrusted" sources. (Newsletter are looking good in Thunderbird).
 
I did notice that the newsletter extension did embed the images into the
e-mail, but there was still a problem with embedded stylesheets (stylesheets
defined *into* the html file): images did not get displayed. This is a
problem where you define styles like this :
 
.mystyle
{ background-image: url(/path/to/my/image); }
 
Therefore, I modified the t3lib_htmlmail class in order to embed images that
were defined into embedded stylesheets. It's a dirty trick, which works for
me. Here's the code, don't know if it should be submitted as a bug or not :
 
Insert line 841, file typo3/t3lib/class.t3lib_htmlmailer.php
 
  // PATCH BEGIN
  // Date : 2005-03-23
  // Author : Cedric CHAMPEAU, e-manation
  // Description : quick and dirty fix to embed images linked into embedded
stylesheets
  preg_match_all("/url\((.*)\)/", $html_code, $allcodepieces); // looks for
url(/path/to/file) matches in the html code. Ugly because to simple to be
perfect matcher
  $codepieces=$allcodepieces[1];
    $pieces = count($codepieces);
  for($i=0; $i < $pieces; $i++) {
      $imageData=array();
    $imageData["ref"]=$codepieces[$i];
    $imageData["quotes"]=(substr($codepieces[$i],strpos($codepieces[$i],
$imageData["ref"])-1,1)=='"')?'"':'';  // Finds out if the value had quotes
around it
      $imageData["subst_str"] =
$imageData["quotes"].$imageData["ref"].$imageData["quotes"]; // subst_str is
the string to look for, when substituting lateron
    if ($imageData["ref"] &&
!strstr($this->image_fullpath_list,"|".$imageData["subst_str"]."|")) {
     $this->image_fullpath_list.="|".$imageData["subst_str"]."|";
     $imageData["absRef"] = $this->absRef($imageData["ref"]);
     $this->theParts["html"]["media"][]=$imageData;
    }    
  }
  // PATCH END
 
 
I still have one problem, and I've not yet found if it was just that I
missed another part of the code to patch : the images defined into embedded
stylesheets appear as attached files in Outlook, while the newsletter is now
broken in Thunderbird (images defined into the stylesheet do not appear
anymore, and Thunderbird displays many attached parts).
 
Cédric Champeau
 



More information about the TYPO3-english mailing list