Workaround for Yahoo Mail’s hack
emile
It appears that Yahoo Mail doesn't want you pulling in outside stylesheets. When our Trader Interviews email arrived in a Yahoo Mail account, the <link> tag to our CSS was replaced with an <xlink> tag, rendering it unusable. Googling around, it appears that xlink is a valid XHTML tag, but it appears that Yahoo is using it just to break links to outside stylesheets, since they also replace a <body> tag with <xbody>. Our workaround is to replace any <link> tags to outside stylesheets with the contents of that outside stylesheet, before an email is sent. Below is a test file with the function we use to do such a thing.
CODE:
-
<?php
-
-
$text = '<LINK href="http://www.traderinterviews.com/main.css"type=text/css rel=stylesheet>Some more text';
-
-
echo StylesheetLink_Replace($text);
-
-
/*------------------------------------------------------------------------------
-
Name: StylesheetLink_Replace
-
Arguments: html: The HTML to search for <link> tags in
-
Returns: The HTML passed in, with <link> tags to external stylesheets
-
replaced with the contents of that file
-
Purpose: Replaces links to external stylesheets with the actual contents of
-
the stylesheet. Yahoo changes the <link tag to <xlink, making the
-
CSS not work. Embedding it gets around the problem.
-
Notes:
-
------------------------------------------------------------------------------*/
-
function StylesheetLink_Replace($html)
-
{
-
/* Find links to CSS files */
-
preg_match_all('/<LINK.*href="{0,1}.+\.css"{0,1}.*>/i',
-
$html, $whole_links);
-
-
/* Process each css link found */
-
foreach($whole_links[0] as $whole_link)
-
{
-
/* Find the css file path in the match */
-
preg_match('/href="{0,1}(.+\.css)"{0,1}/i', $whole_link, $paths);
-
-
/* Open the file and read it into a variable */
-
$handle = fopen($paths[1], 'rb');
-
-
/* If the remote file could be opened, do the replacement */
-
if($handle)
-
{
-
$contents = stream_get_contents($handle);
-
fclose($handle);
-
-
/* Replace the found string with the contents */
-
$html = str_replace($whole_link,
-
'<style type="text/css">'.$contents.'</style>',
-
$html);
-
}
-
/* Otherwise, remove the CSS link, since it couldn't be opened anyway */
-
else
-
{
-
$html = str_replace($whole_link, '', $html);
-
}
-
}
-
-
return $html;
-
}
-
-
?>
| 2.5 |
Posted in Technology |
No Comments »
