If i use some text format the check_markup function that use a format where line break is set the html mail will be bad.

I tryed to figure out this and what i found is if drupal_wrap_mail() run before check_markup() that uses line break set the html text goes wrong.

So i think the check_markup function should be ran in mail_alter function so drupal_wrap_mail will be called after this.

What happens is the following:

Original link after !url is replaced
activate
reigstration

call drupal_wrap_mail() there is a break between href="http://www.example.com/user/validate/27/133405660/633061349343256caab094404e6bf5">activate
reigstration

and call check_markup after it that mess the text with


href="http://www.example.com/user/validate/27/133405660/633061349343256caab094404e6bf5">activate
reigstration

Comments

mibfire’s picture

i forget the automatic links convert

If i use <a href="!url">some text</a> format the check_markup function that use a format where line break is set the html mail will be bad.

I tryed to figure out this and what i found is if drupal_wrap_mail() run before check_markup() that uses line break set the html text goes wrong.

So i think the check_markup function should be ran in mail_alter function so drupal_wrap_mail will be called after this.

What happens is the following:

Original link after !url is replaced

<a href="http://www.example.com/user/validate/27/133405660/633061349343256caab094404e6bf5">activate
 reigstration</a>

call drupal_wrap_mail() there is a break between <a and href

<a
 href="http://www.example.com/user/validate/27/133405660/633061349343256caab094404e6bf5">activate
 reigstration</a>

and call check_markup after it and that mess the text with <br>

<a <br>
 href="http://www.example.com/user/validate/27/133405660/633061349343256caab094404e6bf5">activate <br> reigstration</a>
mibfire’s picture

It should work like in html mail module.

royiby’s picture

I am experiencing the same issue and it's a real downer....any suggestions on how could i fix it?

edit: i forgot to point out that i am experiencing it on the latest release ie beta2

thomasmurphy’s picture

subscribing

sgabe’s picture

Version: 6.x-1.0-alpha8 » 6.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new1.84 KB

I think we should move the check_markup() call to hook_mail() instead of hook_mail_alter() which is called for all messages. Please test the attached patch and report back.

sgabe’s picture

Title: html links go wrong if input format uses line break » Check markup only before wrapping
Status: Needs review » Needs work

#506112: wrong line wrapping on drupal_wrap_mail() in mail.inc is marked as a duplicate of this.

However, we need to remove the check_markup() call from drupal_mail_wrapper().

sgabe’s picture

Status: Needs work » Needs review
StatusFileSize
new3.22 KB

In the following patch I moved the check_markup() call from drupal_mail_wrapper() into hook_form_alter(). We need this to create HTML versions of plain text system messages, but we need to check if the message needs to be converted to HTML format or not.

sgabe’s picture

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

Lets move this to D7.

Sarenc’s picture

patch in #7 works great for me. Mime mail wasn't converting line breaks to br tags at all before implementing this patch.

moshe weitzman’s picture

Code looks good. Have not verified that it fixes the bug.

mrbubbs’s picture

I would like to confirm the patch in #7 works for me too. I've patched against Mime Mail 6.x-1.0. The HTML portion of the email now has complete lines that aren't broken in the browser except for intended breaks inserted with ckeditor.

I implemented the exact same solution before I found this post! It would be nice if the patch could eventually be included with the 6.x branch. I think this would be classified as a bug, not a feature. I have several annoyed end-users complaining about weird wrapping HTML email. I'll be manually applying this patch to fix the issue for now.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community
ezra-g’s picture

Status: Reviewed & tested by the community » Needs work

#7 does not apply to 6.x-2.x or 6.x-2.0.

mrbubbs’s picture

When will this make it into 6.x?

langworthy’s picture

How about 7.x? I'm trying to get something like #7 for 7.x but I can't figure out where the second part of the diff for mimemail.module would go.

raphaelhuefner’s picture

In order to handle at least the mails of user.module in Drupal 7, I came up with this hook_mail_alter() implementation:

function mymodule_mail_alter(&$message) {
  $mail_system = drupal_mail_system($message['module'], $message['key']);
  $is_mimemail_active = ($mail_system instanceof MimeMailSystem);
  if (
    $is_mimemail_active
    &&
    ('user' == $message['module'])
    &&
    in_array($message['key'], array(
      'register_admin_created', 'register_no_approval_required',
      'register_pending_approval', 'password_reset', 'status_activated',
      'status_blocked', 'cancel_confirm', 'status_canceled',
    ))
  ) {
    $message['body'][0] = nl2br($message['body'][0]);
  }
}

Where "mymodule" would be the name of a custom module of your own. Yep, it's just a work-around, not a real solution.

hanskuiters’s picture

Thanks @raphaelhuefner for this work-around.