I just realized there is no email system so I put this on the base. Rfay found an issue in the email system and we are not sure if this is a bug in the email system or intended behavior. When sending a plain text message including the '<' character, the body is truncated at this character by the drupal_html_to_text() function, even if the body is not html.

I'm writing the issue from my poor understanding of the email system, so I'll ask some questions I can't reply myself.

1st - The format() method of the DefaultMailSystem class (modules/system/mail.sending.inc) forces the conversion of the message body from html to text. Should this happen for plain text emails also?

2nd - the function drupal_html_to_text() should remove a bogus html tag when it is not closed?

These two concerns combined break the tests of the email_example module when trying to send a message with the character '<' followed by arbitrary characters of well known html tags in a random body.

Basically what is happening is that the following call on plain text body:

drupal_html_to_text(" this simple check, if(a<b) should fail");

returns the string "this simple check, if(a*"

Comments

rfay’s picture

Good detective work - thanks for tracking this down, ilo.

This seems like a fundamental "wrong" with emails, since it inexplicably would throw away the remainder of an email body where the user used the < character for any reason.

sun’s picture

All e-mail messages are now considered to be HTML.

Plain-text messages should follow this flow:

// hook_mail():
$body = check_plain(" this simple check, if(a<b) should fail");

// elsewhere in the mail system (the mail sending system)
drupal_html_to_text($body);
ilo’s picture

Thanks sun for your attention.

In an attempt to document this 'requirement' (for the D6 to D7 upgrade handbook, and the email example module) I can't find any issue about that, so don't know where to point about that.

Is this string " < b " (without spaces) considered an invalid html tag? or the function drupal_html_to_text is not working as expected with tags not closed properly?

Edited: the " < b " string just truncated the next sentence in the comment (I thought it was only happening in the email system..). It is a copy of the previous one but removing the spaces between < and b.

On the other hand.. is the "

rfay’s picture

@ilo, there's great irony that your post was truncated with the introduction of a <. You probably have to return and finish it :-)

ilo’s picture

@rfay, I edited, and posted the line with a fix and without it to be kept as demonstration :)

rfay’s picture

@sun (#2) So you're saying this is a behavior change for D7? I don't see anything on the module update page about this, but I'll be happy to add it. Is the basic information you put in #2 adequate for this, or is there a broader context?

rfay’s picture

Assigned: Unassigned » rfay

I'll document this per sun's statement in #2. @sun, are there any other email changes in behavior that go with this? Can you point me to an issue where it was discussed?

rfay’s picture

Status: Active » Fixed

Sun beat me to this in http://drupal.org/node/727352. I added a little bit to it. @sun you may want to review.

Followup on the Email Example at #730984: Email example (D7) needs to check_plain on user text

Status: Fixed » Closed (fixed)

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