media=<print|screen|all> selector stripped from mime_mail embedded css

jean-bernard.addor - April 24, 2009 - 13:53
Project:Mime Mail
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

In a drupal 6.10 site with Foliage as the default theme, it has been observed that emails send by Simple News in html and Mime Mail where completly black, instead of the the expected behavior: using the same color as the web site, which are provided by css.

After a troubleshouting described in the following link, it has been suspected that Mime Mail takes into account a file from Foliage named print.css. This files seems to be used on request by Iceweasel to produce b/w printings.

http://drupal.org/node/436706#comment-1514386

People sending emails complain that numerous recipients will never click on a black link which is event not underlined. Those link to the sender web site allow to send shorter emails which are easier to read and more apreciated from recipients.

As they could also be a problem in Foliage theme, the probleme will also be reported there.

#1

jean-bernard.addor - April 26, 2009 - 11:00

This comes from Mime Mail using the css print mode of the page, which may be producing b/w results. The idea is to let some color pass to that css print mode.

This issue is also reported in Foliage theme:
#443970: Mime Mail and print.css compatibility issue
A workaround is proposed.

#2

pillarsdotnet - August 14, 2009 - 10:59
Title:print.css from Foliage theme used resulting in b/w emails» media=<print|screen|all> selector stripped from mime_mail embedded css
Status:active» needs review

I have completely different symptoms which stem from the same problem.

In the mimemail.module file, the template_preprocess_mimemail_message() function adds style information to the email by taking the output of drupal_get_css() and concatenating the contents of all the linked stylesheets within a single <style>...</style> tag.

Unfortunately, in doing so, mimemail is stripping the "media=" selector from each link, so that styles intended for printing are mixed with styles intended for screen display.

In my case, this resulted in my print.css stylesheet, which hides selected portions of the page for printing, also hiding certain portions of the Yahoo webmail API when their customers view my messages.

The fix is to replace each link by an embedded stylesheet, one-by-one, while retaining the "media=" selector.

I am attaching three patches, one to fix the css errors, one to fix various E_ALL warnings, and one to fix a mail_alter bug reported in #448996: Wrong implementation of hook_mail_alter().

I have also corrected some unrelated problems in the original code:

  1. The test for file_exists($styles) is made before the $styles variable is defined.
  2. The regex patterns should keep working if drupal_get_css() changes how it formats its output.
  3. Whitespace is collapsed rather than stripped. See #448670: Spaces are removed from CSS definitions.
  4. I also found it necessary to add linefeeds. Otherwise, my /usr/sbin/sendmail chokes whenever a single line exceeds 5000 characters.
AttachmentSize
mimemail-css-fixes.patch 1.99 KB
mimemail-E_ALL-fixes.patch 2.22 KB
mimemail-mail_alter-fixes.patch 2.99 KB
 
 

Drupal is a registered trademark of Dries Buytaert.