While sending the newsletter through Mime Mail the recipient's text mail preference isn't taken into account, the attached patch loads the user.name and user.data in simplenews_get_subscription and passes the entire $subscription object to Mime Mail which uses it to decide if send the mail in plain text or in html format.

This patch depends on #400998: mimemail_prepare won't accept $plaintext = FALSE argument.

Comments

sutharsan’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Active » Needs review

Code looks good but I like to see test results of this.
Moving this to HEAD since I will not put any new features in 6.x-1.x any more.

jdwfly’s picture

I used the patch at #400998: mimemail_prepare won't accept $plaintext = FALSE argument for mime_mail and then I applied this patch. I have been testing this and it seems to work like it is supposed to. This was a definite need for me because our users are somewhat particular about what types of emails we send them.

sutharsan’s picture

Status: Needs review » Reviewed & tested by the community

I'll do a final test and commit it to HEAD when I have a chance.

jdwfly’s picture

Status: Reviewed & tested by the community » Needs review

I'm not quite sure that this solution scales very well. All of my smaller scale tests worked fine without problems, but when I ran it for real it ended up sending out text emails to everyone. It could be that this logic is flawed? I'm going to be looking into it over the next few hours.

jdwfly’s picture

Status: Needs review » Reviewed & tested by the community

Just figured it out. Let me explain how I can about this.

I have two different types of subscribers. Ones without accounts and ones with accounts. The ones that have accounts have their text mail preference set and the ones without will receive whatever format the newsletter comes. In my case that is HTML. Since I needed to import several hundred accounts I ran a simple database query to update the data field for every user. This modification changed EVERY user account to have text emails only. This of course was fine for me because the only ones with accounts were supposed to get text email. The problem came because I did not realize that the anonymous user mail preference is used when the email address has no user account. So when I sent out my first mass mailing, everyone got a plain text email.

This took me a while to figure out (it was my own fault), but I still don't know exactly why it uses the anonymous user's mail preference for email addresses without a user account. All I know is when I removed the data from the anonymous user and tested the emails, it worked just like it should.

miro_dietiker’s picture

This patch does not apply to the current repo HEAD (2009-09-16).

The only thing that gets applied is:

-        $message['to'],
+        isset($message['params']['context']['account']) ? $message['params']['context']['account'] : $message['to'],

Other things seems to be disappeared... even if i see that $subscription->data don't get loaded and can't be applied thus using drupal_unpack().

I don't understand jet why we really need this (missing) unpack. Any explanation, any reroll?

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work

state transitions...

miro_dietiker’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.21 KB

Initially i wanted to fix this from an other perspective.
#581326: Mimemail integration wrong
Now i see that the fix overthere combined with one here is a perfect fix for the situation.
For more information please consider the other issue and related mimemail patch which is no more needed now.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs review

that was a bit too fast. someone pls review.

dawehner’s picture

Status: Needs review » Needs work
+++ simplenews.module	18 Sep 2009 19:14:38 -0000
@@ -1681,10 +1681,13 @@ function simplenews_mail_mail($nid, $vid
+      if($message['params']['context']['node']->simplenews['s_format']=='plain') {

I would have used ? . Anyway, there are two coding problems in this line :p

if( and
]=='

+++ simplenews.module	18 Sep 2009 19:14:38 -0000
@@ -1681,10 +1681,13 @@ function simplenews_mail_mail($nid, $vid
+	isset($message['params']['context']['account']) ? $message['params']['context']['account'] : $message['to'],

Here is a tab.
I'm on crack. Are you, too?

This was just a coding style review :)

sutharsan’s picture

Status: Needs work » Fixed
StatusFileSize
new1.18 KB

I've reworked the patch and committed to 1.x and 2.x branch. Fixes are available in the next dev release.

miro_dietiker’s picture

Looks perfect. Thank you!

Status: Fixed » Closed (fixed)

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