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.

Comments

jean-bernard.addor’s picture

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.

pillarsdotnet’s picture

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
StatusFileSize
new2.99 KB
new2.22 KB
new1.99 KB

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 and Line Breaks 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.
sgabe’s picture

StatusFileSize
new938 bytes

I think it's better (less drastic modification at least) if we just remove the lines which have print media type.

gjvoosten’s picture

I agree with sgabe in #3, less of an impact to just skip the print styles.
Please note: in sgabe's patch, the line reading

+ $styles = preg_replace($pattern, $replaces, drupal_get_css());

should be

+ $styles = preg_replace($patterns, $replaces, drupal_get_css());

($patterns instead of $pattern).
[Additional note: I see sgabe has corrected it in the patch on http://drupal.org/node/743150 ]

sgabe’s picture

StatusFileSize
new938 bytes

@gjvoosten: Yeah, I forgot to attach the right patch. Thanks for noticing.

sgabe’s picture

Title: media=<print|screen|all> selector stripped from mime_mail embedded css » Skip style sheets with print media
Version: 6.x-1.x-dev » 7.x-1.x-dev
StatusFileSize
new1.25 KB

I am attaching a patch with another approach, posted by AlexisWilke in #870568: CSS concatenation problems & solution.

sgabe’s picture

StatusFileSize
new1 KB

Please ignore the previous patch...

sgabe’s picture

StatusFileSize
new1.09 KB

I think we should use CSS files with theme type only.

aron novak’s picture

Status: Needs review » Needs work

This patch works fine, even if it does not apply cleanly anymore.
I'm ready to make it clean again for both 6.x and 7.x, it's quite a major thing for everyone who has fine-grained print.css, but does not need a completely different mail.css

sgabe’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Changing version.

sgabe’s picture

Status: Needs work » Fixed

Committed to both branches.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.