As of alpha8 (possibly before) mimemail is no longer generating text alternative versions of email. The culprit for this bug is in mimemail.inc
function mimemail_html_body($body, $subject, $plaintext = FALSE, $text = NULL, $attachments = array()) {
if (empty($text)) {
// todo: remove this preg_replace once filter_xss() is properly handling
// direct descendant css selectors '>' in inline CSS. For now this cleans
// up our plain text part. See mimemail #364198, drupal #370903
$text = preg_replace('|<style.*?</style>|mis', '', $body);
$text = drupal_html_to_text($text);
}
Changing to the following brings this back, though I'm not sure what the implications are for the xss issue. Given that this should be fully plain text, I'm not sure what the initial filter was all about.
function mimemail_html_body($body, $subject, $plaintext = FALSE, $text = NULL, $attachments = array()) {
if (empty($text)) {
// todo: remove this preg_replace once filter_xss() is properly handling
// direct descendant css selectors '>' in inline CSS. For now this cleans
// up our plain text part. See mimemail #364198, drupal #370903
$text = drupal_html_to_text($body);
}
Comments
Comment #1
sgabe commentedI cannot reproduce this, can you give an example?
Comment #2
sdague commentedI can't give a live example because I had to hot fix it on our site - http://mhvlug.org. I'm using the print module restricted to admins to generate meeting announce emails via mimemail. If there is some slice of that data that I could give you that you think would be useful, let me know.
Comment #3
sgabe commentedThat preg_replace() removes the CSS code from the message before passing it to drupal_html_to_text() since that cannot handle direct-descendant CSS selectors (>) properly. If you remove that line there is a chance (depends on your theme or mail.css) you will see some CSS code in your messages.
If you can provide the value of the $text variable before and after these modifications, that would be great help to see what happens exactly.
You can use the Devel module's dd() function which logs any variable to a file named “drupal_debug.txt” in the site’s temp directory.
Please, use the "code" and "php" tags when posting code.
Comment #4
polWhy not using
$text = strip_tags($body);?Comment #5
sgabe commentedBecause that will work only if the CSS Compressor is enabled, otherwise it won't remove the CSS.
Comment #6
polSo, if CSS compressor is not enabled, where is the CSS ? always between
<style></style>or somewhere else ?Comment #7
sgabe commentedIt will be between style tags, but it can be inline too (that would be removed by strip_tags). Depends on the content, just think about the WYSIWYG editors.
Comment #8
polI'm proposing a solution in this patch.
Comment #9
sgabe commented$textbefore and after the above line. In every case (with or without CSS Compressor or mail.css) the text alternative is automatically generated just fine. As I see thepreg_replace()properly removes the style tags and drupal_html_to_text() deals with the rest. What am I missing here, fellas? Why is this not working for you?Comment #10
polHello sgabe,
We are using a custom form, extended from the stock contact module form.
You can have an example of the HTML generated here: http://pastebin.com/FitSh1Zz
If you use that HTML, it won't work with your current code, that's why I did the function
mimemail_strip_html_tags().Comment #11
sgabe commentedIt seems that preg_replace() crashes when the text is too large.
Comment #12
polYes... unfortunately.
Comment #13
sgabe commentedThen lets just extract the body and pass it to drupal_html_to_text().
Comment #14
sgabe commentedSee the attached patch.
Comment #15
polI think that's the way to go.
I just tested with the text from http://pastebin.com/FitSh1Zz and it seems to work pretty good.
Unfortunately, It will be impossible for me to do more tests on this until Monday.
I'll give you a report on it monday if you want, I think it's gonna be positive and maybe an alpha9 will be out :-)
Thanks sgabe ;-)
Comment #16
sgabe commentedUnfortunately this is not the one that blocks the new release but #1044534: Improve support for multipart/mixed messages for example. However, thanks for your help with this and for posting the other one too. ;)
Comment #17
sgabe commentedCommitted for both branches. Let me know if you encounter any problem with this.
Comment #18
polPatch is working pretty good, tested this morning, everything's fine...
About #1044534: Improve support for multipart/mixed messages, I still have to look at it, but it seems quite complicated.
Don't you think we should release an alpha9 correcting #1116930: No text alternative if the CSS is too large and #1167576: Accept plaintext and text parameters for system messages ?
Thanks !
Comment #20
milovan commentedI have an issue with Mimemail sending empty email to users who hecked to receive only plain emails.
Debugging, I came to the following piece of code that retruns body as empty string after regex:
Variable
$matches[0]is empty, because this regex doesn't even work, I believe. I tried on a couple of online regex testers and none of them matched anything with for example following html mail code:My second question is, what "mis" in regex is for? I couldn't find a reference what that is.
Thanks!
Comment #21
matslats commentedHaving the same issue.
I don't understand this regular expression, and the case of it returning no matches is not covered.
preg_match('|<body.*?</body>|mis', $body, $matches);The problematic email is being generated by the support module.
The mail body at that moment is a chunk of valid html inside
tags.
Comment #22
tr commentedAdded code tags to the original post to make it readable.