!pm_body linebreaks not coming through
| Project: | Privatemsg |
| Version: | 7.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
We have a custom module that fires off a private message when a rules event is triggered on the site. The private message comes through looking just fine on the site (it uses a filter in Messaging that allows some HTML and BBCode). Line breaks are all rendered where they're supposed to, and it all looks good.
That message is then sent out to users via pm_email_notify.module, and this is where things get strange. in the Email Notify settings, we stuff the body of the private message into the outgoing mail using the !pm_body token. But all of the linebreaks within !pm_body are lost in the outgoing email. the curious part is that linebreaks that we put into the template inside of the form at admin/settings/messages/notify come through fine. That is, everything in the email has line breaks except for the embedded text from !pm_body.
This is what !pm_body should look like:
testuser22 commented on Re: This is a top post:
testuser22 wrote:
this is some test text that should have line breaks in it here
and then here
and then here again
You can reply to this at
http://site.com/node/add/forum-reply/1761/1847This is the template:
Hi !username,
!pm_body
---
If you don't want to receive these emails again, change your preferences here:
!uri/user/!user_uid/editThis is what the private message looks like:
Hi friolator,
testuser22 commented on Re: This is a top post:
testuser22 wrote:
this is some test text that should have line breaks in it here
and then here
and then here again
You can reply to this at
http://site.com/node/add/forum-reply/1761/1847
---
If you don't want to receive these emails again, change your preferences here:
http://site.com/user/13/editAnd this is the email that goes out:
Hi friolator,
testuser22 commented on Re: This is a top post: testuser22 wrote: this is some test text that should have line breaks in it here and then here and then here again You can reply to this at
http://site.com/node/add/forum-reply/1761/1847
---
If you don't want to receive these emails again, change your preferences here:
http://site.com/user/13/editAs you can see, !pm_body is one big lump of text.
Any ideas how we can fix this?

#1
Ok, I found the culprit, which I'm assuming is a bug.
In _pm_email_notify_token(), the call to drupal_html_to_text() sends an empty array as the second argument. this causes that function to fail. I changed the second argument to null, and the emails come through perfectly now.
Was:
<?php
function _pm_email_notify_token($recipient, $message) {
$tokens = array(
'!author' => $message['author']->name,
'!pm_subject' => drupal_html_to_text($message['subject'], array()),
'!pm_body' => drupal_html_to_text($message['body'], array()),
'!thread' => $message['thread_id'],
'!user_uid' => $recipient->uid,
);
return $tokens;
}
?>
Is now:
<?php'!pm_subject' => drupal_html_to_text($message['subject'], null),
'!pm_body' => drupal_html_to_text($message['body'], null),
?>
And the result is that the linebreaks in !pm_body come through just fine.
That said, I think the html_to_text filter in drupal produces kind of an ugly result, with the links being dumped at the end of the message. It's not particularly friendly in terms of UX, especially if you only have one link in the body of the email - in my use case, there's a link at the end of !pm_body and it's repeated on the next line of text with a footnote number next to it. It looks like a mistake, since it's just repeating the same URL two lines down.
So I changed it to check_markup() instead, using the plain text filter (which leaves the urls in place and doesn't footnote them like the html_to_text filter does.
Is there any chance that there could be an option of input formats in the email template form, and that this function calls check_markup(), applying the preferred format instead? that would really be ideal.
#2
here's a patch that does what I described above using drupal_html_to_text()
#3
If you write patch, why not.. But you should also add an option to use drupal_html_to_text().
#4
Setting the correct category.
#5
That doesn't seem to be enough when using the default input filter. Try the attached patch, which should work for these too.
#6
+++ pm_email_notify/pm_email_notify.module 28 Oct 2009 19:48:55 -0000@@ -126,8 +126,8 @@ function _pm_email_notify_token($recipie
+ '!pm_subject' => drupal_html_to_text($message['subject']),
+ '!pm_body' => drupal_html_to_text(check_markup($message['body'], $message['format'])),
FYI: In general, this dhtt() conversion prohibits sending of HTML mails.
If that is OK with you, then everything is alright.
+++ pm_email_notify/pm_email_notify.module 28 Oct 2009 19:48:55 -0000@@ -126,8 +126,8 @@ function _pm_email_notify_token($recipie
+ '!pm_subject' => drupal_html_to_text($message['subject']),
dhtt() expects HTML, so you need to check_plain() the subject. Otherwise, it's not HTML.
This review is powered by Dreditor.
#7
Thanks, committed the attached patch (with check_plain()) to 6.x-1.x-dev and 7.x-1.x-dev.
#8
Automatically closed -- issue fixed for 2 weeks with no activity.