Currently, the Privatemsg Email Notification Module uses old-style tokens (!username, !site, and !author). These tokens don't currently work in the D7 port.

Since we're now close to finalizing full D7 core token integration (when sending Private Messages), we need to switch over to these new-style tokens in the Email Notification Module, too. This includes support for the token browser that is part of the D7 Token contrib module.

So I've created this issue so that we don't forget. We'll be able to proceed with this as soon as http://drupal.org/node/511796 is committed.

--Ben

Comments

BenK’s picture

Title: Email Notification Module: Replace Old-Style Tokens with New Token Integration » Email Notification Sub-Module: Replace Old-Style Tokens with New Token Integration
BenK’s picture

One more thought: We'll probably need to add a token for the message body itself. This way, the actual message could be included in the e-mail notification.

--Ben

berdir’s picture

Title: Email Notification Sub-Module: Replace Old-Style Tokens with New Token Integration » Replace old-style tokens with new token integration
Component: Code » Code (pm_email_notify)

Just changing the title and component. One question, though... why do you always write issue titles capitalized? ;)

BenK’s picture

I'm bumping this issue to the top of the queue since D7 token integration is now committed... :-)

BenK’s picture

Wondering if we should work on this before the 7.x-alpha release?

berdir’s picture

Status: Active » Needs review
StatusFileSize
new8.21 KB

Finally, here is a first attempt, requires the patch at #946812: Proper entity loading, uri callback and more tokens.

Tokens have been changed, default values updated, token browser integrated and there is an update function that should convert the old tokens to the new ones.

Status: Needs review » Needs work

The last submitted patch, notifiy_tokens.patch, failed testing.

BenK’s picture

Hey Berdir,

The patch looks really good. I tested all of the Private Message tokens and they seem to work well. Here are a couple of issues I noticed:

1. Tokens placed in the e-mail subject line do not appear to be escaped properly. For instance, my test site name is "Ben's Site" (using the [site:name] token). But it is displaying in the email subject line like this:

"Ben's Site"

The apostrophe is not being escaped. Note that it appears fine in the message body, so this is just an issue with the e-mail subject line.

2. I'm getting some weird line breaks when using the body field token. There are line breaks, but it's at random places... not at the paragraphs. Per our discussion in IRC, we should look at how other notification modules are doing this in d7 (comment_notify for example).

--Ben

BenK’s picture

I also noticed this:

3. In my PM message itself (not the email notify template), I used tokens and included the subject token ([privatemsg_message:subject]) in my body text. The tokens used in my PM new message subject line were as follows: "Hey [privatemsg_message:recipient] I've got some info for you... [privatemsg_message:url]"

In my e-mail notification, the subject token (in the body text) appeared like this:

Hey editor I've got some info for you... <span
class="privatemsg-token-valid">&lt; Token http://localhost/messages/view/307
&gt;</span>

--Ben

BenK’s picture

So there appears to be an issue with token handling if tokens were also included in the original PM message. For instance, I sent the following message to a user. Here is how the message displayed in the sender's sent mail (who has permission to use tokens):

My name is < Token [privatemsg_message:author] >.

Here is the data you requested: < Token [privatemsg_message:field-extra] >

The current time is: < Token [privatemsg_message:timestamp] >

--Ben

Note: Valid tokens will be replaced when a recipient is reading this message.
Extra: 
My extra text....

However, it appeared in the recipient's e-mail notification (using the message body token) like this:

My name is < Token [privatemsg_message:author] >.Here is the data you requested:  < Token [privatemsg_message:field-extra] >The current time is:  < Token Thu, 10/28/2010 - 12:58 >--Ben

As you can see, the recipient shouldn't be seeing the "< Token" format and some tokens are not being replaced.

--Ben

dave reid’s picture

Why are you using < Token [privatemsg_message:author] > rather than just [privatemsg_message:author] ?

BenK’s picture

@Dave Reid: One feature of the token implementation in PM is token validation: If a token is correct, it prints it as "< Token [tokenname]" for the sender during message preview and in sent messages. If a token is invalid, it prints an invalid message and does some CSS styling to highlight it for the sender.

So in this issue, the recipient is incorrectly seeing this formatting (in an e-mail notification) when it should only be displaying to the sender.

--Ben

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new10.1 KB

1. Fixed. Tokens aren't sanitized anymore.

2. How did you test this? It's working fine for me. If you used the debug output to verify, note that you need to look at the sourcecode and not what's displayed.

Example I used to test:
----
Hi Fred Editor,

This is an automatic reminder from the site Berdir's Drupal 7 Testsite. You have received a new private message from Berdir.

The message:
This is a multi-line message.
This is a new line.
This also. This not.

These are tokens: editor - asdf

Bla bla

To read your message, follow this link:
http://d7/messages/view/152

If you don't want to receive these emails again, change your preferences here:
http://d7/user/144/edit
-----

3. This should be fixed.

Also removed the dpm() statement.

BenK’s picture

Status: Needs review » Needs work

Hey Berdir,

#1 and #3 are fixed. Here are the issues that remain:

#2: This seems to be an issue only if you're using full paragraphs of text (not just short lines). The code looks fine except that the line just ends instead of being a continuous paragraph. It's not a huge deal, but I think that e-mail text in a paragraph is just supposed to continue indefinitely and wrap at the full width of the browser area. Instead, the paragraph just stops at predetermined lines, some shorter than others.

Here's the paragraph I used for testing:

LONDON and CUPERTINO, California—November 16, 2010—Apple Corps, EMI and Apple® today announced that the Beatles, the most influential and beloved rock band in music history, are now available for the first time on the iTunes Store® (www.itunes.com). Starting today, the group’s 13 legendary remastered studio albums with iTunes LPs, the two-volume “Past Masters” compilation and the classic “Red” and “Blue” collections are available for purchase and download on iTunes® worldwide as either albums or individual songs. Fans can also get a special digital “Beatles Box Set” featuring the “Live at the Washington Coliseum, 1964” concert film, a worldwide iTunes exclusive which captures the Beatles’ very first US concert.

If there's no easy way to solve this, it's not a major issue and we could let it slide.

#4 (NEW): When I'm sending a message to a role, individual users in that role are not receiving e-mail notifications. If I address an e-mail individually to a user in the role, they will receive an email notification. But once I send a message to a role itself, the individual e-mail notifications are not being sent out. I'm not sure if this is related to this patch or a separate issue.

--Ben

berdir’s picture

Status: Needs work » Needs review

2. Tried with your text and still can't reproduce. I haven't actually check the sent mail but in the generated mail body, the whole thing was on a single line. And after that, it must be either Drupal core or maybe even your mail client that does something strange. Not something that we can solve IMHO.

4. We already have an issue for this, two actually: #967164: E-mails not sent if message was sent to role members. Someone even provided a patch but didn't update yet.

Setting back to needs review, since there are no code changes.

berdir’s picture

StatusFileSize
new10.08 KB

Actually, there is a change. I fixed a typo in a comment :)

BenK’s picture

Status: Needs review » Reviewed & tested by the community

Okay, let's not worry about #2 and we can take care of #4 on the other thread.

So just to be thorough, I tested the new patch in #16 and everything is working great. This is RTBC! :-)

--Ben

Status: Reviewed & tested by the community » Needs work

The last submitted patch, notifiy_tokens3.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review

#16: notifiy_tokens3.patch queued for re-testing.

BenK’s picture

Status: Needs review » Reviewed & tested by the community
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Commited!

Status: Fixed » Closed (fixed)

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